jenkins-bot has submitted this change and it was merged.

Change subject: Fixed running percents in SectionProfiler
......................................................................


Fixed running percents in SectionProfiler

* Previously it assumed methods never overlapped.
* Also fixed running collation when in trace mode.

Change-Id: I6cbf5384a57ea68197495173d75732f5df328040
---
M includes/profiler/SectionProfiler.php
1 file changed, 52 insertions(+), 16 deletions(-)

Approvals:
  BryanDavis: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/profiler/SectionProfiler.php 
b/includes/profiler/SectionProfiler.php
index 5591c99..d28c36a 100644
--- a/includes/profiler/SectionProfiler.php
+++ b/includes/profiler/SectionProfiler.php
@@ -28,6 +28,10 @@
  * @since 1.25
  */
 class SectionProfiler {
+       /** @var array Map of (mem,real,cpu) */
+       protected $start;
+       /** @var array Map of (mem,real,cpu) */
+       protected $end;
        /** @var array List of resolved profile calls with start/end data */
        protected $stack = array();
        /** @var array Queue of open profile calls with start data */
@@ -37,9 +41,9 @@
        protected $collated = array();
        /** @var bool */
        protected $collateDone = false;
+
        /** @var bool Whether to collect the full stack trace or just 
aggregates */
        protected $collateOnly = true;
-
        /** @var array Cache of a standard broken collation entry */
        protected $errorEntry;
 
@@ -93,14 +97,9 @@
        public function getFunctionStats() {
                $this->collateData();
 
-               $totalCpu = 0.0;
-               $totalReal = 0.0;
-               $totalMem = 0;
-               foreach ( $this->collated as $fname => $data ) {
-                       $totalCpu += $data['cpu'];
-                       $totalReal += $data['real'];
-                       $totalMem += $data['memory'];
-               }
+               $totalCpu = max( $this->end['cpu'] - $this->start['cpu'], 0 );
+               $totalReal = max( $this->end['real'] - $this->start['real'], 0 
);
+               $totalMem = max( $this->end['memory'] - $this->start['memory'], 
0 );
 
                $profile = array();
                foreach ( $this->collated as $fname => $data ) {
@@ -128,6 +127,18 @@
                );
 
                return $profile;
+       }
+
+       /**
+        * Clear all of the profiling data for another run
+        */
+       public function reset() {
+               $this->start = null;
+               $this->end = null;
+               $this->stack = array();
+               $this->workStack = array();
+               $this->collated = array();
+               $this->collateDone = false;
        }
 
        /**
@@ -177,12 +188,25 @@
         * @param string $functionname
         */
        public function profileInInternal( $functionname ) {
+               // Once the data is collated for reports, any future calls
+               // should clear the collation cache so the next report will
+               // reflect them. This matters when trace mode is used.
+               $this->collateDone = false;
+
+               $cpu = $this->getTime( 'cpu' );
+               $real = $this->getTime( 'wall' );
+               $memory = memory_get_usage();
+
+               if ( $this->start === null ) {
+                       $this->start = array( 'cpu' => $cpu, 'real' => $real, 
'memory' => $memory );
+               }
+
                $this->workStack[] = array(
                        $functionname,
                        count( $this->workStack ),
-                       $this->getTime( 'time' ),
-                       $this->getTime( 'cpu' ),
-                       memory_get_usage()
+                       $real,
+                       $cpu,
+                       $memory
                );
        }
 
@@ -217,17 +241,25 @@
                                $this->stack[] = array( $message, 0, 0.0, 0.0, 
0, 0.0, 0.0, 0 );
                        }
                }
+
                $realTime = $this->getTime( 'wall' );
                $cpuTime = $this->getTime( 'cpu' );
+               $memUsage = memory_get_usage();
+
                if ( $this->collateOnly ) {
                        $elapsedcpu = $cpuTime - $octime;
                        $elapsedreal = $realTime - $ortime;
-                       $memchange = memory_get_usage() - $omem;
+                       $memchange = $memUsage - $omem;
                        $this->updateEntry( $functionname, $elapsedcpu, 
$elapsedreal, $memchange );
                } else {
-                       $this->stack[] = array_merge( $item,
-                               array( $realTime, $cpuTime,     
memory_get_usage() ) );
+                       $this->stack[] = array_merge( $item, array( $realTime, 
$cpuTime, $memUsage ) );
                }
+
+               $this->end = array(
+                       'cpu'      => $cpuTime,
+                       'real'     => $realTime,
+                       'memory'   => $memUsage
+               );
        }
 
        /**
@@ -320,6 +352,7 @@
                $this->collated = array();
 
                # Estimate profiling overhead
+               $oldEnd = $this->end;
                $profileCount = count( $this->stack );
                $this->calculateOverhead( $profileCount );
 
@@ -355,7 +388,7 @@
                        $subcalls = $this->calltreeCount( $this->stack, $index 
);
 
                        if ( substr( $fname, 0, 9 ) !== '-overhead' ) {
-                               # Adjust for profiling overhead (except special 
values with elapsed=0
+                               # Adjust for profiling overhead (except special 
values with elapsed=0)
                                if ( $elapsed ) {
                                        $elapsed -= $overheadInternal;
                                        $elapsed -= ( $subcalls * 
$overheadTotal );
@@ -368,6 +401,9 @@
 
                $this->collated['-overhead-total']['count'] = $profileCount;
                arsort( $this->collated, SORT_NUMERIC );
+
+               // Unclobber the end info map (the overhead checking alters it)
+               $this->end = $oldEnd;
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/177414
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6cbf5384a57ea68197495173d75732f5df328040
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to