From 2fd015b161f133cbb2de072100569b9413bc3dab Mon Sep 17 00:00:00 2001 From: Domas Mituzas Date: Tue, 17 Mar 2009 19:46:05 +0000 Subject: [PATCH] add memory tracing --- includes/ProfilerSimpleTrace.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/includes/ProfilerSimpleTrace.php b/includes/ProfilerSimpleTrace.php index fcd79ac5ef..631192288c 100644 --- a/includes/ProfilerSimpleTrace.php +++ b/includes/ProfilerSimpleTrace.php @@ -17,6 +17,7 @@ class ProfilerSimpleTrace extends ProfilerSimple { var $mMinimumTime = 0; var $mProfileID = false; var $trace = ""; + var $memory = 0; function __construct() { global $wgRequestTime, $wgRUstart; @@ -31,7 +32,7 @@ class ProfilerSimpleTrace extends ProfilerSimple { function profileIn($functionname) { global $wgDebugFunctionEntry; $this->mWorkStack[] = array($functionname, count( $this->mWorkStack ), microtime(true), $this->getCpuTime()); - $this->trace .= str_repeat( " ", count($this->mWorkStack) + 14) . " > " . $functionname . "\n"; + $this->trace .= " " . sprintf("%6.1f",$this->memoryDiff()) . str_repeat( " ", count($this->mWorkStack)) . " > " . $functionname . "\n"; } function profileOut($functionname) { @@ -56,9 +57,15 @@ class ProfilerSimpleTrace extends ProfilerSimple { } $elapsedcpu = $this->getCpuTime() - $octime; $elapsedreal = microtime(true) - $ortime; - $this->trace .= sprintf("%03.6f ",$elapsedreal) . str_repeat(" ",count($this->mWorkStack)+1) . " < " . $functionname . "\n"; + $this->trace .= sprintf("%03.6f %6.1f",$elapsedreal,$this->memoryDiff()) . str_repeat(" ",count($this->mWorkStack)+1) . " < " . $functionname . "\n"; } } + + function memoryDiff() { + $diff = memory_get_usage() - $this->memory; + $this->memory = memory_get_usage(); + return $diff/1024; + } function getOutput() { print ""; -- 2.20.1