r48017 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48016‎ | r48017 | r48018 >
Date:09:37, 4 March 2009
Author:midom
Status:deferred
Tags:
Comment:
a handy development utility!
Modified paths:
  • /trunk/phase3/includes/ProfilerSimpleTrace.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/ProfilerSimpleTrace.php
@@ -0,0 +1,66 @@
 2+<?php
 3+/**
 4+ * @file
 5+ * @ingroup Profiler
 6+ */
 7+
 8+if ( !class_exists( 'ProfilerSimple' ) ) {
 9+ require_once(dirname(__FILE__).'/ProfilerSimple.php');
 10+}
 11+
 12+/**
 13+ * Execution trace
 14+ * @todo document methods (?)
 15+ * @ingroup Profiler
 16+ */
 17+class ProfilerSimpleTrace extends ProfilerSimple {
 18+ var $mMinimumTime = 0;
 19+ var $mProfileID = false;
 20+ var $trace = "";
 21+
 22+ function __construct() {
 23+ global $wgRequestTime, $wgRUstart;
 24+ if (!empty($wgRequestTime) && !empty($wgRUstart)) {
 25+ $this->mWorkStack[] = array( '-total', 0, $wgRequestTime,$this->getCpuTime($wgRUstart));
 26+ $elapsedcpu = $this->getCpuTime() - $this->getCpuTime($wgRUstart);
 27+ $elapsedreal = microtime(true) - $wgRequestTime;
 28+ }
 29+ $this->trace .= "Beginning trace: \n";
 30+ }
 31+
 32+ function profileIn($functionname) {
 33+ global $wgDebugFunctionEntry;
 34+ $this->mWorkStack[] = array($functionname, count( $this->mWorkStack ), microtime(true), $this->getCpuTime());
 35+ $this->trace .= str_repeat( " ", count($this->mWorkStack) + 14) . " > " . $functionname . "\n";
 36+ }
 37+
 38+ function profileOut($functionname) {
 39+ global $wgDebugFunctionEntry;
 40+
 41+ if ($wgDebugFunctionEntry) {
 42+ $this->debug(str_repeat(' ', count($this->mWorkStack) - 1).'Exiting '.$functionname."\n");
 43+ }
 44+
 45+ list($ofname, /* $ocount */ ,$ortime,$octime) = array_pop($this->mWorkStack);
 46+
 47+ if (!$ofname) {
 48+ $this->trace .= "Profiling error: $functionname\n";
 49+ } else {
 50+ if ($functionname == 'close') {
 51+ $message = "Profile section ended by close(): {$ofname}";
 52+ $functionname = $ofname;
 53+ $this->trace .= $message . "\n";
 54+ }
 55+ elseif ($ofname != $functionname) {
 56+ $self->trace .= "Profiling error: in({$ofname}), out($functionname)";
 57+ }
 58+ $elapsedcpu = $this->getCpuTime() - $octime;
 59+ $elapsedreal = microtime(true) - $ortime;
 60+ $this->trace .= sprintf("%03.6f ",$elapsedreal) . str_repeat(" ",count($this->mWorkStack)+1) . " < " . $functionname . "\n";
 61+ }
 62+ }
 63+
 64+ function getOutput() {
 65+ print "<!-- \n {$this->trace} \n -->";
 66+ }
 67+}

Status & tagging log