Skip to content

Commit

Permalink
Changes needed for debug-toolbar https://github.com/vokiel/debug-toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
vokiel committed Mar 13, 2011
1 parent 89303ae commit 883161c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
7 changes: 6 additions & 1 deletion modules/profiler/classes/kohana/database/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ public function query($type, $sql, $as_object)

if (isset($benchmark))
{
Profiler::stop($benchmark);
$debug = debug_backtrace();
$arr = array (
'file' => $debug[count($debug)-6]['line'],
'line' => $debug[count($debug)-6]['file'],
);
Profiler::stop($benchmark,$arr);
Profiler::add($benchmark, 'R: '.mysql_affected_rows($this->_connection));
}

Expand Down
58 changes: 55 additions & 3 deletions modules/profiler/classes/profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public static function start($group, $name)
'stop_time' => FALSE,
'stop_memory' => FALSE,
'other' => FALSE,

'file' => FALSE,
'line' => FALSE,
);

return $token;
Expand All @@ -53,10 +56,9 @@ public static function stats(array $tokens)
$total = array(
'time' => 0,
'memory' => 0);

foreach ($tokens as $token)
{

$other = Profiler::$_marks[$token]['other'];
// Get the total time and memory for this benchmark
list($time, $memory) = Profiler::total($token);
Expand Down Expand Up @@ -105,8 +107,58 @@ public static function stats(array $tokens)
'max' => $max,
'total' => $total,
'average' => $average,
'other'=>$other);
'other'=>$other
);
}

/**
* Stops a benchmark.
*
* Profiler::stop($token);
*
* @param string token
* @return void
*/
public static function stop($token,$arr=false)
{
// Stop the benchmark
Profiler::$_marks[$token]['stop_time'] = microtime(TRUE);
Profiler::$_marks[$token]['stop_memory'] = memory_get_usage();
if (Arr::is_array($arr)){
Profiler::$_marks[$token]['file'] = $arr['file'];
Profiler::$_marks[$token]['line'] = $arr['line'];
}
}

/**
* Gets the total execution time and memory usage of a benchmark as a list.
*
* list($time, $memory) = Profiler::total($token);
*
* @param string token
* @return array execution time, memory
*/
public static function total($token)
{
// Import the benchmark data
$mark = Profiler::$_marks[$token];

if ($mark['stop_time'] === FALSE)
{
// The benchmark has not been stopped yet
$mark['stop_time'] = microtime(TRUE);
$mark['stop_memory'] = memory_get_usage();
}

return array
(
// Total time in seconds
$mark['stop_time'] - $mark['start_time'],
// Amount of memory in bytes
$mark['stop_memory'] - $mark['start_memory'],

$mark['file'],
$mark['line']
);
}
}

0 comments on commit 883161c

Please sign in to comment.