Index: src/modules/standard/mod_status.c =================================================================== --- src/modules/standard/mod_status.c (revision 155622) +++ src/modules/standard/mod_status.c (working copy) @@ -178,6 +178,10 @@ static char status_flags[SERVER_NUM_STATUS]; +#ifdef AP_TRACK_ACTIVE_MODULE +static const char *modnames[256]; +#endif + static int status_handler(request_rec *r) { char *loc; @@ -441,12 +445,15 @@ if (no_table_report) ap_rputs("


Server Details

\n\n", r); else -#ifdef NO_TIMES - /* Allow for OS/2 not having CPU stats */ - ap_rputs("

\n\n\n\n", r); -#else - ap_rputs("

\n\n

SrvPIDAccM\nSSReqConnChildSlotClientVHostRequest
\n\n", r); + ap_rputs("

\n\n

SrvPIDAccMCPU\nSSReqConnChildSlotClientVHostRequest
\n\n", + r); } for (i = 0; i < HARD_SERVER_LIMIT; ++i) { @@ -574,6 +581,7 @@ vhost->server_hostname) : "(unavailable)"); } else { /* !no_table_report */ + if (score_record.status == SERVER_DEAD) #ifdef TPF if (kill(ps_record.pid, 0) == 0) { @@ -628,6 +636,12 @@ ap_rputs("
SrvPIDAccM\n" +#ifdef AP_TRACK_ACTIVE_MODULE + "Module" #endif +#ifndef NO_TIMES + "CPU\n" +#endif + "SSReqConnChildSlotClientVHostRequest
?", r); break; } +#ifdef AP_TRACK_ACTIVE_MODULE + ap_rprintf(r, "%.15s ", + score_record.short_module_index < 256 ? + modnames[score_record.short_module_index] : + modnames[255]); +#endif #ifdef NO_TIMES /* Allow for OS/2 not having CPU stats */ ap_rprintf(r, "\n%.0f%ld", @@ -716,6 +730,20 @@ static void status_init(server_rec *s, pool *p) { +#ifdef AP_TRACK_ACTIVE_MODULE + module *modp; + extern module API_VAR_EXPORT *top_module; + + for (modp = top_module; modp; modp = modp->next) { + if (modp->module_index < 255) { + modnames[modp->module_index] = modp->name; + } + } + modnames[0] = ""; /* treat core as not-a-module */ + modnames[255] = "unknown"; /* overflow caused by limitation in + * scoreboard field (unsigned char) */ +#endif + status_flags[SERVER_DEAD] = '.'; /* We don't want to assume these are in */ status_flags[SERVER_READY] = '_'; /* any particular order in scoreboard.h */ status_flags[SERVER_STARTING] = 'S'; Index: src/modules/experimental/mod_whatkilledus.c =================================================================== --- src/modules/experimental/mod_whatkilledus.c (revision 155622) +++ src/modules/experimental/mod_whatkilledus.c (working copy) @@ -67,6 +67,9 @@ #include "httpd.h" #include "http_config.h" #include "http_log.h" +#ifdef AP_TRACK_ACTIVE_MODULE +#include "scoreboard.h" +#endif #include "test_char.h" /* an odd one since it is not installed */ @@ -75,11 +78,40 @@ * client connections */ static char *log_fname; +static conn_rec *active_connection; static char *local_addr; static char *remote_addr; +static request_rec *active_request; static char *request_plus_headers; static char buffer[2048]; +#ifdef AP_TRACK_ACTIVE_MODULE +static const char *get_modname(conn_rec *c) +{ + short_score *ss = &ap_scoreboard_image->servers[c->child_num]; + extern module API_VAR_EXPORT *top_module; + int index = ss->short_module_index; + + module *modp; + + if (index >= 255) { + return "unknown"; + } + + if (index == 0) { + return "(core)"; + } + + for (modp = top_module; modp; modp = modp->next) { + if (modp->module_index == index) { + return modp->name; + } + } + + return "unknown"; +} +#endif + static void exception_hook(ap_exception_info_t *ei) { int msg_len; @@ -121,10 +153,17 @@ msg_prefix, ei->sig); write(logfd, buffer, msg_len); - if (local_addr) { + if (active_connection) { +#ifdef AP_TRACK_ACTIVE_MODULE msg_len = ap_snprintf(buffer, sizeof buffer, - "%s active connection: %s->%s\n", - msg_prefix, remote_addr, local_addr); + "%s active module: %s\n", + msg_prefix, get_modname(active_connection)); + write(logfd, buffer, msg_len); +#endif + msg_len = ap_snprintf(buffer, sizeof buffer, + "%s active connection: %s->%s (conn_rec %pp)\n", + msg_prefix, remote_addr, local_addr, + active_connection); } else { msg_len = ap_snprintf(buffer, sizeof buffer, @@ -134,10 +173,11 @@ write(logfd, buffer, msg_len); - if (request_plus_headers) { + if (active_request) { msg_len = ap_snprintf(buffer, sizeof buffer, - "%s active request:\n", - msg_prefix); + "%s active request (request_rec %pp):\n", + msg_prefix, + active_request); write(logfd, buffer, msg_len); write(logfd, request_plus_headers, strlen(request_plus_headers)); } @@ -170,12 +210,14 @@ static void clear_conn_info(void *ignored) { + active_connection = NULL; local_addr = remote_addr = NULL; } static void save_conn_info(request_rec *r) { conn_rec *c = r->connection; + active_connection = r->connection; local_addr = ap_psprintf(c->pool, "%pI", &c->local_addr); remote_addr = ap_psprintf(c->pool, "%pI", &c->remote_addr); @@ -184,6 +226,7 @@ static void clear_req_info(void *ignored) { + active_request = NULL; request_plus_headers = NULL; } @@ -261,6 +304,9 @@ */ int len = strlen(r->the_request); char *ch; + + active_request = r; + ap_table_do(count_headers, &len, r->headers_in, NULL); request_plus_headers = ap_palloc(r->pool, len + 2 /* 2 for the '\n' + '\0' at end */); @@ -286,7 +332,7 @@ /* save whatever info, like client, which vhost, which port * (to know SSL or not), etc. */ - if (!local_addr) { /* first request on this connection */ + if (!active_connection) { /* first request on this connection */ save_conn_info(r); } Index: src/include/httpd.h =================================================================== --- src/include/httpd.h (revision 155622) +++ src/include/httpd.h (working copy) @@ -1,3 +1,4 @@ +#define AP_TRACK_ACTIVE_MODULE /* Copyright 1999-2004 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); Index: src/include/scoreboard.h =================================================================== --- src/include/scoreboard.h (revision 155622) +++ src/include/scoreboard.h (working copy) @@ -95,6 +95,12 @@ unsigned short timeout_len; /* length of the timeout */ #endif unsigned char status; +#ifdef AP_TRACK_ACTIVE_MODULE + /* don't use this feature unless the offset of access_count is + * the same with or without this enabled + */ + unsigned char short_module_index; +#endif unsigned long access_count; unsigned long bytes_served; unsigned long my_access_count; Index: src/main/http_config.c =================================================================== --- src/main/http_config.c (revision 155622) +++ src/main/http_config.c (working copy) @@ -39,6 +39,9 @@ #include "http_vhost.h" #include "explain.h" #include "fnmatch.h" +#ifdef AP_TRACK_ACTIVE_MODULE +#include "scoreboard.h" +#endif DEF_Explain @@ -258,12 +261,21 @@ * This structure was designed to hopefully maximize cache-coolness. */ static handler_func *method_ptrs; +#ifdef AP_TRACK_ACTIVE_MODULE +/* + * modindex_ptrs gives the module index corresponding to the + * module whose handler_func is at same index in method_ptrs + */ +static int *modindex_ptrs; +#endif - void ap_cleanup_method_ptrs() { if (method_ptrs) { free(method_ptrs); +#ifdef AP_TRACK_ACTIVE_MODULE + free(modindex_ptrs); +#endif } } @@ -282,6 +294,9 @@ if (method_ptrs) { /* free up any previous set of method_ptrs */ free(method_ptrs); +#ifdef AP_TRACK_ACTIVE_MODULE + free(modindex_ptrs); +#endif } /* first we count how many functions we have */ @@ -297,6 +312,12 @@ if (method_ptrs == NULL) { fprintf(stderr, "Ouch! Out of memory in build_method_shortcuts()!\n"); } +#ifdef AP_TRACK_ACTIVE_MODULE + modindex_ptrs = malloc((how_many_ptrs + NMETHODS) * sizeof(int)); + if (modindex_ptrs == NULL) { + fprintf(stderr, "Ouch! Out of memory in build_method_shortcuts()!\n"); + } +#endif next_ptr = 0; for (i = 0; i < NMETHODS; ++i) { /* XXX: This is an itsy bit presumptuous about the alignment @@ -306,6 +327,9 @@ for (modp = top_module; modp; modp = modp->next) { fp = *(handler_func *) (method_offsets[i] + (char *) modp); if (fp) { +#ifdef AP_TRACK_ACTIVE_MODULE + modindex_ptrs[next_ptr] = modp->module_index; +#endif method_ptrs[next_ptr++] = fp; } } @@ -324,6 +348,21 @@ if (mod_handler) { int result; +#ifdef AP_TRACK_ACTIVE_MODULE + if (ap_extended_status) { + short_score *ss; + ss = &ap_scoreboard_image->servers[r->connection->child_num]; + if (modindex_ptrs[i] >= 255) { + ss->short_module_index = 255; + } + else { + ss->short_module_index = modindex_ptrs[i]; + } + result = (*mod_handler) (r); + ss->short_module_index = 0; /* back to core Apache code */ + } + else +#endif result = (*mod_handler) (r); if (result != DECLINED && (!run_all || result != OK)) @@ -393,6 +432,9 @@ typedef struct { handler_rec hr; size_t len; +#ifdef AP_TRACK_ACTIVE_MODULE + int module_index; +#endif } fast_handler_rec; static fast_handler_rec *handlers; @@ -428,11 +470,17 @@ pw->hr.content_type = handp->content_type; pw->hr.handler = handp->handler; pw->len = starp - handp->content_type; +#ifdef AP_TRACK_ACTIVE_MODULE + pw->module_index = modp->module_index; +#endif pw ++; } else { ph->hr.content_type = handp->content_type; ph->hr.handler = handp->handler; ph->len = strlen(handp->content_type); +#ifdef AP_TRACK_ACTIVE_MODULE + ph->module_index = modp->module_index; +#endif ph ++; } } @@ -472,6 +520,21 @@ for (handp = handlers; handp->hr.content_type; ++handp) { if (handler_len == handp->len && !strncmp(handler, handp->hr.content_type, handler_len)) { +#ifdef AP_TRACK_ACTIVE_MODULE + if (ap_extended_status) { + short_score *ss; + ss = &ap_scoreboard_image->servers[r->connection->child_num]; + if (handp->module_index >= 255) { + ss->short_module_index = 255; + } + else { + ss->short_module_index = handp->module_index; + } + result = (*handp->hr.handler) (r); + ss->short_module_index = 0; /* back to core Apache code */ + } + else +#endif result = (*handp->hr.handler) (r); if (result != DECLINED) @@ -484,6 +547,21 @@ for (handp = wildhandlers; handp->hr.content_type; ++handp) { if (handler_len >= handp->len && !strncmp(handler, handp->hr.content_type, handp->len)) { +#ifdef AP_TRACK_ACTIVE_MODULE + if (ap_extended_status) { + short_score *ss; + ss = &ap_scoreboard_image->servers[r->connection->child_num]; + if (handp->module_index >= 255) { + ss->short_module_index = 255; + } + else { + ss->short_module_index = handp->module_index; + } + result = (*handp->hr.handler) (r); + ss->short_module_index = 0; /* back to core Apache code */ + } + else +#endif result = (*handp->hr.handler) (r); if (result != DECLINED)