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 0.1
12
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
13
 */
14
 
15
App::uses('Debugger', 'Utility');
16
App::uses('FireCake', 'DebugKit.Lib');
17
App::uses('DebugTimer', 'DebugKit.Lib');
18
App::uses('DebugMemory', 'DebugKit.Lib');
19
 
20
/**
21
 * DebugKit Temporary Debugger Class
22
 *
23
 * Provides the future features that are planned. Yet not implemented in the 1.2 code base
24
 *
25
 * This file will not be needed in future version of CakePHP.
26
 *
27
 * @since         DebugKit 0.1
28
 */
29
class DebugKitDebugger extends Debugger {
30
 
31
/**
32
 * destruct method
33
 *
34
 * Allow timer info to be displayed if the code dies or is being debugged before rendering the view
35
 * Cheat and use the debug log class for formatting
36
 *
37
 * @return void
38
 */
39
	public function __destruct() {
40
		$timers = DebugTimer::getAll();
41
		if (Configure::read('debug') < 2 || count($timers) > 0) {
42
			return;
43
		}
44
		$timers = array_values($timers);
45
		$end = end($timers);
46
		echo '<table class="cake-sql-log"><tbody>';
47
		echo '<caption>Debug timer info</caption>';
48
		echo '<tr><th>Message</th><th>Start Time (ms)</th><th>End Time (ms)</th><th>Duration (ms)</th></tr>';
49
		$i = 0;
50
		foreach ($timers as $timer) {
51
			$indent = 0;
52
			for ($j = 0; $j < $i; $j++) {
53
				if (($timers[$j]['end']) > ($timer['start']) && ($timers[$j]['end']) > ($timer['end'])) {
54
					$indent++;
55
				}
56
			}
57
			$indent = str_repeat(' &raquo; ', $indent);
58
 
59
			extract($timer);
60
			$start = round($start * 1000, 0);
61
			$end = round($end * 1000, 0);
62
			$time = round($time * 1000, 0);
63
			echo "<tr><td>{$indent}$message</td><td>$start</td><td>$end</td><td>$time</td></tr>";
64
			$i++;
65
		}
66
		echo '</tbody></table>';
67
	}
68
 
69
/**
70
 * Start an benchmarking timer.
71
 *
72
 * @param string $name The name of the timer to start.
73
 * @param string $message A message for your timer
74
 * @return boolean true
75
 * @deprecated use DebugTimer::start()
76
 */
77
	public static function startTimer($name = null, $message = null) {
78
		return DebugTimer::start($name, $message);
79
	}
80
 
81
/**
82
 * Stop a benchmarking timer.
83
 *
84
 * $name should be the same as the $name used in startTimer().
85
 *
86
 * @param string $name The name of the timer to end.
87
 * @return boolean true if timer was ended, false if timer was not started.
88
 * @deprecated use DebugTimer::stop()
89
 */
90
	public static function stopTimer($name = null) {
91
		return DebugTimer::stop($name);
92
	}
93
 
94
/**
95
 * Get all timers that have been started and stopped.
96
 * Calculates elapsed time for each timer. If clear is true, will delete existing timers
97
 *
98
 * @param boolean $clear false
99
 * @return array
100
 * @deprecated use DebugTimer::getAll()
101
 */
102
	public static function getTimers($clear = false) {
103
		return DebugTimer::getAll($clear);
104
	}
105
 
106
/**
107
 * Clear all existing timers
108
 *
109
 * @return boolean true
110
 * @deprecated use DebugTimer::clear()
111
 */
112
	public static function clearTimers() {
113
		return DebugTimer::clear();
114
	}
115
 
116
/**
117
 * Get the difference in time between the timer start and timer end.
118
 *
119
 * @param $name string the name of the timer you want elapsed time for.
120
 * @param $precision int the number of decimal places to return, defaults to 5.
121
 * @return float number of seconds elapsed for timer name, 0 on missing key
122
 * @deprecated use DebugTimer::elapsedTime()
123
 */
124
	public static function elapsedTime($name = 'default', $precision = 5) {
125
		return DebugTimer::elapsedTime($name, $precision);
126
	}
127
 
128
/**
129
 * Get the total execution time until this point
130
 *
131
 * @return float elapsed time in seconds since script start.
132
 * @deprecated use DebugTimer::requestTime()
133
 */
134
	public static function requestTime() {
135
		return DebugTimer::requestTime();
136
	}
137
 
138
/**
139
 * get the time the current request started.
140
 *
141
 * @return float time of request start
142
 * @deprecated use DebugTimer::requestStartTime()
143
 */
144
	public static function requestStartTime() {
145
		return DebugTimer::requestStartTime();
146
	}
147
 
148
/**
149
 * get current memory usage
150
 *
151
 * @return integer number of bytes ram currently in use. 0 if memory_get_usage() is not available.
152
 * @deprecated Use DebugMemory::getCurrent() instead.
153
 */
154
	public static function getMemoryUse() {
155
		return DebugMemory::getCurrent();
156
	}
157
 
158
/**
159
 * Get peak memory use
160
 *
161
 * @return integer peak memory use (in bytes). Returns 0 if memory_get_peak_usage() is not available
162
 * @deprecated Use DebugMemory::getPeak() instead.
163
 */
164
	public static function getPeakMemoryUse() {
165
		return DebugMemory::getPeak();
166
	}
167
 
168
/**
169
 * Stores a memory point in the internal tracker.
170
 * Takes a optional message name which can be used to identify the memory point.
171
 * If no message is supplied a debug_backtrace will be done to identifty the memory point.
172
 * If you don't have memory_get_xx methods this will not work.
173
 *
174
 * @param string $message Message to identify this memory point.
175
 * @return boolean
176
 * @deprecated Use DebugMemory::getAll() instead.
177
 */
178
	public static function setMemoryPoint($message = null) {
179
		return DebugMemory::record($message);
180
	}
181
 
182
/**
183
 * Get all the stored memory points
184
 *
185
 * @param boolean $clear Whether you want to clear the memory points as well. Defaults to false.
186
 * @return array Array of memory marks stored so far.
187
 * @deprecated Use DebugMemory::getAll() instead.
188
 */
189
	public static function getMemoryPoints($clear = false) {
190
		return DebugMemory::getAll($clear);
191
	}
192
 
193
/**
194
 * Clear out any existing memory points
195
 *
196
 * @return void
197
 * @deprecated Use DebugMemory::clear() instead.
198
 */
199
	public static function clearMemoryPoints() {
200
		DebugMemory::clear();
201
	}
202
 
203
/**
204
 * Create a FirePHP error message
205
 *
206
 * @param array $data Data of the error
207
 * @param array $links  Links for the error
208
 * @return void
209
 */
210
	public static function fireError($data, $links) {
211
		$name = $data['error'] . ' - ' . $data['description'];
212
		$message = "{$data['error']} {$data['code']} {$data['description']} on line: {$data['line']} in file: {$data['file']}";
213
		FireCake::group($name);
214
		FireCake::error($message, $name);
215
		if (isset($data['context'])) {
216
			FireCake::log($data['context'], 'Context');
217
		}
218
		if (isset($data['trace'])) {
219
			FireCake::log(preg_split('/[\r\n]+/', $data['trace']), 'Trace');
220
		}
221
		FireCake::groupEnd();
222
	}
223
 
224
}
225
 
226
DebugKitDebugger::getInstance('DebugKitDebugger');
227
Debugger::addFormat('fb', array('callback' => 'DebugKitDebugger::fireError'));