From cfa7101d594c75787cc9110266bb14b30d0efcc7 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 29 Jan 2021 11:56:21 +0100 Subject: [PATCH] MINOR: activity: flush scheduler stats on "set profiling tasks on" If a user enables profiling by hand, it makes sense to reset the stats counters to provide fresh new measurements. Therefore it's worth using this as the standard method to reset counters. --- doc/management.txt | 4 +++- src/activity.c | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/management.txt b/doc/management.txt index 99b3e5936c..e71849a525 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -1788,7 +1788,9 @@ set maxconn global set profiling { tasks } { auto | on | off } Enables or disables CPU profiling for the indicated subsystem. This is equivalent to setting or clearing the "profiling" settings in the "global" - section of the configuration file. Please also see "show profiling". + section of the configuration file. Please also see "show profiling". Note + that manually setting the tasks profiling to "on" automatically resets the + scheduler statistics, thus allows to check activity over a given interval. set rate-limit connections global Change the process-wide connection rate limit, which is set by the global diff --git a/src/activity.c b/src/activity.c index e0e6693b7b..ffad3701d6 100644 --- a/src/activity.c +++ b/src/activity.c @@ -72,8 +72,17 @@ static int cli_parse_set_profiling(char **args, char *payload, struct appctx *ap if (strcmp(args[3], "on") == 0) { unsigned int old = profiling; + int i; + while (!_HA_ATOMIC_CAS(&profiling, &old, (old & ~HA_PROF_TASKS_MASK) | HA_PROF_TASKS_ON)) ; + /* also flush current profiling stats */ + for (i = 0; i < 256; i++) { + HA_ATOMIC_STORE(&sched_activity[i].calls, 0); + HA_ATOMIC_STORE(&sched_activity[i].cpu_time, 0); + HA_ATOMIC_STORE(&sched_activity[i].lat_time, 0); + HA_ATOMIC_STORE(&sched_activity[i].func, NULL); + } } else if (strcmp(args[3], "auto") == 0) { unsigned int old = profiling;