[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Driver / check-time-trace-sections.py
blob297ab38e36555f46da13e623709ca04f90b5c15c
1 #!/usr/bin/env python
3 import json, sys, time
5 def 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)
10 def is_before(range1, range2):
11 b = range1["ts"] + range1["dur"]; c = range2["ts"]
12 return b <= c
14 log_contents = json.loads(sys.stdin.read())
15 events = log_contents["traceEvents"]
16 codegens = [event for event in events if event["name"] == "CodeGen Function"]
17 frontends = [event for event in events if event["name"] == "Frontend"]
18 backends = [event for event in events if event["name"] == "Backend"]
20 beginning_of_time = log_contents["beginningOfTime"] / 1000000
21 seconds_since_epoch = time.time()
23 # Make sure that the 'beginningOfTime' is not later than now.
24 if beginning_of_time > seconds_since_epoch:
25 sys.exit("'beginningOfTime' should represent the absolute time when the "
26 "process has started")
28 if 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!")
32 if 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!")