3 * Profiler storing information in the DB.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Logs profiling data into the local DB
27 * $wgProfiler['class'] = 'ProfilerSimpleDB';
32 class ProfilerOutputDb
extends ProfilerOutput
{
33 public function canUse() {
34 # Do not log anything if database is readonly (bug 5375)
38 protected function logStandardData( array $stats ) {
39 global $wgProfilePerHost;
41 if ( $wgProfilePerHost ) {
42 $pfhost = wfHostname();
48 $dbw = wfGetDB( DB_MASTER
);
49 $useTrx = ( $dbw->getType() === 'sqlite' ); // much faster
51 $dbw->startAtomic( __METHOD__
);
53 foreach ( $stats as $data ) {
54 $name = $data['name'];
55 $eventCount = $data['calls'];
56 $timeSum = (float)$data['real'];
57 $memorySum = (float)$data['memory'];
58 $name = substr( $name, 0, 255 );
61 $timeSum = $timeSum >= 0 ?
$timeSum : 0;
62 $memorySum = $memorySum >= 0 ?
$memorySum : 0;
64 $dbw->upsert( 'profiling',
67 'pf_count' => $eventCount,
68 'pf_time' => $timeSum,
69 'pf_memory' => $memorySum,
70 'pf_server' => $pfhost
72 array( array( 'pf_name', 'pf_server' ) ),
74 "pf_count=pf_count+{$eventCount}",
75 "pf_time=pf_time+{$timeSum}",
76 "pf_memory=pf_memory+{$memorySum}",
82 $dbw->endAtomic( __METHOD__
);
84 } catch ( DBError
$e ) {