Permalink
Browse files

added the --traceback-include parameter

  • Loading branch information...
keul committed Dec 6, 2012
1 parent 28c646f commit 6c94cd5ef7b88063ef37cfa94ea145c08ec3ff60
Showing with 47 additions and 10 deletions.
  1. +23 −2 README.rst
  2. +3 −3 docs/HISTORY.txt
  3. +21 −5 src/zope_lrr_analyzer.py
View
@@ -4,11 +4,28 @@ Introduction
============
This project adds to your system a new utility command: ``zope_lrr_analyzer``. This utility only works with
-Zope instance logs with `haufe.requestmonitoring`__ installed.
+Zope instance logs with `haufe.requestmonitoring`__ installed (and where the
+`monitoring long running requests hook`__ is enabled).
__ http://pypi.python.org/pypi/haufe.requestmonitoring
+__ http://pypi.python.org/pypi/haufe.requestmonitoring#monitoring-long-running-requests
-It will help you to parse slow running request reports and collect some statistical data.
+Your *instance.log* will be populated by entries like this::
+
+ ------
+ 2012-03-27T15:58:19 WARNING RequestMonitor.DumpTrace Long running request
+ Request 28060 "/VirtualHostBase/http/www.mysite.com:80/mysiteid/VirtualHostRoot/myrequest/..." running in thread 1133545792 since 10.7206499577s
+ Python call stack (innermost first)
+ ...
+ lot of lines, depends on Python traceback
+ ...
+ Module ZPublisherEventsBackport.patch, line 80, in publish
+ Module ZPublisher.Publish, line 202, in publish_module_standard
+ Module ZPublisher.Publish, line 401, in publish_module
+ Module ZServer.PubCore.ZServerPublisher, line 25, in __init__
+ <BLANKLINE>
+
+The utility will help you to parse long running request collecting some statistical data.
How to use
==========
@@ -33,6 +50,10 @@ How to use
a regexp expression that a calling path must match or
will be discarded. Can be called multiple times,
expanding the set
+ -t TRACEBACK_INCLUDE_REGEX, --traceback-include=TRACEBACK_INCLUDE_REGEX
+ a regexp expression that the Python traceback must
+ match or will be discarded. Can be called multiple
+ times, expanding the set
-r, --keep-request-id
Use request and thread ids to handle every match as a
different entry
View
@@ -4,13 +4,13 @@ Changelog
0.4 (unreleased)
----------------
-- Nothing changed yet.
-
+* added the ``--traceback-include`` option
+ [keul]
0.3 (2012-11-15)
----------------
-- Always display the start and end date of the request
+* Always display the start and end date of the request
(not only if ``-r`` option is given)
[keul]
View
@@ -43,6 +43,10 @@
p.add_option('--include', '-i', dest="includes", default=[], action="append", metavar="INCLUDE_REGEX",
help="a regexp expression that a calling path must match or will be discarded. "
"Can be called multiple times, expanding the set")
+p.add_option('--traceback-include', '-t', dest="traceback_includes", default=[], action="append",
+ metavar="TRACEBACK_INCLUDE_REGEX",
+ help="a regexp expression that the Python traceback must match or will be discarded. "
+ "Can be called multiple times, expanding the set")
p.add_option('--keep-request-id', '-r', dest="keep_req_id", default=False, action="store_true",
help="Use request and thread ids to handle every match as a different entry")
@@ -52,13 +56,13 @@
PATTERN = """^------$
^(?P<date>\d{4}-\d{2}-\d{2})T(?P<time>\d\d\:\d\d\:\d\d).*?$
^Request (?P<reqid>\d*?) "(?P<path>.*?)" running in thread (?P<threadid>\d*?) since (?P<reqtime>\d*?\.\d*?)s$
-.*?
+(?P<traceback>.*?)
^$"""
-PATH_PARRENT = """^(?P<path>.*?)(?:\?.*?)?$"""
+PATH_PATTERN = """^(?P<path>.*?)(?:\?.*?)?$"""
reqLine = re.compile(PATTERN, re.M|re.S)
-pathLine = re.compile(PATH_PARRENT, re.M|re.S)
+pathLine = re.compile(PATH_PATTERN, re.M|re.S)
stats = {}
stat_data = {'count': 0, 'totaltime': 0, 'req-thread-ids': [], 'start': None, 'end': None}
@@ -93,6 +97,7 @@ def main():
threadid = data.get('threadid')
rdate = data.get('date')
rtime = data.get('time')
+ traceback = data.get('traceback')
d = datetime.strptime("%s %s" % (rdate, rtime), "%Y-%m-%d %H:%M:%S")
@@ -101,7 +106,7 @@ def main():
if end_at and d>end_at:
break
- # include only...
+ # include only... (path)
stop = False
if options.includes:
stop = True
@@ -111,7 +116,18 @@ def main():
break
if stop:
continue
-
+
+ # include only... (traceback)
+ stop = False
+ if options.traceback_includes:
+ stop = True
+ for i in options.traceback_includes:
+ if re.search(i, traceback, re.MULTILINE) is not None:
+ stop = False
+ break
+ if stop:
+ continue
+
if not min_date or d<min_date:
min_date = d
if not max_date or d>min_date:

0 comments on commit 6c94cd5

Please sign in to comment.