[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r15460: -Buildtimes are now tracked and recorded in <basefile_name>. (torflow/branches/gsoc2008)



Author: fallon
Date: 2008-06-24 20:27:31 -0400 (Tue, 24 Jun 2008)
New Revision: 15460

Modified:
   torflow/branches/gsoc2008/guardslices.py
Log:
-Buildtimes are now tracked and recorded in <basefile_name>.buildtimes
-Missed circuit events (on relevant circuits) are now recorded




Modified: torflow/branches/gsoc2008/guardslices.py
===================================================================
--- torflow/branches/gsoc2008/guardslices.py	2008-06-24 20:39:47 UTC (rev 15459)
+++ torflow/branches/gsoc2008/guardslices.py	2008-06-25 00:27:31 UTC (rev 15460)
@@ -49,36 +49,69 @@
     StatsHandler.__init__(self,c, selmgr)
 
     self.detailfile = open(basefile_name + '.detail','w')
-    self.timesfile = open(basefile_name + '.buildtimes','w')
+    self.buildtimesfile = open(basefile_name + '.buildtimes','w')
     self.circ_built = 0
     self.nstats = nstats
 
+    # sometimes relevant CircEvents occur before the circ_id is 
+    # added to self.circuits, which means they get discarded
+    # we track them in self.othercircs: a dictionary of list of events
+    self.othercircs = {} 
 
+  def circ_event_str(self,now,circ_event):
+    """ returns an string summarizing the circuit event"""
+    output = [circ_event.event_name, str(circ_event.circ_id),
+        circ_event.status]
+    if circ_event.path:
+      output.append(",".join(circ_event.path))
+    if circ_event.reason:
+      output.append("REASON=" + circ_event.reason)
+    if circ_event.remote_reason:
+      output.append("REMOTE_REASON=" + circ_event.remote_reason)
+    output = [now]+ output
+    outstr = ' '.join(output) + '\n'
+    return outstr
+ 
+  def add_missed_events(self,circ_id):
+    """ if there are events for a circuit that were missed, add them"""
+    if circ_id in self.othercircs:
+      for e_str in self.othercircs[circ_id]:
+        self.detailfile.write(e_str)
+      self.detailfile.flush()
+      # now in self.circuits, so can delete it from self.othercircs
+      del self.othercircs[circ_id]
+      
+
   def circ_status_event(self, circ_event):
+    """ handles circuit status event """
     now = time.time()
     now = '%3.10f' % now
 
     if circ_event.circ_id in self.circuits.keys():
-      output = [circ_event.event_name, str(circ_event.circ_id),
-          circ_event.status]
-      if circ_event.path:
-        output.append(",".join(circ_event.path))
-      if circ_event.reason:
-        output.append("REASON=" + circ_event.reason)
-      if circ_event.remote_reason:
-        output.append("REMOTE_REASON=" + circ_event.remote_reason)
-     
-      output = [now]+ output
-      outstr = ' '.join(output) + '\n'
+      self.add_missed_events(circ_event.circ_id)
+      if circ_event.status == 'EXTENDED':
+        extend_time = circ_event.arrived_at-self.circuits[circ_event.circ_id].last_extended_at
+        self.circuits[circ_event.circ_id].extend_times.append(extend_time)
+        self.circuits[circ_event.circ_id].last_extended_at = circ_event.arrived_at
+
+      if circ_event.status == 'BUILT':
+        circ = self.circuits[circ_event.circ_id]
+        buildtime = reduce(lambda x,y:x+y,circ.extend_times,0.0)
+        self.buildtimesfile.write(str(circ.circ_id) + '\t' + str(buildtime) + '\n')
+        self.buildtimesfile.flush()
+
+      outstr = self.circ_event_str(now,circ_event)
       self.detailfile.write(outstr)
       self.detailfile.flush()
-      if self.circuits[circ_event.circ_id].setup_duration:
-        self.buildtimesfile.write(str(self.circuits[circ_event.circ_id].setup_duration) + '\n')
-      print 'wrote',outstr
 
       # check to see if done gathering data
       if circ_event.status == 'BUILT': self.circ_built += 1
-
+    else:
+      #eventstr = 
+      #if circ_event.circ_id in self.othercircs.keys():
+      if circ_event.circ_id not in self.othercircs.keys():
+        self.othercircs[circ_event.circ_id] = []
+      self.othercircs[circ_event.circ_id] += [self.circ_event_str(now,circ_event)]
     StatsHandler.circ_status_event(self,circ_event)
 
 def getdata(filename,ncircuits):
@@ -125,6 +158,8 @@
 def usage():
     print 'usage: statscontroller.py -p <#percentile>  -n <# circuits> -d <output dir name>'
     sys.exit(1)
+
+
 def main():
   ncircuits,p,dirname = setargs()
 
@@ -144,12 +179,19 @@
   __selmgr.percent_skip = p
   
   c = getdata(basefile_name,ncircuits) 
+
   for i in range(0,ncircuits):
-    circ = c.build_circuit(__selmgr.pathlen,__selmgr.path_selector)
-    c._handler.circuits[circ.circ_id] = circ
+    print 'Building circuit',i
+    try:
+      circ = c.build_circuit(__selmgr.pathlen,__selmgr.path_selector)
+      c._handler.circuits[circ.circ_id] = circ
+    except TorCtl.ErrorReply,e:
+      plog("NOTICE","Error building circuit: " + str(e.args))
+
   while True:
     if c._handler.circ_built + c._handler.circ_failed >= ncircuits:
-      print 'Done gathering'
+      print 'Done gathering stats for slice',p,'to',p+5,'on',ncircuits
+      print c._handler.circ_built,'built',c._handler.circ_failed,'failed' 
       break
   c._handler.write_stats(aggfile_name)