function write_debug($message, $level = DEBUG_LEVEL_FULL){ // Only allow full debug messages to continue through if FULL DEBUG is enabled. if($level >= DEBUG_LEVEL_FULL && !FULL_DEBUG) return; $profiler = Profiler::GetDefaultProfiler(); // Grab how many ms have passed since the application started. $time = $profiler->getTime(); // Format this into a human readable format. $time = \Core\time_duration_format($time, 2); $time = str_pad($time, 10, '0', STR_PAD_LEFT); if (EXEC_MODE == 'CLI'){ // CLI gets no formatting and is just written to the screen. echo '[ DEBUG ' . $time . ' ] - ' . $message . "\n"; } elseif($level == DEBUG_LEVEL_LOG){ // LOG level messages just get error logged. error_log('[ DEBUG ' . $time . ' ] - ' . $message); } else{ echo '<pre class="xdebug-var-dump screen">[' . $time . '] ' . $message . '</pre>'; } }
/** * Created by PhpStorm. * User: charlie * Date: 2/20/16 * Time: 8:12 PM */ function smarty_function_duration($params, $smarty){ $duration = $params[0]; return \Core\time_duration_format($duration); }
/** * Get the overall execution time of this profiler. * * This will be rounded and formatted as such: * "# µs", "# ms", "# s", "# m # s", or "# h # m". * * @return string */ public function getTimeFormatted(){ $time = $this->getTime(); return \Core\time_duration_format($time, 4); }
/** * Get the breakdown of recorded events and their time into the profiler operation. * * @return string */ public function getEventTimesFormatted(){ $out = ''; $ql = $this->getEvents(); $qls = sizeof($this->_events); foreach($ql as $i => $dat){ if($i > 1000){ $out .= 'Plus ' . ($qls - 1000) . ' more!' . "\n"; break; } $typecolor = ($dat['type'] == 'read') ? '#88F' : '#005'; $tpad = ($dat['type'] == 'read') ? ' ' : ' '; $type = $dat['type']; $time = str_pad(\Core\time_duration_format($dat['time'], 2), 9, '0', STR_PAD_LEFT); $query = $dat['query']; $caller = print_r($dat['caller'], true); if($dat['rows'] !== null){ $caller .= "\n" . 'Number of affected rows: ' . $dat['rows']; } $out .= sprintf( "<span title='%s'><span style='color:%s;'>[%s]</span>%s[%s] <code class='sql'>%s</code></span>\n", $caller, $typecolor, $type, $tpad, $time, htmlentities($query, ENT_QUOTES | ENT_HTML5) ); } // Purge the output. Session::UnsetKey('datamodel_profiler_events/*'); return $out; }