1#!/usr/bin/env python 2 3import json, sys, time 4 5def is_inside(range1, range2): 6 a = range1["ts"]; b = a + range1["dur"] 7 c = range2["ts"]; d = c + range2["dur"] 8 return (a >= c and a <= d) and (b >= c and b <= d) 9 10def is_before(range1, range2): 11 b = range1["ts"] + range1["dur"]; c = range2["ts"] 12 return b <= c 13 14log_contents = json.loads(sys.stdin.read()) 15events = log_contents["traceEvents"] 16codegens = [event for event in events if event["name"] == "CodeGen Function"] 17frontends = [event for event in events if event["name"] == "Frontend"] 18backends = [event for event in events if event["name"] == "Backend"] 19 20beginning_of_time = log_contents["beginningOfTime"] / 1000000 21seconds_since_epoch = time.time() 22 23# Make sure that the 'beginningOfTime' is not later than now. 24if beginning_of_time > seconds_since_epoch: 25 sys.exit("'beginningOfTime' should represent the absolute time when the " 26 "process has started") 27 28if not all([any([is_inside(codegen, frontend) for frontend in frontends]) 29 for codegen in codegens]): 30 sys.exit("Not all CodeGen sections are inside any Frontend section!") 31 32if not all([all([is_before(frontend, backend) for frontend in frontends]) 33 for backend in backends]): 34 sys.exit("Not all Frontend section are before all Backend sections!") 35