Base for a static organization website

DebugTimerHelper.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @link http://cakephp.org CakePHP(tm) Project
  11. * @since DebugKit 2.1
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. App::uses('DebugTimer', 'DebugKit.Lib');
  15. App::uses('DebugMemory', 'DebugKit.Lib');
  16. App::uses('Helper', 'View');
  17. /**
  18. * Class DebugTimerHelper
  19. *
  20. * Tracks time and memory usage while rendering view.
  21. *
  22. */
  23. class DebugTimerHelper extends Helper {
  24. /**
  25. * Set to true when rendering is complete.
  26. * Used to not add timers for rendering the toolbar.
  27. *
  28. * @var boolean
  29. */
  30. protected $_renderComplete = false;
  31. /**
  32. * Constructor
  33. *
  34. * @param View $View
  35. * @param array $settings
  36. */
  37. public function __construct(View $View, $settings = array()) {
  38. parent::__construct($View, $settings);
  39. DebugTimer::start(
  40. 'viewRender',
  41. __d('debug_kit', 'Rendering View')
  42. );
  43. }
  44. /**
  45. * Sets a timer point before rendering a file.
  46. *
  47. * @param string $viewFile The view being rendered
  48. */
  49. public function beforeRenderFile($viewFile) {
  50. if ($this->_renderComplete) {
  51. return;
  52. }
  53. DebugTimer::start(
  54. 'render_' . basename($viewFile),
  55. __d('debug_kit', 'Rendering %s',
  56. Debugger::trimPath($viewFile))
  57. );
  58. }
  59. /**
  60. * Stops the timer point before rendering a file.
  61. *
  62. * @param string $viewFile The view being rendered
  63. * @param string $content The contents of the view.
  64. */
  65. public function afterRenderFile($viewFile, $content) {
  66. if ($this->_renderComplete) {
  67. return;
  68. }
  69. DebugTimer::stop('render_' . basename($viewFile));
  70. }
  71. /**
  72. * Stop timers for rendering.
  73. *
  74. * @param string $layoutFile
  75. */
  76. public function afterLayout($layoutFile) {
  77. DebugTimer::stop('viewRender');
  78. DebugTimer::stop('controllerRender');
  79. DebugMemory::record(__d('debug_kit', 'View render complete'));
  80. $this->_renderComplete = true;
  81. }
  82. }