From: Gonzalo A. <ga...@us...> - 2006-10-05 15:59:51
|
Update of /cvsroot/mod-c/mod_c/src In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv7169/src Modified Files: mod_c.c Log Message: * Added the ability to sort cpu usage report. Index: mod_c.c =================================================================== RCS file: /cvsroot/mod-c/mod_c/src/mod_c.c,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** mod_c.c 21 Sep 2006 17:23:58 -0000 1.27 --- mod_c.c 5 Oct 2006 15:59:46 -0000 1.28 *************** *** 29,32 **** --- 29,34 ---- #include <http_log.h> + #include <assert.h> + /** * The name of the EHMTL file handler. *************** *** 131,134 **** --- 133,161 ---- } + int sort_field; + + int spec_cmp(const void* v1, const void* v2) { + struct runspec** p1 = (struct runspec**)v1; + struct runspec** p2 = (struct runspec**)v2; + switch (sort_field) { + case 0: // accum + default: + return p1[0]->accum - p2[0]->accum; + case 1: // self + return p1[0]->self - p2[0]->self; + case 2: // self/ncalls + return (p1[0]->self/p1[0]->ncalls) - (p2[0]->self/p2[0]->ncalls); + case 3: // ncalls + return p1[0]->ncalls - p2[0]->ncalls; + } + assert(0); + } + + static void show_spec(request_rec* r, struct runspec* spec) { + ap_rprintf(r, "%20llu %20llu %20lld %20lld %s/%s:%d\n", + spec->accum, spec->self, spec->self / spec->ncalls, spec->ncalls, + spec->name, spec->file, spec->line); + } + /** * Produce EHTML profiling statistics. *************** *** 140,147 **** * @return Returns... */ static int EHTMLProfileHandler( request_rec *r ) { void* cbdata = NULL; - struct runspec spec; if (r->handler == NULL || --- 167,174 ---- * @return Returns... */ + #define FMT(i) "<a href=\"?" #i "\">%20s</a> " static int EHTMLProfileHandler( request_rec *r ) { void* cbdata = NULL; if (r->handler == NULL || *************** *** 153,166 **** return DECLINED; ! ap_set_content_type(r, "text/plain"); - ap_rprintf(r, "%20s %20s %20s function/file:line\n", - "accum", "self", "ncalls"); - while (profile_tick(&cbdata, &spec), cbdata != NULL) { - ap_rprintf(r, "%20llu %20llu %20lld %s/%s:%d\n", - spec.accum, spec.self, spec.ncalls, - spec.name, spec.file, spec.line); } return 0; } --- 180,228 ---- return DECLINED; ! ap_set_content_type(r, "text/html"); ! ! ap_rprintf(r, "<pre>"); ! ap_rprintf(r, FMT(0) FMT(1) FMT(2) FMT(3) "function/file:line\n", ! "accum", "self", "self/call", "ncalls"); ! ! unsigned long n = profile_stubs(); ! ! sort_field = 0; ! ! struct runspec* v = (struct runspec*)malloc(sizeof(struct runspec) * n); ! struct runspec** p = (struct runspec**)malloc(sizeof(struct runspec*) * n); ! ! if (v == NULL || p == NULL) { ! ! ap_rputs("Running low on memory, will not sort results.\n", r); ! struct runspec spec; ! ! while (profile_tick(&cbdata, &spec), cbdata != NULL) ! show_spec(r, &spec); ! ! if (v != NULL) free(v); ! if (p != NULL) free(p); ! ! return 0; } + int i = 0; + for (i = 0; profile_tick(&cbdata, v+i), cbdata != NULL; ++i) + p[i] = v+i; + + sort_field = 2; + if (r->args && *r->args) + sort_field = atoi(r->args); + + qsort(p, n, sizeof(struct runspec*), spec_cmp); + + for (i = 0; i < n; ++i) { + show_spec(r, p[i]); + } + + free(p); + free(v); + return 0; } |