[Zope-Checkins] CVS: Zope2 - requestprofiler.py:1.2

chrism@serenade.digicool.com chrism@serenade.digicool.com
Sat, 21 Apr 2001 16:37:00 -0400


Update of /cvs-repository/Zope2/utilities
In directory serenade.digicool.com:/home/chrism/sandboxes/testtrunk/utilities

Modified Files:
	requestprofiler.py 
Log Message:
Windows compatibility and --today flag.


--- Updated File requestprofiler.py in package Zope2 --
--- requestprofiler.py	2001/04/21 06:19:38	1.1
+++ requestprofiler.py	2001/04/21 20:36:59	1.2
@@ -190,7 +190,7 @@
                 t = t + elapsed
         return t
 
-def analyze(f, top, sortf):
+def analyze(f, top, sortf, start=None, end=None):
     requests={}
     while 1:
         line = f.readline()
@@ -205,8 +205,21 @@
             code, id, timestr, desc = tup
         else:
             continue
-        gmtimetup = time.strptime(timestr, '%Y-%m-%dT%H:%M:%S')
-        fromepoch = time.mktime(gmtimetup)
+        #gmtimetup = time.strptime(timestr, '%Y-%m-%dT%H:%M:%S')
+        # this doesn't work on windows
+        timestr = string.strip(timestr)
+        year = int(timestr[:4])
+        month = int(timestr[5:7])
+        day = int(timestr[8:10])
+        hour = int(timestr[11:13])
+        minute = int(timestr[14:16])
+        second = int(timestr[17:19])
+        gmttup = (year, month, day, hour, minute, second, 0, 0, -1)
+        fromepoch = time.mktime(gmttup)
+        if start is not None:
+            if fromepoch < start: continue
+        if end is not None:
+            if fromepoch > end: continue
         request = requests.get(id)
         if request is None:
             request = Request()
@@ -278,13 +291,15 @@
 If the 'top' argument is specified, only report on the top 'n' requests in
 the log (as per the sort).  The default is 10.
 
-If the 'verbose' argument is specified, do not trim url to fit into 80 cols."""
+If the 'verbose' argument is specified, do not trim url to fit into 80 cols.
+
+If the 'today' argument is specified, limit results to hits received today."""
     return details
 
 def usage(basic=1):
     usage = (
         """
-Usage: %s filename [--sort=spec] [--top=n] [--verbose] [--help]
+Usage: %s filename [--sort=spec] [--top=n] [--verbose] [--today] [--help]
         
 Provides a profile of the detailed (-M) Zope request log.
 """ % sys.argv[0]
@@ -303,9 +318,11 @@
     top = 10
     verbose = 0
     sortby = 'total'
+    start = None
+    end = None
     try:
         opts, extra = getopt.getopt(
-            sys.argv[2:], '', ['sort=', 'top=', 'help', 'verbose']
+            sys.argv[2:], '', ['sort=', 'top=', 'help', 'verbose', 'today']
             )
     except:
         print usage()
@@ -317,7 +334,16 @@
         if opt=='--verbose':
             global verbose
             verbose = 1
-        
+        if opt=='--today':
+            now = time.gmtime(time.time())
+            # for testing - now = (2001, 04, 19, 0, 0, 0, 0, 0, -1)
+            start = list(now)
+            start[3] = start[4] = start[5] = 0
+            start = time.mktime(start)
+            end = list(now)
+            end[3] = 23; end[4] = 59; end[5] = 59
+            end = time.mktime(end)
+            
     if sortby in ['url', 'hits', 'hangs', 'max', 'min', 'median', 'mean',
                   'total']:
         if sortby == 'url':
@@ -326,7 +352,7 @@
         else:
             sortf = Sort(sortby)
         try:
-            analyze(open(sys.argv[1]), top, sortf)
+            analyze(open(sys.argv[1]), top, sortf, start, end)
         except:
             import traceback
             traceback.print_exc()