* @since 1.25
*/
class ProfilerOutputDb extends ProfilerOutput {
+ /** @var bool Whether to store host data with profiling calls */
+ private $perHost = false;
+
+ public function __construct( Profiler $collector, array $params ) {
+ parent::__construct( $collector, $params );
+
+ // Initialize per-host profiling from config, back-compat if available
+ if ( isset( $this->params['perHost'] ) ) {
+ $this->perHost = $this->params['perHost'];
+ }
+ }
+
public function canUse() {
# Do not log anything if database is readonly (bug 5375)
return !wfReadOnly();
}
public function log( array $stats ) {
- global $wgProfilePerHost;
-
- if ( $wgProfilePerHost ) {
- $pfhost = wfHostname();
- } else {
- $pfhost = '';
- }
+ $pfhost = $this->perHost ? wfHostname() : '';
try {
$dbw = wfGetDB( DB_MASTER );
$memorySum = $memorySum >= 0 ? $memorySum : 0;
$dbw->upsert( 'profiling',
- array(
+ [
'pf_name' => $name,
'pf_count' => $eventCount,
'pf_time' => $timeSum,
'pf_memory' => $memorySum,
'pf_server' => $pfhost
- ),
- array( array( 'pf_name', 'pf_server' ) ),
- array(
+ ],
+ [ [ 'pf_name', 'pf_server' ] ],
+ [
"pf_count=pf_count+{$eventCount}",
"pf_time=pf_time+{$timeSum}",
"pf_memory=pf_memory+{$memorySum}",
- ),
+ ],
__METHOD__
);
}