httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject cvs commit: httpd-2.0/modules/generators mod_status.c
Date Wed, 29 Oct 2003 20:56:28 GMT
trawick     2003/10/29 12:56:28

  Modified:    .        CHANGES
               modules/generators mod_status.c
  Log:
  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
  
  Revision  Changes    Path
  1.1301    +3 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.1300
  retrieving revision 1.1301
  diff -u -r1.1300 -r1.1301
  --- CHANGES	26 Oct 2003 23:25:44 -0000	1.1300
  +++ CHANGES	29 Oct 2003 20:56:28 -0000	1.1301
  @@ -2,6 +2,9 @@
   
     [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>]
   
  
  
  
  1.75      +52 -5     httpd-2.0/modules/generators/mod_status.c
  
  Index: mod_status.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/generators/mod_status.c,v
  retrieving revision 1.74
  retrieving revision 1.75
  diff -u -r1.74 -r1.75
  --- mod_status.c	22 Jul 2003 20:01:43 -0000	1.74
  +++ mod_status.c	29 Oct 2003 20:56:28 -0000	1.75
  @@ -148,6 +148,14 @@
                                       (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 @@
       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 @@
       }
   
       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 @@
   
                   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 @@
                   }
               }
           }
  -
  +#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 @@
       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 =
  
  
  

Mime
View raw message