]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
merge this fix from 2.1-dev:
authorJeff Trawick <trawick@apache.org>
Sun, 14 Dec 2003 00:26:12 +0000 (00:26 +0000)
committerJeff Trawick <trawick@apache.org>
Sun, 14 Dec 2003 00:26:12 +0000 (00:26 +0000)
  mod_status: Report total CPU time accurately when using a threaded
  MPM.

PR:             23795
Submitted by:   Jeff Trawick
Reviewed by:    jim, ianh, nd

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/APACHE_2_0_BRANCH@102050 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
modules/generators/mod_status.c

diff --git a/CHANGES b/CHANGES
index bb1990295e50aabd65ea0e7d1fdf8025a96b1415..09f9e7f2267b6050b6e261be5dcecca66c3a2ba8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
 Changes with Apache 2.0.49
 
+  *) mod_status: Report total CPU time accurately when using a threaded
+     MPM.  PR 23795.  [Jeff Trawick]
+
   *) Fix memory leak in handling of request bodies during reverse
      proxy operations.  PR 24991. [Larry Toppi <larry.toppi citrix.com>]
 
diff --git a/STATUS b/STATUS
index dcc568e9ca1b5cb894837d6b59b905f830ba7678..6f797e468d3895849acbedccbd75845a8b624cdc 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -1,5 +1,5 @@
 APACHE 2.0 STATUS:                                              -*-text-*-
-Last modified at [$Date: 2003/12/14 00:17:41 $]
+Last modified at [$Date: 2003/12/14 00:26:12 $]
 
 Release:
 
@@ -297,13 +297,6 @@ PATCHES TO BACKPORT FROM 2.1
          nd replies: But if it can't be 0 the alternatives thereafter make no
            sense anymore, right?
 
-    * mod_status: Report total CPU time accurately when using a
-      threaded MPM.  PR: 23795
-        modules/generators/mod_status.c r1.75
-      +1: trawick, jim, ianh
-       (nd: +1 on concept, lacking knowledge prevents me from definitely +1'ing
-            it.)
-
     * Let mod_autoindex show filenames containing special characters.
       PR 13598.
         server/request.c: r1.130
index 172cb888f8f359010ba4cab396860053d4a39ed9..81e410d3cc13d6d869b022b90c45be4bc667e4b5 100644 (file)
@@ -141,6 +141,14 @@ module AP_MODULE_DECLARE_DATA status_module;
 
 int server_limit, thread_limit;
 
+#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.
@@ -249,6 +257,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;
@@ -335,6 +344,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;
@@ -363,10 +377,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;
@@ -379,7 +411,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;
     }
 
@@ -814,10 +851,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 =