From: Jeff Trawick Date: Wed, 29 Oct 2003 20:56:28 +0000 (+0000) Subject: mod_status: Report total CPU time accurately when using a threaded X-Git-Tag: pre_ajp_proxy~1096 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=468254b6b05ff0270e2a11594ae5cf2c57c08174;p=apache mod_status: Report total CPU time accurately when using a threaded MPM. Note: It worked before with linuxthreads and it still does. But now it works with normal thread implementations too. PR: 23795 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@101614 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index b3d6b8a0f6..e9585e5137 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.1.0-dev [Remove entries to the current 2.0 section below, when backported] + *) mod_status: Report total CPU time accurately when using a threaded + MPM. PR 23795. [Jeff Trawick] + *) mod_ssl: Fix segfault on a non-SSL request if the the 'c' log format code is used. PR 22741. [Gary E. Miller ] diff --git a/modules/generators/mod_status.c b/modules/generators/mod_status.c index cb416d4b1d..366267f31e 100644 --- a/modules/generators/mod_status.c +++ b/modules/generators/mod_status.c @@ -148,6 +148,14 @@ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap, STATUS, int, status_hook, (r, flags), OK, DECLINED) +#ifdef HAVE_TIMES +/* ugh... need to know if we're running with a pthread implementation + * such as linuxthreads that treats individual threads as distinct + * processes; that affects how we add up CPU time in a process + */ +static pid_t child_pid; +#endif + /* * command-related code. This is here to prevent use of ExtendedStatus * without status_module included. @@ -256,6 +264,7 @@ static int status_handler(request_rec *r) long req_time; #ifdef HAVE_TIMES float tick; + int times_per_thread = getpid() != child_pid; #endif int short_report; int no_table_report; @@ -342,6 +351,11 @@ static int status_handler(request_rec *r) } for (i = 0; i < server_limit; ++i) { +#ifdef HAVE_TIMES + clock_t proc_tu = 0, proc_ts = 0, proc_tcu = 0, proc_tcs = 0; + clock_t tmp_tu, tmp_ts, tmp_tcu, tmp_tcs; +#endif + ps_record = ap_get_scoreboard_process(i); for (j = 0; j < thread_limit; ++j) { int indx = (i * thread_limit) + j; @@ -370,10 +384,28 @@ static int status_handler(request_rec *r) if (lres != 0 || (res != SERVER_READY && res != SERVER_DEAD)) { #ifdef HAVE_TIMES - tu += ws_record->times.tms_utime; - ts += ws_record->times.tms_stime; - tcu += ws_record->times.tms_cutime; - tcs += ws_record->times.tms_cstime; + tmp_tu = ws_record->times.tms_utime; + tmp_ts = ws_record->times.tms_stime; + tmp_tcu = ws_record->times.tms_cutime; + tmp_tcs = ws_record->times.tms_cstime; + + if (times_per_thread) { + proc_tu += tmp_tu; + proc_ts += tmp_ts; + proc_tcu += tmp_tcu; + proc_tcs += proc_tcs; + } + else { + if (tmp_tu > proc_tu || + tmp_ts > proc_ts || + tmp_tcu > proc_tcu || + tmp_tcs > proc_tcs) { + proc_tu = tmp_tu; + proc_ts = tmp_ts; + proc_tcu = tmp_tcu; + proc_tcs = proc_tcs; + } + } #endif /* HAVE_TIMES */ count += lres; @@ -386,7 +418,12 @@ static int status_handler(request_rec *r) } } } - +#ifdef HAVE_TIMES + tu += proc_tu; + ts += proc_ts; + tcu += proc_tcu; + tcs += proc_tcs; +#endif pid_buffer[i] = ps_record->pid; } @@ -831,10 +868,20 @@ static int status_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, return OK; } +#ifdef HAVE_TIMES +static void status_child_init(apr_pool_t *p, server_rec *s) +{ + child_pid = getpid(); +} +#endif + static void register_hooks(apr_pool_t *p) { ap_hook_handler(status_handler, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_post_config(status_init, NULL, NULL, APR_HOOK_MIDDLE); +#ifdef HAVE_TIMES + ap_hook_child_init(status_child_init, NULL, NULL, APR_HOOK_MIDDLE); +#endif } module AP_MODULE_DECLARE_DATA status_module =