4 * Set $config['log_benchmark_to_file'] = '/tmp/ninja_benchmark.log' in
5 * ninja/application/config/custom/config.php
6 * to log benchmarking data.
12 * @param $filename string
14 function __construct($filename) {
15 $this->filename
= $filename;
16 Event
::add('system.display', array($this, 'log_to_file'));
20 * Collects benchmarking information and prints to file
22 function log_to_file() {
23 $benchmark = Benchmark
::get(SYSTEM_BENCHMARK
.'_total_execution');
24 $memory = function_exists('memory_get_usage') ?
(memory_get_usage() / 1024 / 1024) : 0;
27 foreach (Database
::$benchmarks as $key => $value){
28 $sqltime +
= $value["time"];
29 $sqlrows +
= $value["rows"];
33 'timestamp' => time(),
34 // we want to be able to pipe to cut -d ' ', hence: no spaces in username
35 'user' => Auth
::instance()->get_user() ?
str_replace(' ', '_', Auth
::instance()->get_user()->username
) : '[not_logged_in]',
36 'url' => url
::current(true),
37 'execution_time' => $benchmark['time'].'s',
38 'memory_usage' => number_format($memory, 2).'MB',
39 'num_sql' => count(Database
::$benchmarks),
40 'sqltime' => $sqltime,
45 file_put_contents($this->filename
, implode(' ', $output)."\n", FILE_APPEND
);
49 if($log_benchmark_to_file = Kohana
::config('config.log_benchmark_to_file')) {
50 new benchmark_log($log_benchmark_to_file);