/** * @inheritdoc */ public static function finish($labelOrFormat = null, $args = null, $_ = null) { if (static::$enabled) { if ($labelOrFormat === null) { $labelOrFormat = static::getCurrentFileHashLine(1); $args = null; $_ = null; } $profile = parent::finish($labelOrFormat, $args, $_); if (static::$postProcessor === null) { return $profile; } return call_user_func(static::$postProcessor, $profile); } return false; }
</ul> <!-- cd-tabs-content --> <?php if (isset($_COOKIE['debug']) && $_COOKIE['debug'] == True) { ?> <div style="padding: 4em 0 2em 2em;"> <div style="padding-bottom: 1em; font-weight: bold; font-size: 1.5em;"> Debug Information </div> <div style="padding-bottom: 2em;"> <div style="padding: 1em 0; font-weight: bold; font-size: 1.2em;"> PHP Profile </div> <?php SimpleProfiler::stop_profile(); $profile = SimpleProfiler::get_profile(); $grand_total = 0.0; foreach ($profile as $array => $next) { foreach ($next as $key => $value) { $grand_total += $value; } } $step_total = 0.0; echo ' <table class="debug-profiler"> <tr> <td> Event </td> <td> Event (seconds)
/** * Profile. * This records the source class / function / file of the current tickable event * and the time between now and the last tickable event. This information is * stored in self::$_profile * @access public * @return void */ public static function do_profile() { $frame = NULL; // Get the backtrace, keep the object in case we need to reflect // upon it to find the original source file if (version_compare(PHP_VERSION, '5.3.6') < 0) { $bt = debug_backtrace(true); } elseif (version_compare(PHP_VERSION, '5.4.0') < 0) { $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); } else { // Examine the last 2 frames $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT, 2); } // Find the calling function $frame = $bt[0]; if (count($bt) >= 2) { $frame = $bt[1]; } // If the calling function was a lambda, the original file is stored here. // Copy this elsewhere before unsetting the backtrace $lambda_file = @$bt[0]['file']; // Free up memory unset($bt); // Include/require if (in_array(strtolower($frame['function']), array('include', 'require', 'include_once', 'require_once'))) { $file = $frame['args'][0]; // Object instances } elseif (isset($frame['object']) && method_exists($frame['object'], $frame['function'])) { try { $reflector = new ReflectionMethod($frame['object'], $frame['function']); $file = $reflector->getFileName(); } catch (Exception $e) { } // Static method calls } elseif (isset($frame['class']) && method_exists($frame['class'], $frame['function'])) { try { $reflector = new ReflectionMethod($frame['class'], $frame['function']); $file = $reflector->getFileName(); } catch (Exception $e) { } // Functions } elseif (!empty($frame['function']) && function_exists($frame['function'])) { try { $reflector = new ReflectionFunction($frame['function']); $file = $reflector->getFileName(); } catch (Exception $e) { } // Lambdas / closures } elseif ('__lambda_func' == $frame['function'] || '{closure}' == $frame['function']) { $file = preg_replace('/\\(\\d+\\)\\s+:\\s+runtime-created function/', '', $lambda_file); // File info only } elseif (isset($frame['file'])) { $file = $frame['file']; // If we get here, we have no idea where the call came from. // Assume it originated in the script the user requested. } else { $file = $_SERVER['SCRIPT_FILENAME']; } // Function $function = $frame['function']; if (isset($frame['object'])) { $function = get_class($frame['object']) . '::' . $function; } // Create the entry for the file if (!isset(self::$_profile[$file])) { self::$_profile[$file] = array(); } // Create the entry for the function if (!isset(self::$_profile[$file][$function])) { self::$_profile[$file][$function] = 0; } // Record the call self::$_profile[$file][$function] += microtime(true) - self::$_last_time; self::$_last_time = microtime(true); }
function start_profiler() { declare (ticks=1); require_once './classes/SimpleProfiler.php'; SimpleProfiler::start_profile(); }