| 12345 |
anikendra |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Timer Panel Element
|
|
|
4 |
*
|
|
|
5 |
* PHP 5
|
|
|
6 |
*
|
|
|
7 |
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
8 |
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
9 |
*
|
|
|
10 |
* Licensed under The MIT License
|
|
|
11 |
* Redistributions of files must retain the above copyright notice.
|
|
|
12 |
*
|
|
|
13 |
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
14 |
* @link http://cakephp.org CakePHP(tm) Project
|
|
|
15 |
* @since DebugKit 0.1
|
|
|
16 |
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
$this->Number = $this->Helpers->load('Number');
|
|
|
20 |
$this->SimpleGraph = $this->Helpers->load('DebugKit.SimpleGraph');
|
|
|
21 |
|
|
|
22 |
if (!isset($debugKitInHistoryMode)):
|
|
|
23 |
$timers = DebugTimer::getAll(true);
|
|
|
24 |
$currentMemory = DebugKitDebugger::getMemoryUse();
|
|
|
25 |
$peakMemory = DebugKitDebugger::getPeakMemoryUse();
|
|
|
26 |
$requestTime = DebugTimer::requestTime();
|
|
|
27 |
else:
|
|
|
28 |
$content = $this->Toolbar->readCache('timer', $this->request->params['pass'][0]);
|
|
|
29 |
if (is_array($content)):
|
|
|
30 |
extract($content);
|
|
|
31 |
endif;
|
|
|
32 |
endif;
|
|
|
33 |
?>
|
|
|
34 |
<div class="debug-info">
|
|
|
35 |
<h2><?php echo __d('debug_kit', 'Memory'); ?></h2>
|
|
|
36 |
<div class="peak-mem-use">
|
|
|
37 |
<?php
|
|
|
38 |
echo $this->Toolbar->message(__d('debug_kit', 'Peak Memory Use'), $this->Number->toReadableSize($peakMemory)); ?>
|
|
|
39 |
</div>
|
|
|
40 |
|
|
|
41 |
<?php
|
|
|
42 |
$headers = array(__d('debug_kit', 'Message'), __d('debug_kit', 'Memory use'));
|
|
|
43 |
$memoryPoints = DebugKitDebugger::getMemoryPoints();
|
|
|
44 |
|
|
|
45 |
$rows = array();
|
|
|
46 |
foreach ($memoryPoints as $key => $value):
|
|
|
47 |
$rows[] = array($key, $this->Number->toReadableSize($value));
|
|
|
48 |
endforeach;
|
|
|
49 |
|
|
|
50 |
echo $this->Toolbar->table($rows, $headers);
|
|
|
51 |
?>
|
|
|
52 |
</div>
|
|
|
53 |
|
|
|
54 |
<div class="debug-info debug-timers">
|
|
|
55 |
<h2><?php echo __d('debug_kit', 'Timers'); ?></h2>
|
|
|
56 |
<div class="request-time">
|
|
|
57 |
<?php $totalTime = __d('debug_kit', '%s (ms)', $this->Number->precision($requestTime * 1000, 0)); ?>
|
|
|
58 |
<?php echo $this->Toolbar->message(__d('debug_kit', 'Total Request Time:'), $totalTime)?>
|
|
|
59 |
</div>
|
|
|
60 |
<?php
|
|
|
61 |
$rows = array();
|
|
|
62 |
$end = end($timers);
|
|
|
63 |
$maxTime = $end['end'];
|
|
|
64 |
|
|
|
65 |
$headers = array(
|
|
|
66 |
__d('debug_kit', 'Message'),
|
|
|
67 |
__d('debug_kit', 'Time in ms'),
|
|
|
68 |
__d('debug_kit', 'Graph')
|
|
|
69 |
);
|
|
|
70 |
|
|
|
71 |
$i = 0;
|
|
|
72 |
$values = array_values($timers);
|
|
|
73 |
|
|
|
74 |
foreach ($timers as $timerName => $timeInfo):
|
|
|
75 |
$indent = 0;
|
|
|
76 |
for ($j = 0; $j < $i; $j++) {
|
|
|
77 |
if (($values[$j]['end'] > $timeInfo['start']) && ($values[$j]['end']) > ($timeInfo['end'])) {
|
|
|
78 |
$indent++;
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
$indent = str_repeat(' » ', $indent);
|
|
|
82 |
$rows[] = array(
|
|
|
83 |
$indent . $timeInfo['message'],
|
|
|
84 |
$this->Number->precision($timeInfo['time'] * 1000, 2),
|
|
|
85 |
$this->SimpleGraph->bar(
|
|
|
86 |
$this->Number->precision($timeInfo['time'] * 1000, 2),
|
|
|
87 |
$this->Number->precision($timeInfo['start'] * 1000, 2),
|
|
|
88 |
array(
|
|
|
89 |
'max' => $maxTime * 1000,
|
|
|
90 |
'requestTime' => $requestTime * 1000,
|
|
|
91 |
)
|
|
|
92 |
)
|
|
|
93 |
);
|
|
|
94 |
$i++;
|
|
|
95 |
endforeach;
|
|
|
96 |
|
|
|
97 |
if (strtolower($this->Toolbar->getName()) === 'firephptoolbar'):
|
|
|
98 |
for ($i = 0, $len = count($rows); $i < $len; $i++):
|
|
|
99 |
unset($rows[$i][2]);
|
|
|
100 |
endfor;
|
|
|
101 |
unset($headers[2]);
|
|
|
102 |
endif;
|
|
|
103 |
|
|
|
104 |
echo $this->Toolbar->table($rows, $headers, array('title' => 'Timers'));
|
|
|
105 |
|
|
|
106 |
if (!isset($debugKitInHistoryMode)):
|
|
|
107 |
$this->Toolbar->writeCache('timer', compact('timers', 'currentMemory', 'peakMemory', 'requestTime'));
|
|
|
108 |
endif;
|
|
|
109 |
?>
|
|
|
110 |
</div>
|