From 0a02afaa06ec4b2a5fd0faaf4cbf13fe77be8ad9 Mon Sep 17 00:00:00 2001 From: Benjamin Walker Date: Fri, 24 May 2024 17:11:57 +1000 Subject: [PATCH] Add toggle for partial save --- classes/web_processor.php | 11 ++++++++--- lang/en/tool_excimer.php | 9 +++++++-- settings.php | 9 +++++++++ version.php | 4 ++-- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/classes/web_processor.php b/classes/web_processor.php index df4f0fa..2925f3e 100644 --- a/classes/web_processor.php +++ b/classes/web_processor.php @@ -40,6 +40,8 @@ class web_processor implements processor { protected $minduration; /** @var int */ protected $samplems; + /** @var bool */ + protected $partialsave; /** * Construct the web processor. @@ -48,6 +50,7 @@ public function __construct() { // Preload config values to avoid DB access during processing. See manager::get_altconnection() for more information. $this->minduration = (float) get_config('tool_excimer', 'trigger_ms') / 1000.0; $this->samplems = (int) get_config('tool_excimer', 'sample_ms'); + $this->partialsave = get_config('tool_excimer', 'enable_partial_save'); } /** @@ -73,9 +76,11 @@ public function init(manager $manager) { $this->profile->add_env($this->sampleset->name); $this->profile->set('created', $this->sampleset->starttime); - $manager->get_timer()->setCallback(function () use ($manager) { - $this->process($manager, false); - }); + if ($this->partialsave) { + $manager->get_timer()->setCallback(function () use ($manager) { + $this->process($manager, false); + }); + } \core_shutdown_manager::register_function( function () use ($manager) { diff --git a/lang/en/tool_excimer.php b/lang/en/tool_excimer.php index 8dfa1c7..5ac2542 100644 --- a/lang/en/tool_excimer.php +++ b/lang/en/tool_excimer.php @@ -55,6 +55,10 @@ $string['enable_auto_desc'] = 'Any page will be automatically profiled if they exceed the miniumum duration.'; $string['enable_fuzzy_count'] = 'Enable fuzzy counting'; $string['enable_fuzzy_count_desc'] = 'This will cause the plugin to maintain an approximate count of page runs using the {$a}. Automatic profiling must also be enabled.'; +$string['enable_partial_save'] = 'Enable partial save'; +$string['enable_partial_save_desc'] = 'This will save partial profiles of slow web processes every processing interval. This + provides information about these processes while they are still running or if a container gets reaped, but the extra writes + can be problematic when experiencing large scale database issues.'; $string['expiry_s'] = 'Log expiry (days)'; $string['expiry_s_desc'] = 'Remove profiles after this long.'; $string['num_slowest'] = 'Max to save'; @@ -66,8 +70,9 @@ $string['num_slowest_by_page'] = 'Max to save by page'; $string['num_slowest_by_page_desc'] = 'Only the N slowest profiles will be kept for each script page.'; $string['noexcimerprofiler'] = 'ExcimerProfiler class does not exist so profiling cannot continue. Please check the installation instructions {$a}.'; -$string['long_interval_s'] = 'Partial save interval (seconds)'; -$string['long_interval_s_desc'] = 'For long running taks, save a partial profile every N seconds.'; +$string['long_interval_s'] = 'Processing interval (seconds)'; +$string['long_interval_s_desc'] = 'Checks the current status of long running tasks every N seconds and processes as required. + This includes saving profiles of finished cron tasks and partial saves of ongoing web processes if enabled.'; $string['task_min_duration'] = 'Task min duration (seconds)'; $string['task_min_duration_desc'] = 'For scheduled and ad-hoc tasks, the minimum approx duration, in seconds.'; $string['samplelimit'] = 'Sample limit'; diff --git a/settings.php b/settings.php index 6d644f3..4f6e843 100644 --- a/settings.php +++ b/settings.php @@ -176,6 +176,15 @@ function ($v) { ) ); + $settings->add( + new admin_setting_configcheckbox( + 'tool_excimer/enable_partial_save', + get_string('enable_partial_save', 'tool_excimer'), + get_string('enable_partial_save_desc', 'tool_excimer'), + 0 + ) + ); + $item = new admin_setting_configtext( 'tool_excimer/trigger_ms', get_string('request_ms', 'tool_excimer'), diff --git a/version.php b/version.php index e25677a..ec97d7c 100644 --- a/version.php +++ b/version.php @@ -25,8 +25,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024050700; -$plugin->release = 2024050700; +$plugin->version = 2024052400; +$plugin->release = 2024052400; $plugin->requires = 2017051500; // Moodle 3.3 for Totara support. $plugin->supported = [35, 401]; // Supports Moodle 3.5 or later. // TODO $plugin->incompatible = ; // Available as of Moodle 3.9.0 or later.