diff --git a/lib/xhprof/xhprof_moodle.php b/lib/xhprof/xhprof_moodle.php index 853e5f50d3b..28c41f30065 100644 --- a/lib/xhprof/xhprof_moodle.php +++ b/lib/xhprof/xhprof_moodle.php @@ -152,7 +152,7 @@ function profiling_start() { * Stop profiling, gathering results and storing them */ function profiling_stop() { - global $CFG, $SCRIPT; + global $CFG, $DB, $SCRIPT; // If profiling isn't available, nothing to stop if (!extension_loaded('xhprof') || !function_exists('xhprof_enable')) { @@ -176,6 +176,14 @@ function profiling_stop() { profiling_is_running(false); $data = xhprof_disable(); + // We only save the run after ensuring the DB table exists + // (this prevents problems with profiling runs enabled in + // config.php before Moodle is installed. Rare but... + $tables = $DB->get_tables(); + if (!in_array('profiling', $tables)) { + return false; + } + $run = new moodle_xhprofrun(); $run->prepare_run($script); $runid = $run->save_run($data, null);