From 90fd90d8ce3926e448c525138f644b74231e6402 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 5 Dec 2014 15:45:29 +1100 Subject: [PATCH] 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 --- includes/db/Database.php | 8 +++++++- includes/profiler/ProfilerStandard.php | 20 ++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) 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; + } + } ); } /** -- 2.20.1