Implement time logging.
Mon Feb 20 03:23:19 UTC 2006 Alberto Bertogli <albertogli@telpin.com.ar>
* Implement time logging.
This record adds an option to log the time it took darcsweb to present a
page. Unfortunately, because of the way it's implemented, it's impossible to
isolate the time it takes to call darcs; however, every darcs invocation is
logged too, to allow independant measures.
{
hunk ./config.py.sample 48
+
+ # If you want to log the times it took darcsweb to present a page,
+ # uncomment this option. The value should be a file writeable by
+ # darcsweb.
+ #logtimes = "/tmp/darcsweb_times"
hunk ./darcsweb.cgi 11
+import time
+time_begin = time.time()
hunk ./darcsweb.cgi 16
-import time
hunk ./darcsweb.cgi 24
+time_imports = time.time() - time_begin
hunk ./darcsweb.cgi 32
+# list of run_darcs() invocations, for performance measures
+darcs_runs = []
+
hunk ./darcsweb.cgi 241
+def log_times(cache_hit, event = None):
+ if not config.logtimes:
+ return
+
+ time_total = time.time() - time_begin
+ processing = time_total - time_imports
+ if not event:
+ event = action
+ if cache_hit:
+ event = event + " (hit)"
+ s = """\
+%s
+ total: %.3f
+ processing: %.3f
+ imports: %.3f\n""" % (event, time_total, processing, time_imports)
+
+ if darcs_runs:
+ s += "\truns:\n"
+ for params in darcs_runs:
+ s += '\t\t%s\n' % params
+ s += '\n'
+
+ lf = open(config.logtimes, 'a')
+ lf.write(s)
+ lf.close()
+
hunk ./darcsweb.cgi 581
+ darcs_runs.append(params)
hunk ./darcsweb.cgi 2240
+ if "logtimes" in dir(base):
+ config.logtimes = base.logtimes
+ else:
+ config.logtimes = None
+
hunk ./darcsweb.cgi 2265
+ log_times(cache_hit = 0, event = 'index')
hunk ./darcsweb.cgi 2293
+ log_times(cache_hit = 1)
hunk ./darcsweb.cgi 2446
+log_times(cache_hit = 0)
+
+
}