From: Tim Starling Date: Fri, 5 Dec 2014 04:45:29 +0000 (+1100) Subject: Fix ProfilerStandard sorting and a profile error X-Git-Tag: 1.31.0-rc.0~12998 X-Git-Url: http://git.cyclocoop.org/wiki/Target_page?a=commitdiff_plain;h=90fd90d8ce3926e448c525138f644b74231e6402;p=lhc%2Fweb%2Fwiklou.git Fix ProfilerStandard sorting and a profile error * Sort $this->collated even if collateOnly is set. Also I don't think arsort works that way. * Fix a profiling error in every DB query, which was due to the two scoped profiling sections being destroyed in the wrong order. Change-Id: I6af05f37a5c0391acfa80d54ecbca7a08ad81250 --- diff --git a/includes/db/Database.php b/includes/db/Database.php index eb9d9b3b48..93ce61f79d 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1198,7 +1198,13 @@ abstract class DatabaseBase implements IDatabase { $this->reportQueryError( $this->lastError(), $this->lastErrno(), $sql, $fname, $tempIgnore ); } - return $this->resultObject( $ret ); + $res = $this->resultObject( $ret ); + + // Destroy profile sections in the opposite order to their creation + $queryProfSection = false; + $totalProfSection = false; + + return $res; } /** diff --git a/includes/profiler/ProfilerStandard.php b/includes/profiler/ProfilerStandard.php index b40519e089..4ce88bdbcc 100644 --- a/includes/profiler/ProfilerStandard.php +++ b/includes/profiler/ProfilerStandard.php @@ -345,7 +345,9 @@ class ProfilerStandard extends Profiler { $this->close(); // set "-total" entry if ( $this->collateOnly ) { - return; // already collated as methods exited + // already collated as methods exited + $this->sortCollated(); + return; } $this->collated = array(); @@ -400,7 +402,21 @@ class ProfilerStandard extends Profiler { } $this->collated['-overhead-total']['count'] = $profileCount; - arsort( $this->collated, SORT_NUMERIC ); + $this->sortCollated(); + } + + protected function sortCollated() { + uksort( $this->collated, function ( $a, $b ) { + $ca = $this->collated[$a]['real']; + $cb = $this->collated[$b]['real']; + if ( $ca > $cb ) { + return -1; + } elseif ( $cb > $ca ) { + return 1; + } else { + return 0; + } + } ); } /**