#!/usr/bin/env python
importjson,sys,timedefis_inside(range1,range2):a=range1["ts"];b=a+range1["dur"]c=range2["ts"];d=c+range2["dur"]return(a>=canda<=d)and(b>=candb<=d)defis_before(range1,range2):b=range1["ts"]+range1["dur"];c=range2["ts"]returnb<=clog_contents=json.loads(sys.stdin.read())events=log_contents["traceEvents"]codegens=[eventforeventineventsifevent["name"]=="CodeGen Function"]frontends=[eventforeventineventsifevent["name"]=="Frontend"]backends=[eventforeventineventsifevent["name"]=="Backend"]beginning_of_time=log_contents["beginningOfTime"]/1000000seconds_since_epoch=time.time()# Make sure that the 'beginningOfTime' is not later than now.
ifbeginning_of_time>seconds_since_epoch:sys.exit("'beginningOfTime' should represent the absolute time when the ""process has started")ifnotall([any([is_inside(codegen,frontend)forfrontendinfrontends])forcodegenincodegens]):sys.exit("Not all CodeGen sections are inside any Frontend section!")ifnotall([all([is_before(frontend,backend)forfrontendinfrontends])forbackendinbackends]):sys.exit("Not all Frontend section are before all Backend sections!")