update.php now create profiling table when needed
authoraude <aude.wiki@gmail.com>
Sun, 7 Oct 2012 12:15:57 +0000 (12:15 +0000)
committerAntoine Musso <hashar@free.fr>
Mon, 19 Nov 2012 11:38:32 +0000 (12:38 +0100)
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
includes/installer/MysqlUpdater.php
includes/installer/SqliteUpdater.php
maintenance/sqlite/archives/patch-profiling.sql [new file with mode: 0644]
profileinfo.php

index 494b2a3..9621984 100644 (file)
@@ -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
  */
index 7cf382b..113c65a 100644 (file)
@@ -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
index 3921def..472283d 100644 (file)
@@ -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 (file)
index 0000000..4a07283
--- /dev/null
@@ -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);
index 068c58b..5c7c0e0 100644 (file)
@@ -156,9 +156,9 @@ $dbr = wfGetDB( DB_SLAVE );
 
 if( !$dbr->tableExists( 'profiling' ) ) {
        echo '<p>No <code>profiling</code> table exists, so we can\'t show you anything.</p>'
-               . '<p>If you want to log profiling data, create the table using '
-               . '<code>maintenance/archives/patch-profiling.sql</code> and enable '
-               . '<code>$wgProfileToDatabase</code>.</p>'
+               . '<p>If you want to log profiling data, enable <code>$wgProfileToDatabase</code>'
+               . ' in your LocalSettings.php and run <code>maintenance/update.php</code> to'
+               . ' create the profiling table.'
                . '</body></html>';
        exit( 1 );
 }