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