Base for a static organization website

timer_panel.ctp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. $this->Number = $this->Helpers->load('Number');
  19. $this->SimpleGraph = $this->Helpers->load('DebugKit.SimpleGraph');
  20. if (!isset($debugKitInHistoryMode)):
  21. $timers = DebugTimer::getAll(true);
  22. $currentMemory = DebugKitDebugger::getMemoryUse();
  23. $peakMemory = DebugKitDebugger::getPeakMemoryUse();
  24. $requestTime = DebugTimer::requestTime();
  25. else:
  26. $content = $this->Toolbar->readCache('timer', $this->request->params['pass'][0]);
  27. if (is_array($content)):
  28. extract($content);
  29. endif;
  30. endif;
  31. ?>
  32. <div class="debug-info">
  33. <h2><?php echo __d('debug_kit', 'Memory'); ?></h2>
  34. <div class="peak-mem-use">
  35. <?php
  36. echo $this->Toolbar->message(__d('debug_kit', 'Peak Memory Use'), $this->Number->toReadableSize($peakMemory)); ?>
  37. </div>
  38. <?php
  39. $headers = array(__d('debug_kit', 'Message'), __d('debug_kit', 'Memory use'));
  40. $memoryPoints = DebugKitDebugger::getMemoryPoints();
  41. $rows = array();
  42. foreach ($memoryPoints as $key => $value):
  43. $rows[] = array($key, $this->Number->toReadableSize($value));
  44. endforeach;
  45. echo $this->Toolbar->table($rows, $headers);
  46. ?>
  47. </div>
  48. <div class="debug-info debug-timers">
  49. <h2><?php echo __d('debug_kit', 'Timers'); ?></h2>
  50. <div class="request-time">
  51. <?php $totalTime = __d('debug_kit', '%s (ms)', $this->Number->precision($requestTime * 1000, 0)); ?>
  52. <?php echo $this->Toolbar->message(__d('debug_kit', 'Total Request Time:'), $totalTime)?>
  53. </div>
  54. <?php
  55. $rows = array();
  56. $end = end($timers);
  57. $maxTime = $end['end'];
  58. $headers = array(
  59. __d('debug_kit', 'Message'),
  60. __d('debug_kit', 'Time in ms'),
  61. __d('debug_kit', 'Graph')
  62. );
  63. $i = 0;
  64. $values = array_values($timers);
  65. foreach ($timers as $timerName => $timeInfo):
  66. $indent = 0;
  67. for ($j = 0; $j < $i; $j++) {
  68. if (($values[$j]['end'] > $timeInfo['start']) && ($values[$j]['end']) > ($timeInfo['end'])) {
  69. $indent++;
  70. }
  71. }
  72. $indent = str_repeat(' &raquo; ', $indent);
  73. $rows[] = array(
  74. $indent . $timeInfo['message'],
  75. $this->Number->precision($timeInfo['time'] * 1000, 2),
  76. $this->SimpleGraph->bar(
  77. $this->Number->precision($timeInfo['time'] * 1000, 2),
  78. $this->Number->precision($timeInfo['start'] * 1000, 2),
  79. array(
  80. 'max' => $maxTime * 1000,
  81. 'requestTime' => $requestTime * 1000,
  82. )
  83. )
  84. );
  85. $i++;
  86. endforeach;
  87. if (strtolower($this->Toolbar->getName()) === 'firephptoolbar'):
  88. for ($i = 0, $len = count($rows); $i < $len; $i++):
  89. unset($rows[$i][2]);
  90. endfor;
  91. unset($headers[2]);
  92. endif;
  93. echo $this->Toolbar->table($rows, $headers, array('title' => 'Timers'));
  94. if (!isset($debugKitInHistoryMode)):
  95. $this->Toolbar->writeCache('timer', compact('timers', 'currentMemory', 'peakMemory', 'requestTime'));
  96. endif;
  97. ?>
  98. </div>