f4531a2004-05-19Henrik Grubbström (Grubba) /*
0917d32013-03-04Anders Johansson  * $Id$
f4531a2004-05-19Henrik Grubbström (Grubba)  */ #include <stat.h> #include <roxen.h> //<locale-token project="admin_tasks">LOCALE</locale-token> #define LOCALE(X,Y) _DEF_LOCALE("admin_tasks",X,Y) constant action = "debug_info";
df53b32004-05-25Anders Johansson LocaleString name= LOCALE(181,"Request profiling information"); LocaleString doc = LOCALE(182,"Show some information about how how much time "
f4531a2004-05-19Henrik Grubbström (Grubba)  "has been spent in requests. " "Mostly useful for developers."); int creation_date = time(); int no_reload() { return creation_date > file_stat( __FILE__ )[ST_MTIME]; } mixed page_0(object id) { string res = ""; foreach(roxen->configurations, Configuration conf) {
df53b32004-05-25Anders Johansson  if (id->variables->reset) { conf->profile_map = ([]); continue; }
f4531a2004-05-19Henrik Grubbström (Grubba)  mapping(string:array(int)) prof = conf->profile_map; if (sizeof(prof)) { array(string) ind = indices(prof); array(array(int)) val = values(prof); // Make sure we get a nice, deterministic order. sort(ind, val); // Sort after not_query.
df53b32004-05-25Anders Johansson  sort(0-column(val, 0)[*], ind, val); // Sort after number of requets array(array(string)) data = (array(array(string))) (((ind[*]/"?method=")[*]+val[*])[*]+((val[*][1][*]/val[*][0][*])/({}))[*]); array(int) sizes = allocate(4); map(data, lambda(array(string) row) { for(int i=2;i<=5;i++) { row[i] = reverse(reverse((string)row[i])/3.0*"."); sizes[i-2] = max(sizes[i-2], sizeof(row[i])); } return row; }); map(data, lambda(array(string) row) { for(int i=2;i<=5;i++) row[i] = sprintf("%:*s", sizes[i-2], row[i]); return row; });
f4531a2004-05-19Henrik Grubbström (Grubba)  res += "<br />\n" "Configuration: " "<b>"+Roxen.html_encode_string(conf->name)+"</b><br />\n" "<pre>"+
df53b32004-05-25Anders Johansson  ADT.Table.ASCII.encode(ADT.Table.table(data,
f4531a2004-05-19Henrik Grubbström (Grubba)  ({ "Path", "Method", "Count", "Total(µs)", "Max(µs)", "Average(µs)" })))+ "</pre>"; } } return res; } mixed parse( RequestID id ) { string ret = "<font size='+1'><b>"+
df53b32004-05-25Anders Johansson  LOCALE(181,"Request profiling information")+ "</b></font><p />\n";
f4531a2004-05-19Henrik Grubbström (Grubba)  if (roxen->configurations[0]->profile_map) { ret +=
df53b32004-05-25Anders Johansson  LOCALE(183,"All times are in microseconds.") + "<br />\n"
f4531a2004-05-19Henrik Grubbström (Grubba)  "<p />" "<input type='hidden' name='action' value='request_profiling.pike' />\n"
dd21c32017-10-03Anders Johansson  "<p /><submit-gbutton2 name='refresh' width='75' align='center' img-align='middle'>" + LOCALE(186, "Refresh") +
df53b32004-05-25Anders Johansson  "</submit-gbutton2>\n"
dd21c32017-10-03Anders Johansson  "<submit-gbutton2 name='reset' width='75' align='center' img-align='middle'>" +
df53b32004-05-25Anders Johansson  LOCALE(187,"Reset") + "</submit-gbutton2>\n"
e1fff72016-01-15Henrik Grubbström (Grubba)  "<cf-cancel href='?class=&form.class;&amp;&usr.set-wiz-id;'/>\n"
f4531a2004-05-19Henrik Grubbström (Grubba)  "<p />\n" + page_0( id ); } else { ret += "<p />\n"
731a562004-05-25Anders Johansson  "<font color='&usr.warncolor;'>" +
df53b32004-05-25Anders Johansson  LOCALE(184,"NOTE: This information is only available if the " "server has been stared with <tt>-DPROFILE</tt>.") +
731a562004-05-25Anders Johansson  "</font>" "<p />\n"
e1fff72016-01-15Henrik Grubbström (Grubba)  "<cf-ok-button href='?class=&form.class;&amp;&usr.set-wiz-id;'/>";
f4531a2004-05-19Henrik Grubbström (Grubba)  } return ret; }