Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/175170
Change subject: Added custom frame support to Profiler
......................................................................
Added custom frame support to Profiler
* Made use of it in the DatabaseBase classes
* For the xhprof class, this only works in HHVM for now
Change-Id: I95d7cc128d4a770328fbdd2b546972d3fc2e2e8a
---
M includes/db/Database.php
M includes/profiler/Profiler.php
M includes/profiler/ProfilerStandard.php
M includes/profiler/ProfilerStub.php
M includes/profiler/ProfilerXhprof.php
5 files changed, 51 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/70/175170/1
diff --git a/includes/db/Database.php b/includes/db/Database.php
index e5332d2..a8ecdc4 100644
--- a/includes/db/Database.php
+++ b/includes/db/Database.php
@@ -962,7 +962,8 @@
$totalProf = '';
$isMaster = !is_null( $this->getLBInfo( 'master' ) );
- if ( !Profiler::instance()->isStub() ) {
+ $profiler = Profiler::instance();
+ if ( !$profiler->isStub() ) {
# generalizeSQL will probably cut down the query to
reasonable
# logging size most of the time. The substr is really
just a sanity check.
if ( $isMaster ) {
@@ -976,8 +977,8 @@
$queryProf .= $this->mTrxShortId ? "
[TRX#{$this->mTrxShortId}]" : "";
$trx = $this->mTrxLevel ? 'TRX=yes' : 'TRX=no';
- wfProfileIn( $totalProf );
- wfProfileIn( $queryProf );
+ $totalProfSection = $profiler->scopedProfileIn(
$totalProf );
+ $queryProfSection = $profiler->scopedProfileIn(
$queryProf );
}
if ( $this->debug() ) {
diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php
index 2b3b616..9650ff5 100644
--- a/includes/profiler/Profiler.php
+++ b/includes/profiler/Profiler.php
@@ -140,6 +140,23 @@
abstract public function profileOut( $functionname );
/**
+ * Mark the start of a custom profiling frame (e.g. DB queries).
+ * The frame ends when the result of this method falls out of scope.
+ *
+ * @param string $section
+ * @return ScopedCallback|null
+ * @since 1.25
+ */
+ abstract public function scopedProfileIn( $section );
+
+ /**
+ * @param ScopedCallback $section
+ */
+ public function scopedProfileOut( ScopedCallback &$section ) {
+ $section = null;
+ }
+
+ /**
* @return TransactionProfiler
* @since 1.25
*/
diff --git a/includes/profiler/ProfilerStandard.php
b/includes/profiler/ProfilerStandard.php
index 15c5cdd..ab5e3ab 100644
--- a/includes/profiler/ProfilerStandard.php
+++ b/includes/profiler/ProfilerStandard.php
@@ -227,6 +227,15 @@
}
}
+ public function scopedProfileIn( $section ) {
+ $this->profileIn( $section );
+
+ $that = $this;
+ return new ScopedCallback( function() use ( $that, $section ) {
+ $that->profileOut( $section );
+ } );
+ }
+
/**
* Close opened profiling sections
*/
diff --git a/includes/profiler/ProfilerStub.php
b/includes/profiler/ProfilerStub.php
index 510a0a0..6fc74ef 100644
--- a/includes/profiler/ProfilerStub.php
+++ b/includes/profiler/ProfilerStub.php
@@ -37,6 +37,10 @@
public function profileOut( $fn ) {
}
+ public function scopedProfileIn( $section ) {
+ return null;
+ }
+
public function getFunctionStats() {
}
diff --git a/includes/profiler/ProfilerXhprof.php
b/includes/profiler/ProfilerXhprof.php
index d67806b..cbd081d 100644
--- a/includes/profiler/ProfilerXhprof.php
+++ b/includes/profiler/ProfilerXhprof.php
@@ -122,6 +122,23 @@
public function profileOut( $functionname ) {
}
+ public function scopedProfileIn( $section ) {
+ static $exists = null;
+ // Only HHVM supports this, not the standard PECL extension
+ if ( $exists === null ) {
+ $exists = function_exists( 'xhprof_frame_begin' );
+ }
+
+ if ( $exists ) {
+ xhprof_frame_begin( $section );
+ return new ScopedCallback( function() use ( $section ) {
+ xhprof_frame_end( $section );
+ } );
+ }
+
+ return null;
+ }
+
/**
* No-op for xhprof profiling.
*/
--
To view, visit https://gerrit.wikimedia.org/r/175170
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I95d7cc128d4a770328fbdd2b546972d3fc2e2e8a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits