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