-
Notifications
You must be signed in to change notification settings - Fork 0
/
show_overlap.py
executable file
·60 lines (49 loc) · 1.88 KB
/
show_overlap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
import argparse
from datetime import datetime
import sys
import pandas
def parseArgs(args):
parser = argparse.ArgumentParser()
parser.add_argument('file', type=str,
help='File to process.')
parser.add_argument('event', type=str,
help='File to process.')
parser.add_argument('--show-spans', action="store_true", default=False,
help='Show spans when there is an overlap')
parser.add_argument('--find-spans', action="store_true", default=False,
help='Find overlapping spans')
parser.add_argument('--hide-rows', action="store_true", default=False,
help='Hide rows')
return parser.parse_args(args)
def process_overlap(args, progress_trace):
spans = {}
filtered_events = progress_trace[progress_trace['MESSAGE'] == args.event]
for ts, fields in filtered_events.sort_index().iterrows():
et = fields['EVENT TYPE']
tid = fields['TRANSACTION ID']
if et == 'start':
assert(tid not in spans)
spans[tid] = 1
if not args.hide_rows:
print(f"{ts} {len(spans)}")
if args.show_spans and len(spans.keys())>1:
print(spans)
elif et == 'stop':
del spans[tid]
if not args.hide_rows:
print(f"{ts} {len(spans)}")
p_ts = ts
p_tid = tid
def main(args):
progress_trace = pandas.read_csv(args.file,
index_col='TIMESTAMP',
converters={'TIMESTAMP': datetime.fromisoformat}
).sort_values('TIMESTAMP')
running = progress_trace[progress_trace['DATASTORE'] == 'running']
if args.find_spans:
args.hide_rows = True
args.show_spans = True
process_overlap(args, running)
if __name__ == '__main__':
main(parseArgs(sys.argv[1:]))