Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12345 anikendra 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
 
15
App::uses('DebugTimer', 'DebugKit.Lib');
16
App::uses('DebugMemory', 'DebugKit.Lib');
17
App::uses('Helper', 'View');
18
 
19
/**
20
 * Class DebugTimerHelper
21
 *
22
 * Tracks time and memory usage while rendering view.
23
 *
24
 */
25
class DebugTimerHelper extends Helper {
26
 
27
/**
28
 * Set to true when rendering is complete.
29
 * Used to not add timers for rendering the toolbar.
30
 *
31
 * @var boolean
32
 */
33
	protected $_renderComplete = false;
34
 
35
/**
36
 * Constructor
37
 *
38
 * @param View $View
39
 * @param array $settings
40
 */
41
	public function __construct(View $View, $settings = array()) {
42
		parent::__construct($View, $settings);
43
		DebugTimer::start(
44
			'viewRender',
45
			__d('debug_kit', 'Rendering View')
46
		);
47
	}
48
 
49
/**
50
 * Sets a timer point before rendering a file.
51
 *
52
 * @param string $viewFile The view being rendered
53
 */
54
	public function beforeRenderFile($viewFile) {
55
		if ($this->_renderComplete) {
56
			return;
57
		}
58
		DebugTimer::start(
59
			'render_' . basename($viewFile),
60
			__d('debug_kit', 'Rendering %s',
61
			Debugger::trimPath($viewFile))
62
		);
63
	}
64
 
65
/**
66
 * Stops the timer point before rendering a file.
67
 *
68
 * @param string $viewFile The view being rendered
69
 * @param string $content The contents of the view.
70
 */
71
	public function afterRenderFile($viewFile, $content) {
72
		if ($this->_renderComplete) {
73
			return;
74
		}
75
		DebugTimer::stop('render_' . basename($viewFile));
76
	}
77
 
78
/**
79
 * Stop timers for rendering.
80
 *
81
 * @param string $layoutFile
82
 */
83
	public function afterLayout($layoutFile) {
84
		DebugTimer::stop('viewRender');
85
		DebugTimer::stop('controllerRender');
86
		DebugMemory::record(__d('debug_kit', 'View render complete'));
87
		$this->_renderComplete = true;
88
	}
89
 
90
}