Created
June 2, 2011 13:17
-
-
Save yuya-matsushima/1004401 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class MY_Profiler extends CI_Profiler | |
{ | |
protected $_available_sections = array( | |
'benchmarks', | |
'memory_usage', | |
'get', | |
'post', | |
'queries', | |
'session_data', | |
'http_headers', | |
'uri_string', | |
'controller_info', | |
'config' | |
); | |
protected $_query_toggle_count = 5; | |
protected $CI; | |
public function __construct($config = array()) | |
{ | |
$this->CI = get_instance(); | |
$this->CI->load->language('profiler'); | |
if (isset($config['query_toggle_count'])) | |
{ | |
$this->_query_toggle_count = (int) $config['query_toggle_count']; | |
unset($config['query_toggle_count']); | |
} | |
// default all sections to display | |
foreach ($this->_available_sections as $section) | |
{ | |
if ( ! isset($config[$section])) | |
{ | |
$this->_compile_{$section} = TRUE; | |
} | |
} | |
$this->set_sections($config); | |
} | |
/** | |
* Compile memory usage | |
* | |
* Display total used memory | |
* | |
* @return string | |
*/ | |
protected function _compile_memory_usage() | |
{ | |
$output = "\n\n"; | |
$output .= '<fieldset id="ci_profiler_memory_usage" style="border:1px solid #5a0099;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">'; | |
$output .= "\n"; | |
$output .= '<legend style="color:#5a0099;"> '.$this->CI->lang->line('profiler_memory_usage').' </legend>'; | |
$output .= "\n"; | |
if (function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '' | |
&& function_exists('memory_get_peak_usage') && ($peak = memory_get_peak_usage()) != '') | |
{ | |
$output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>Usate: ".number_format($usage)." bytes<br>\nPeak : " . number_format($peak) . ' bytes</div>'; | |
} | |
else | |
{ | |
$output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_memory')."</div>"; | |
} | |
$output .= "</fieldset>"; | |
return $output; | |
} | |
/** | |
* Run the Profiler | |
* | |
* @return string | |
*/ | |
public function run() | |
{ | |
$output = "<div id='codeigniter_profiler' style='clear:both;background-color:#fff;padding:10px;'>"; | |
$fields_displayed = 0; | |
foreach ($this->_available_sections as $section) | |
{ | |
if ($this->_compile_{$section} !== FALSE) | |
{ | |
$func = "_compile_{$section}"; | |
$output .= $this->{$func}(); | |
$fields_displayed++; | |
} | |
} | |
if ($fields_displayed == 0) | |
{ | |
$output .= '<p style="border:1px solid #5a0099;padding:10px;margin:20px 0;background-color:#eee">'.$this->CI->lang->line('profiler_no_profiles').'</p>'; | |
} | |
$output .= '</div>'; | |
// for CLI | |
if(defined('STDIN')) | |
{ | |
$line = "--------------------------------------------------"; | |
$output = "\n" . $line . $output . $line . "\n"; | |
$output = preg_replace("%\n\n\n|\n\n%u", "\n", str_replace(' ', '', strip_tags($output))); | |
} | |
$this->write($output); | |
return $output; | |
} | |
protected function write($data) | |
{ | |
return; | |
} | |
} | |
/* End of file MY_Profiler.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment