]> granicus.if.org Git - apache/commitdiff
mod_status: Report total CPU time accurately when using a threaded
authorJeff Trawick <trawick@apache.org>
Wed, 29 Oct 2003 20:56:28 +0000 (20:56 +0000)
committerJeff Trawick <trawick@apache.org>
Wed, 29 Oct 2003 20:56:28 +0000 (20:56 +0000)
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

CHANGES
modules/generators/mod_status.c

diff --git a/CHANGES b/CHANGES
index b3d6b8a0f6d4f82010d08268ac420c24a3252431..e9585e5137b14f696c2cea0ddcb2ccf790ec97c6 100644 (file)
--- 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 <gem@rellim.com>]
 
index cb416d4b1d67b9f7c74c30b99135a5354a62ad63..366267f31eff2b433fe8e0dd3d261452123fe3b5 100644 (file)
@@ -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 =