HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
Yii2ProfilingPanel.php
Go to the documentation of this file.
1 <?php
2 
9 {
13  public function init()
14  {
15  $this->_logsEnabled = true;
16  $this->_logsLevels = CLogger::LEVEL_PROFILE;
17  parent::init();
18  }
19 
20  public function getName()
21  {
22  return 'Profiling';
23  }
24 
25  public function getSummary()
26  {
27  return $this->render(dirname(__FILE__) . '/../views/panels/profiling_bar.php', array(
28  'time' => number_format($this->data['time'] * 1000) . ' ms',
29  'memory' => sprintf('%.1f MB', $this->data['memory'] / 1048576),
30  ));
31  }
32 
33  public function getDetail()
34  {
35  $messages = $this->data['messages'];
36  $timings = array();
37  $stack = array();
38  foreach ($messages as $i => $log) {
39  list($token, , $category, $timestamp) = $log;
40  $log[4] = $i;
41  if (strpos($token, 'begin:') === 0) {
42  $log[0] = $token = substr($token, 6);
43  $stack[] = $log;
44  } elseif (strpos($token, 'end:') === 0) {
45  $log[0] = $token = substr($token, 4);
46  if (($last = array_pop($stack)) !== null && $last[0] === $token) {
47  $timings[$last[4]] = array(count($stack), $token, $category, $timestamp - $last[3]);
48  }
49  }
50  }
51  $now = microtime(true);
52  while (($last = array_pop($stack)) !== null) {
53  $delta = $now - $last[3];
54  $timings[$last[4]] = array(count($stack), $last[0], $last[2], $delta);
55  }
56  ksort($timings);
57  $items = array();
58  foreach ($timings as $timing) {
59  $items[] = array(
60  'indent' => $timing[0],
61  'procedure' => $timing[1],
62  'category' => $timing[2],
63  'time' => sprintf('%.1f ms', $timing[3] * 1000),
64  );
65  }
66  return $this->render(dirname(__FILE__) . '/../views/panels/profiling.php', array(
67  'items' => $items,
68  'time' => number_format($this->data['time'] * 1000) . ' ms',
69  'memory' => sprintf('%.1f MB', $this->data['memory'] / 1048576),
70  ));
71  }
72 
73  public function save()
74  {
75  return array(
76  'memory' => memory_get_peak_usage(),
77  'time' => microtime(true) - YII_BEGIN_TIME,
78  'messages' => $this->getLogs(),
79  );
80  }
81 }