/** * Stop profiling, gathering results and storing them */ function profiling_stop() { global $CFG, $DB, $SCRIPT; // If profiling isn't available, nothing to stop if (!extension_loaded('xhprof') || !function_exists('xhprof_enable')) { return false; } // If profiling isn't enabled, nothing to stop if (empty($CFG->profilingenabled) && empty($CFG->earlyprofilingenabled)) { return false; } // If profiling is not running or is already saved, nothing to stop if (!profiling_is_running() || profiling_is_saved()) { return false; } // Set script (from global if available, else our own) $script = !empty($SCRIPT) ? $SCRIPT : profiling_get_script(); // Arrived here, profiling is running, stop and save everything 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); profiling_is_saved(true); // Prune old runs profiling_prune_old_runs($runid); // Finished, return true return true; }
/** * Stop profiling, gathering results and storing them */ function profiling_stop() { global $CFG, $SCRIPT; // If profiling isn't available, nothing to stop if (!extension_loaded('xhprof') || !function_exists('xhprof_enable')) { return false; } // If profiling isn't enabled, nothing to stop if (!$CFG->profilingenabled) { return false; } // If profiling is not running or is already saved, nothing to stop if (!profiling_is_running() || profiling_is_saved()) { return false; } // Arrived here, profiling is running, stop and save everything profiling_is_running(false); $data = xhprof_disable(); $run = new moodle_xhprofrun(); $run->prepare_run($SCRIPT); $runid = $run->save_run($data, null); profiling_is_saved(true); // Prune old runs profiling_prune_old_runs($runid); }