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], 14 'scan_build_output_file', file=sys.stderr) 15 sys.exit(-1) 16 17 f = open(sys.argv[1], 'r') 18 time = 0.0 19 total_time = 0.0 20 max_time = 0.0 21 warnings = 0 22 count = 0 23 functions_analyzed = 0 24 reachable_blocks = 0 25 reached_max_steps = 0 26 num_steps = 0 27 num_inlined_call_sites = 0 28 num_bifurcated_call_sites = 0 29 max_cfg_size = 0 30 31 for line in f: 32 if "Analyzer total time" in line: 33 s = line.split() 34 time = time + float(s[6]) 35 count = count + 1 36 if float(s[6]) > max_time: 37 max_time = float(s[6]) 38 if "warning generated." in line or "warnings generated" in line: 39 s = line.split() 40 warnings = warnings + int(s[0]) 41 if "The # of functions analysed (as top level)" in line: 42 s = line.split() 43 functions_analyzed = functions_analyzed + int(s[0]) 44 if "The % of reachable basic blocks" in line: 45 s = line.split() 46 reachable_blocks = reachable_blocks + int(s[0]) 47 if "The # of times we reached the max number of steps" in line: 48 s = line.split() 49 reached_max_steps = reached_max_steps + int(s[0]) 50 if "The maximum number of basic blocks in a function" in line: 51 s = line.split() 52 if max_cfg_size < int(s[0]): 53 max_cfg_size = int(s[0]) 54 if "The # of steps executed" in line: 55 s = line.split() 56 num_steps = num_steps + int(s[0]) 57 if "The # of times we inlined a call" in line: 58 s = line.split() 59 num_inlined_call_sites = num_inlined_call_sites + int(s[0]) 60 if "The # of times we split the path due \ 61 to imprecise dynamic dispatch info" in line: 62 s = line.split() 63 num_bifurcated_call_sites = num_bifurcated_call_sites + int(s[0]) 64 if ") Total" in line: 65 s = line.split() 66 total_time = total_time + float(s[6]) 67 68 print(f"TU count {count}") 69 print(f"Time {time}") 70 print(f"Warnings {warnings}") 71 print(f"Functions analyzed {functions_analyzed}") 72 print(f"Reachable blocks {reachable_blocks}") 73 print(f"Reached max steps {reached_max_steps}") 74 print(f"Number of steps {num_steps}") 75 print(f"Number of inlined calls {num_inlined_call_sites} " 76 f"(bifurcated {num_bifurcated_call_sites})") 77 print(f"Max time {max_time}") 78 print(f"Total time {total_time}") 79 print(f"Max CFG Size {max_cfg_size}") 80