xref: /llvm-project/clang/utils/analyzer/SumTimerInfo.py (revision dd3c26a045c081620375a878159f536758baba6e)
1#!/usr/bin/env python
2
3"""
4Script to Summarize statistics in the scan-build output.
5
6Statistics are enabled by passing '-internal-stats' option to scan-build
7(or '-analyzer-stats' to the analyzer).
8"""
9import sys
10
11if __name__ == "__main__":
12    if len(sys.argv) < 2:
13        print("Usage: ", sys.argv[0], "scan_build_output_file", file=sys.stderr)
14        sys.exit(-1)
15
16    f = open(sys.argv[1], "r")
17    time = 0.0
18    total_time = 0.0
19    max_time = 0.0
20    warnings = 0
21    count = 0
22    functions_analyzed = 0
23    reachable_blocks = 0
24    reached_max_steps = 0
25    num_steps = 0
26    num_inlined_call_sites = 0
27    num_bifurcated_call_sites = 0
28    max_cfg_size = 0
29
30    for line in f:
31        if "Analyzer total time" in line:
32            s = line.split()
33            time = time + float(s[6])
34            count = count + 1
35            if float(s[6]) > max_time:
36                max_time = float(s[6])
37        if "warning generated." in line or "warnings generated" in line:
38            s = line.split()
39            warnings = warnings + int(s[0])
40        if "The # of functions analysed (as top level)" in line:
41            s = line.split()
42            functions_analyzed = functions_analyzed + int(s[0])
43        if "The % of reachable basic blocks" in line:
44            s = line.split()
45            reachable_blocks = reachable_blocks + int(s[0])
46        if "The # of times we reached the max number of steps" in line:
47            s = line.split()
48            reached_max_steps = reached_max_steps + int(s[0])
49        if "The maximum number of basic blocks in a function" in line:
50            s = line.split()
51            if max_cfg_size < int(s[0]):
52                max_cfg_size = int(s[0])
53        if "The # of steps executed" in line:
54            s = line.split()
55            num_steps = num_steps + int(s[0])
56        if "The # of times we inlined a call" in line:
57            s = line.split()
58            num_inlined_call_sites = num_inlined_call_sites + int(s[0])
59        if (
60            "The # of times we split the path due \
61                to imprecise dynamic dispatch info"
62            in line
63        ):
64            s = line.split()
65            num_bifurcated_call_sites = num_bifurcated_call_sites + int(s[0])
66        if ")  Total" in line:
67            s = line.split()
68            total_time = total_time + float(s[6])
69
70    print(f"TU count {count}")
71    print(f"Time {time}")
72    print(f"Warnings {warnings}")
73    print(f"Functions analyzed {functions_analyzed}")
74    print(f"Reachable blocks {reachable_blocks}")
75    print(f"Reached max steps {reached_max_steps}")
76    print(f"Number of steps {num_steps}")
77    print(
78        f"Number of inlined calls {num_inlined_call_sites} "
79        f"(bifurcated {num_bifurcated_call_sites})"
80    )
81    print(f"Max time {max_time}")
82    print(f"Total time {total_time}")
83    print(f"Max CFG Size {max_cfg_size}")
84