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