Track inter-request delay in TCP analysis
authorMichael Vrable <mvrable@cs.ucsd.edu>
Thu, 10 Mar 2011 06:15:41 +0000 (22:15 -0800)
committerMichael Vrable <mvrable@cs.ucsd.edu>
Thu, 10 Mar 2011 06:15:41 +0000 (22:15 -0800)
When analyzing TCP connections, track the time the connection goes idle
(between the end of one request and start of the next).

parsetrace/analyze-tcp.py

index d050d08..fb58b6a 100755 (executable)
@@ -91,7 +91,7 @@ def split_trace(packets, predicate, before=True):
     if len(segment) > 0:
         yield segment
 
     if len(segment) > 0:
         yield segment
 
-def analyze_get(packets):
+def analyze_get(packets, prev_time = None):
     packets = iter(packets)
     p = packets.next()
 
     packets = iter(packets)
     p = packets.next()
 
@@ -152,10 +152,15 @@ def analyze_get(packets):
         tot_bytes = max(tot_bytes, bytenr)
 
     #print "Transferred %d bytes in %s seconds, initial response after %s" % (tot_bytes, last_ts - start_ts, resp_ts - start_ts)
         tot_bytes = max(tot_bytes, bytenr)
 
     #print "Transferred %d bytes in %s seconds, initial response after %s" % (tot_bytes, last_ts - start_ts, resp_ts - start_ts)
+    if prev_time is not None:
+        prev_delay = start_ts - prev_time
+    else:
+        prev_delay = 0
     return {'bytes': tot_bytes,
             'start_latency': resp_ts - start_ts,
             'finish_latency': last_ts - start_ts,
     return {'bytes': tot_bytes,
             'start_latency': resp_ts - start_ts,
             'finish_latency': last_ts - start_ts,
-            'interpacket_times': spacings}
+            'interpacket_times': spacings,
+            'delay_from_previous': prev_delay}
 
 if __name__ == '__main__':
     for f in sys.argv[1:]:
 
 if __name__ == '__main__':
     for f in sys.argv[1:]:
@@ -165,6 +170,7 @@ if __name__ == '__main__':
         def request_start(p):
             return p.direction > 0 and p.datalen > 0
         result_list = []
         def request_start(p):
             return p.direction > 0 and p.datalen > 0
         result_list = []
+        prev_time = None
         for s in split_trace(conn.packets, request_start):
             s = list(s)
             if False:
         for s in split_trace(conn.packets, request_start):
             s = list(s)
             if False:
@@ -177,9 +183,10 @@ if __name__ == '__main__':
                     #print p
                     #if p.direction > 0 and p.datalen > 0:
                         #print "Request:", repr(p.data)
                     #print p
                     #if p.direction > 0 and p.datalen > 0:
                         #print "Request:", repr(p.data)
-            results = analyze_get(s)
+            results = analyze_get(s, prev_time)
             if results is not None:
                 result_list.append(results)
             if results is not None:
                 result_list.append(results)
+            prev_time = s[-1].ts
             #print "===="
 
         print dump_data(result_list)
             #print "===="
 
         print dump_data(result_list)