Branch: Tag:

2008-11-05

2008-11-05 18:21:38 by Martin Stjernholm <mast@lysator.liu.se>

Added time reporting to REQUEST_TRACE. It's enabled through
-DREQUEST_TRACE=TIMES.

Rev: server/etc/modules/Roxen.pmod:1.255

1:   // This is a roxen pike module. Copyright © 1999 - 2004, Roxen IS.   // - // $Id: Roxen.pmod,v 1.254 2008/11/05 13:33:09 mast Exp $ + // $Id: Roxen.pmod,v 1.255 2008/11/05 18:21:38 mast Exp $      #include <roxen.h>   #include <config.h>
4724:   }      #ifdef REQUEST_TRACE - protected string trace_msg (mapping id_misc, string msg, string name) + protected string trace_msg (mapping id_misc, string msg, +  string|int name_or_time)   {    array(string) lines = msg / "\n";    if (lines[-1] == "") lines = lines[..sizeof (lines) - 2];    -  if (sizeof (lines)) -  report_debug ("%s%s%-40s %s\n", -  map (lines[..sizeof (lines) - 2], +  if (sizeof (lines)) { +  string byline = sprintf ("%*s%s", id_misc->trace_level + 1, "", +  sizeof (lines) ? lines[-1] : ""); +  +  string info; +  if (stringp (name_or_time)) +  info = name_or_time; +  else if (name_or_time >= 0) { +  float t = name_or_time / 1e3; +  if (sizeof (byline) > 40) +  info = sprintf ("time: %.3fms", t); +  else +  info = sprintf ("time: %10.3fms", t); +  } +  if (info) +  byline = sprintf ("%-40s %s", byline, info); +  +  report_debug (map (lines[..<1],    lambda (string s) {    return sprintf ("%s%*s%s\n", id_misc->trace_id_prefix,    id_misc->trace_level + 1, "", s); -  }) * "", -  id_misc->trace_id_prefix, -  sprintf ("%*s%s", id_misc->trace_level + 1, "", lines[-1]), -  name); +  }) * "" + +  id_misc->trace_id_prefix + +  byline + +  "\n");    } -  + }      void trace_enter (RequestID id, string msg, object|function thing)   {
4776:    else name = "";       trace_msg (id_misc, msg, name); -  id_misc->trace_level++; +  int l = ++id_misc->trace_level;       if(function(string,mixed ...:void) _trace_enter =    [function(string,mixed ...:void)]id_misc->trace_enter)    _trace_enter (msg, thing); -  +  + #if TOSTR (REQUEST_TRACE) == "TIMES" +  array(int) tt = id_misc->trace_times; +  array(string) tm = id_misc->trace_msgs; +  if (!tt) { +  tt = id_misc->trace_times = allocate (10); +  tm = id_misc->trace_msgs = allocate (10);    } -  +  else if (sizeof (tt) <= l) { +  tt = (id_misc->trace_times += allocate (sizeof (tt))); +  tm = (id_misc->trace_msgs += allocate (sizeof (tm)));    } -  + #if efun (gethrvtime) +  tt[l] = gethrvtime(); + #elif efun (gethrtime) +  tt[l] = gethrtime(); + #endif +  sscanf (msg, "%[^\n]", tm[l]); + #endif +  } + }      void trace_leave (RequestID id, string desc)   {
4792:    // leads to races in the TRACE_LEAVE calls in low_get_file.    mapping id_misc = id->misc;    +  string|int name_or_time = ""; + #if TOSTR (REQUEST_TRACE) == "TIMES" +  if (int l = id_misc->trace_level) { +  if (array(int) tt = id_misc->trace_times) +  if (sizeof (tt) > l) { + #if efun (gethrvtime) +  int t = gethrvtime(); + #elif efun (gethrtime) +  int t = gethrtime(); + #endif +  name_or_time = t - tt[l]; +  if (desc == "") desc = "Leave: " + id_misc->trace_msgs[l]; +  } +  id_misc->trace_level--; +  } + #else    if (id_misc->trace_level) id_misc->trace_level--; -  + #endif    -  if (sizeof (desc)) trace_msg (id_misc, desc, ""); +  if (sizeof (desc)) trace_msg (id_misc, desc, name_or_time);       if(function(string:void) _trace_leave =    [function(string:void)]id_misc->trace_leave)