From 4fbaa0b822033c8d85ccf07ecaa411cebf224b4f Mon Sep 17 00:00:00 2001 From: aude Date: Sun, 7 Oct 2012 12:15:57 +0000 Subject: [PATCH] update.php now create profiling table when needed When enabling $wgProfileToDatabase, one would have to manually apply a patch to the database that would add the `profiling` table. This patch let update.php creates the table whenever $wgProfileToDatabase is true. This also provide a SQL patch for SQLite backend and update profileinfo.php to give some clue about enabling the global and running update.php Change-Id: If68a25f7ec2b0fbb61f82a318427abe58a89dae7 --- includes/DefaultSettings.php | 4 +++- includes/installer/MysqlUpdater.php | 8 ++++++++ includes/installer/SqliteUpdater.php | 8 ++++++++ maintenance/sqlite/archives/patch-profiling.sql | 12 ++++++++++++ profileinfo.php | 6 +++--- 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 maintenance/sqlite/archives/patch-profiling.sql diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 494b2a378b..9621984bcb 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -4591,7 +4591,9 @@ $wgProfileOnly = false; * Log sums from profiling into "profiling" table in db. * * You have to create a 'profiling' table in your database before using - * this feature, see maintenance/archives/patch-profiling.sql + * this feature. Run set $wgProfileToDatabase to true in + * LocalSettings.php and run maintenance/update.php or otherwise + * manually add patch-profiling.sql to your database. * * To enable profiling, edit StartProfiler.php */ diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index 7cf382bcee..113c65a20c 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -226,6 +226,7 @@ class MysqlUpdater extends DatabaseUpdater { array( 'addField', 'filearchive', 'fa_sha1', 'patch-fa_sha1.sql' ), array( 'addField', 'job', 'job_token', 'patch-job_token.sql' ), array( 'addField', 'job', 'job_attempts', 'patch-job_attempts.sql' ), + array( 'doEnableProfiling' ), ); } @@ -772,6 +773,13 @@ class MysqlUpdater extends DatabaseUpdater { } } + protected function doEnableProfiling() { + global $wgProfileToDatabase; + if ( $wgProfileToDatabase === true && ! $this->db->tableExists( 'profiling', __METHOD__ ) ) { + $this->applyPatch( 'patch-profiling.sql', false, 'Add profiling table' ); + } + } + protected function doMaybeProfilingMemoryUpdate() { if ( !$this->db->tableExists( 'profiling', __METHOD__ ) ) { // Simply ignore diff --git a/includes/installer/SqliteUpdater.php b/includes/installer/SqliteUpdater.php index 3921defafb..472283de2f 100644 --- a/includes/installer/SqliteUpdater.php +++ b/includes/installer/SqliteUpdater.php @@ -106,6 +106,7 @@ class SqliteUpdater extends DatabaseUpdater { array( 'addField', 'filearchive', 'fa_sha1', 'patch-fa_sha1.sql' ), array( 'addField', 'job', 'job_token', 'patch-job_token.sql' ), array( 'addField', 'job', 'job_attempts', 'patch-job_attempts.sql' ), + array( 'doEnableProfiling' ), ); } @@ -129,4 +130,11 @@ class SqliteUpdater extends DatabaseUpdater { $this->output( "...fulltext search table appears to be in order.\n" ); } } + + protected function doEnableProfiling() { + global $wgProfileToDatabase; + if ( $wgProfileToDatabase === true && ! $this->db->tableExists( 'profiling', __METHOD__ ) ) { + $this->applyPatch( 'patch-profiling.sql', false, 'Add profiling table' ); + } + } } diff --git a/maintenance/sqlite/archives/patch-profiling.sql b/maintenance/sqlite/archives/patch-profiling.sql new file mode 100644 index 0000000000..4a07283c23 --- /dev/null +++ b/maintenance/sqlite/archives/patch-profiling.sql @@ -0,0 +1,12 @@ +-- profiling table +-- This is optional + +CREATE TABLE /*_*/profiling ( + pf_count int NOT NULL default 0, + pf_time float NOT NULL default 0, + pf_memory float NOT NULL default 0, + pf_name varchar(255) NOT NULL default '', + pf_server varchar(30) NOT NULL default '' +); + +CREATE UNIQUE INDEX /*i*/pf_name_server ON /*_*/profiling (pf_name, pf_server); diff --git a/profileinfo.php b/profileinfo.php index 068c58b83b..5c7c0e096b 100644 --- a/profileinfo.php +++ b/profileinfo.php @@ -156,9 +156,9 @@ $dbr = wfGetDB( DB_SLAVE ); if( !$dbr->tableExists( 'profiling' ) ) { echo '

No profiling table exists, so we can\'t show you anything.

' - . '

If you want to log profiling data, create the table using ' - . 'maintenance/archives/patch-profiling.sql and enable ' - . '$wgProfileToDatabase.

' + . '

If you want to log profiling data, enable $wgProfileToDatabase' + . ' in your LocalSettings.php and run maintenance/update.php to' + . ' create the profiling table.' . ''; exit( 1 ); } -- 2.20.1