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 earlier than 10 seconds ago 24# and not later than now. 25if beginning_of_time > seconds_since_epoch or \ 26 seconds_since_epoch - beginning_of_time > 10: 27 sys.exit("'beginningOfTime' should represent the absolute time when the " 28 "process has started") 29 30if not all([any([is_inside(codegen, frontend) for frontend in frontends]) 31 for codegen in codegens]): 32 sys.exit("Not all CodeGen sections are inside any Frontend section!") 33 34if not all([all([is_before(frontend, backend) for frontend in frontends]) 35 for backend in backends]): 36 sys.exit("Not all Frontend section are before all Backend sections!") 37