Created
September 21, 2020 12:43
-
-
Save chrismeyersfsu/9f77ba2a570b241964fe5c2c03d6fb49 to your computer and use it in GitHub Desktop.
strace analysis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import re | |
class Stats: | |
def __init__(self): | |
self.total = 0 | |
self.count = 0 | |
@property | |
def average(self): | |
if self.count != 0: | |
return self.total / self.count | |
else: | |
return 0 | |
def doit(filename): | |
s_size = Stats() | |
s_time = Stats() | |
first_timestamp = None | |
last_timestamp = None | |
with open(filename) as f: | |
strace_log = f.readlines() | |
for l in strace_log: | |
if 'recvfrom' in l: | |
res = re.match('(?P<timestamp>\d+\.\d+) (?P<junk>.*?)= (?P<ret>[-\d]+) <(?P<calltime>\d+\.\d+)>', l) | |
if res: | |
r = res.groupdict() | |
r['ret'] = int(r['ret']) | |
if not first_timestamp: | |
first_timestamp = int(float(r['timestamp'])) | |
last_timestamp = int(float(r['timestamp'])) | |
if r['ret'] >= 0: | |
s_size.total += r['ret'] | |
s_size.count += 1 | |
s_time.total += float(r['calltime']) | |
s_time.count += 1 | |
from datetime import timedelta | |
print(f"Bytes: calls {s_size.count} total {s_size.total} average {s_size.average} bytes/call") | |
print(f"Time: calls {s_time.count} total {s_time.total} (s) average {s_time.average} seconds") | |
total_time = timedelta(seconds=last_timestamp) - timedelta(seconds=first_timestamp) | |
bandwidth = s_size.total / total_time.seconds | |
ops = s_size.count / total_time.seconds | |
print("Experiment summary") | |
print(f"The experiment took {total_time} (hours:minutes:seconds) to run") | |
print(f"The bandwith, over the course of the experiment, averaged {bandwidth} bytes/s") | |
print(f"The average number of events per second was {int(ops)} per second over the course of the experiment.") | |
doit(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment