[CalendarServer-changes] [8507] CalendarServer/trunk/contrib/tools/request_monitor.py

source_changes at macosforge.org source_changes at macosforge.org
Tue Jan 10 12:51:24 PST 2012


Revision: 8507
          http://trac.macosforge.org/projects/calendarserver/changeset/8507
Author:   cdaboo at apple.com
Date:     2012-01-10 12:51:24 -0800 (Tue, 10 Jan 2012)
Log Message:
-----------
Allow a range of lines to be scanned once. 

Modified Paths:
--------------
    CalendarServer/trunk/contrib/tools/request_monitor.py

Modified: CalendarServer/trunk/contrib/tools/request_monitor.py
===================================================================
--- CalendarServer/trunk/contrib/tools/request_monitor.py	2012-01-10 20:40:18 UTC (rev 8506)
+++ CalendarServer/trunk/contrib/tools/request_monitor.py	2012-01-10 20:51:24 UTC (rev 8507)
@@ -85,6 +85,16 @@
     output, _ignore_error = child.communicate()
     return output.split("\n")
 
+def range(filename, start, end):
+    results = []
+    with open(filename) as f:
+        for count, line in enumerate(f):
+            if count >= start:
+                results.append(line)
+            if count > end:
+                break
+    return results
+
 def cpuPerDaemon():
     a = []
     child = Popen(
@@ -206,17 +216,19 @@
     print "-h         print help and exit"
     print "--debug    print tracebacks and error details"
     print "--lines N  specifies how many lines to tail from access.log (default: 10000)"
+    print "--range M:N  specifies a range of lines to analyze from access.log (default: all)"
     print "--procs N  specifies how many python processes are expected in the log file (default: 80)"
     print "--router   analyze a partition server router node"
     print "--worker   analyze a partition server worker node"
     print
-    print "Version: 4"
+    print "Version: 5"
 
 numLines = 10000
 numProcs = 80
+lineRange = None
 router = False
 worker = False
-options, args = getopt.getopt(sys.argv[1:], "h", ["debug", "router", "worker", "lines=", "procs=",])
+options, args = getopt.getopt(sys.argv[1:], "h", ["debug", "router", "worker", "lines=", "range=", "procs=",])
 for option, value in options:
     if option == "-h":
         usage()
@@ -229,6 +241,8 @@
         worker = True
     elif option == "--lines":
         numLines = int(value)
+    elif option == "--range":
+        lineRange = (int(value.split(":")[0]), int(value.split(":")[1]))
     elif option == "--procs":
         numProcs = int(value)
 
@@ -278,8 +292,9 @@
     errorCount = 0
     parseErrors = 0
 
-    try: 
-        for line in tail(filename, numLines):
+    try:
+        lines = tail(filename, numLines) if lineRange is None else range(filename, *lineRange)
+        for line in lines:
             if not line or line.startswith("Log"):
                 continue
 
@@ -488,6 +503,11 @@
                 pass
 
         print
+        
+        # lineRange => do loop only once
+        if lineRange is not None:
+            break
+
         time.sleep(10)
 
     except Exception, e:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120110/5dc5ebfc/attachment.html>


More information about the calendarserver-changes mailing list