Tim Starling has submitted this change and it was merged.
Change subject: Created ProfileSection class to avoid wfProfileOut()
whack-a-mole.
......................................................................
Created ProfileSection class to avoid wfProfileOut() whack-a-mole.
Change-Id: I9f7e0638edd99e1ac07b83054e8f7ef255179281
---
M includes/AutoLoader.php
M includes/profiler/Profiler.php
2 files changed, 42 insertions(+), 1 deletion(-)
Approvals:
Tim Starling: Verified; Looks good to me, approved
diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index 4813d45..9cdf1a4 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -819,6 +819,7 @@
'ProfilerSimpleTrace' => 'includes/profiler/ProfilerSimpleTrace.php',
'ProfilerSimpleUDP' => 'includes/profiler/ProfilerSimpleUDP.php',
'ProfilerStub' => 'includes/profiler/ProfilerStub.php',
+ 'ProfileSection' => 'includes/profiler/Profiler.php',
# includes/resourceloader
'ResourceLoader' => 'includes/resourceloader/ResourceLoader.php',
diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php
index 49d961e..c77fef5 100644
--- a/includes/profiler/Profiler.php
+++ b/includes/profiler/Profiler.php
@@ -49,6 +49,44 @@
}
/**
+ * Class for handling function-scope profiling
+ *
+ * @since 1.22
+ */
+class ProfileSection {
+ protected $name; // string; method name
+ protected $enabled = false; // boolean; whether profiling is enabled
+
+ /**
+ * Begin profiling of a function and return an object that ends
profiling of
+ * the function when that object leaves scope. As long as the object is
not
+ * specifically linked to other objects, it will fall out of scope at
the same
+ * moment that the function to be profiled terminates.
+ *
+ * This is typically called like:
+ * <code>$section = new ProfileSection( __METHOD__ );</code>
+ *
+ * @param string $name Name of the function to profile
+ */
+ public function __construct( $name ) {
+ $this->name = $name;
+ if ( Profiler::$__instance === null ) { // use this directly to
reduce overhead
+ Profiler::instance();
+ }
+ if ( Profiler::$__instance && !( Profiler::$__instance
instanceof ProfilerStub ) ) {
+ $this->enabled = true;
+ Profiler::$__instance->profileIn( $this->name );
+ }
+ }
+
+ function __destruct() {
+ if ( $this->enabled ) {
+ Profiler::$__instance->profileOut( $this->name );
+ }
+ }
+}
+
+/**
* @ingroup Profiler
* @todo document
*/
@@ -57,7 +95,9 @@
$mCalls = array(), $mTotals = array();
protected $mTimeMetric = 'wall';
protected $mProfileID = false, $mCollateDone = false, $mTemplated =
false;
- private static $__instance = null;
+
+ /** @var Profiler */
+ public static $__instance = null; // do not call this outside Profiler
and ProfileSection
function __construct( $params ) {
if ( isset( $params['timeMetric'] ) ) {
--
To view, visit https://gerrit.wikimedia.org/r/60797
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9f7e0638edd99e1ac07b83054e8f7ef255179281
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Platonides <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits