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