*
* For output, add:
* $wgProfiler['output'] = array( 'text' );
- * 'text' can be one (or more) of 'text' 'udp' or 'db'
+ * 'text' can be one (or more) of 'text' 'udp' 'db' or 'dump'
* 'db' requires creating the profiling table, see patch-profiling.sql
*
* The 'text' output will be added to the output page in a comment approriate
* The 'db' output expects a database table that can be created by applying
* maintenance/archives/patch-profiling.sql to your database.
*
+ * The 'dump' output expects a $wgProfiler['outputDir'] telling it where to
+ * write dump files. The files produced are compatible with the XHProf gui.
+ *
* For a rudimentary sampling profiler:
* $wgProfiler['class'] = 'ProfilerXhprof';
* $wgProfiler['output'] = array( 'db' );
'Profiler' => __DIR__ . '/includes/profiler/Profiler.php',
'ProfilerOutput' => __DIR__ . '/includes/profiler/output/ProfilerOutput.php',
'ProfilerOutputDb' => __DIR__ . '/includes/profiler/output/ProfilerOutputDb.php',
+ 'ProfilerOutputDump' => __DIR__ . '/includes/profiler/output/ProfilerOutputDump.php',
'ProfilerOutputText' => __DIR__ . '/includes/profiler/output/ProfilerOutputText.php',
'ProfilerOutputUdp' => __DIR__ . '/includes/profiler/output/ProfilerOutputUdp.php',
'ProfilerSectionOnly' => __DIR__ . '/includes/profiler/ProfilerSectionOnly.php',
'db' => 'ProfilerOutputDb',
'text' => 'ProfilerOutputText',
'udp' => 'ProfilerOutputUdp',
+ 'dump' => 'ProfilerOutputDump',
);
/** @var Profiler */
if ( !is_array( $output ) ) {
$output = array( $output );
}
-
+ $stats = null;
foreach ( $output as $outType ) {
if ( !isset( self::$outputTypes[$outType] ) ) {
throw new MWException( "'$outType' is an invalid output type" );
/** @var ProfilerOutput $profileOut */
$profileOut = new $class( $this, $this->params );
if ( $profileOut->canUse() ) {
- $profileOut->log( $this->getFunctionStats() );
+ if ( is_null( $stats ) ) {
+ $stats = $this->getFunctionStats();
+ }
+ $profileOut->log( $stats );
}
}
}
}
return implode( "\n", $out );
}
+
+ /**
+ * Retrieve raw data from xhprof
+ * @return array
+ */
+ public function getRawData() {
+ return $this->xhprof->getRawData();
+ }
}
--- /dev/null
+<?php
+/**
+ * Profiler dumping output in xhprof dump file
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Profiler
+ */
+
+/**
+ * Profiler dumping output in xhprof dump file
+ * @ingroup Profiler
+ *
+ * @since 1.25
+ */
+class ProfilerOutputDump extends ProfilerOutput {
+
+ protected $suffix = ".xhprof";
+
+ /**
+ * Can this output type be used?
+ *
+ * @return bool
+ */
+ public function canUse() {
+ if ( empty( $this->params['outputDir'] ) ) {
+ return false;
+ }
+ return true;
+ }
+
+ public function log( array $stats ) {
+ $data = $this->collector->getRawData();
+ $filename = sprintf( "%s/%s.%s%s", $this->params['outputDir'], uniqid(), $this->collector->getProfileID(), $this->suffix );
+ file_put_contents( $filename, serialize( $data ) );
+ }
+}