33import subprocess
44import sys
55import argparse
6+ import time
67
78from packaging .version import Version
89
1819parser .add_argument ('--timeout' , type = int , default = 2 , help = 'the amount of seconds to wait for the analysis to finish' )
1920parser .add_argument ('--compact' , action = 'store_true' , help = 'only print versions with changes with --compare' )
2021parser .add_argument ('--no-quiet' , action = 'store_true' , default = False , help = 'do not specify -q' )
22+ parser .add_argument ('--perf' , action = 'store_true' , default = False , help = 'output duration of execution in seconds (CSV format)' )
23+ parser .add_argument ('--start' , default = None , help = 'specify the start version/commit' )
2124package_group = parser .add_mutually_exclusive_group ()
2225package_group .add_argument ('--no-stderr' , action = 'store_true' , default = False , help = 'do not display stdout' )
2326package_group .add_argument ('--no-stdout' , action = 'store_true' , default = False , help = 'do not display stderr' )
@@ -39,6 +42,13 @@ def sort_commit_hashes(commits):
3942 if not do_compare :
4043 print ('error: --compact requires --compare' )
4144 sys .exit (1 )
45+ if args .perf :
46+ if args .compact :
47+ print ('error: --compact has no effect with --perf' )
48+ if args .no_stdout :
49+ print ('error: --no-stdout has no effect with --perf' )
50+ if args .no_stderr :
51+ print ('error: --no-stderr has no effect with --perf' )
4252
4353directory = args .dir
4454input_file = args .infile
@@ -91,7 +101,17 @@ def sort_commit_hashes(commits):
91101last_ec = None
92102last_out = None
93103
104+ if args .perf :
105+ print ('version,time' )
106+
107+ start_entry = args .start
108+
94109for entry in versions :
110+ if start_entry :
111+ if start_entry != entry :
112+ continue
113+ start_entry = None
114+
95115 exe_path = os .path .join (directory , entry )
96116 exe = os .path .join (exe_path , 'cppcheck' )
97117
@@ -134,16 +154,23 @@ def sort_commit_hashes(commits):
134154 else :
135155 # TODO: re-add inconclusive: {callstack}: ({severity}{inconclusive:, inconclusive}) {message
136156 cmd .append ('--template={callstack}: ({severity}) {message} [{id}]' )
157+ # TODO: how to pass addtional options?
158+ if args .perf :
159+ cmd .append ('--error-exitcode=0' )
137160 cmd .append (input_file )
138161 if verbose :
139162 print ("running '{}'" . format (' ' .join (cmd )))
163+ if args .perf :
164+ start = time .time_ns ()
140165 p = subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , cwd = exe_path , universal_newlines = True )
141166 try :
142167 comm = p .communicate (timeout = args .timeout )
168+ if args .perf :
169+ end = time .time_ns ()
143170 out = ''
144171 if not args .no_stdout :
145172 out += comm [0 ]
146- if not args .no_stderr and not args .no_stderr :
173+ if not args .no_stdout and not args .no_stderr :
147174 out += '\n '
148175 if not args .no_stderr :
149176 out += comm [1 ]
@@ -156,9 +183,19 @@ def sort_commit_hashes(commits):
156183
157184 if not do_compare :
158185 if not use_hashes :
159- print ( version )
186+ ver_str = version
160187 else :
161- print ('{} ({})' .format (entry , version ))
188+ ver_str = '{} ({})' .format (entry , version )
189+ if args .perf :
190+ if out == "timeout" :
191+ data_str = "0.0" # TODO: how to handle these properly?
192+ elif not ec == 0 :
193+ continue # skip errors
194+ else :
195+ data_str = '{}' .format ((end - start ) / 1000.0 / 1000.0 / 1000.0 )
196+ print ('"{}",{}' .format (ver_str , data_str ))
197+ continue
198+ print (ver_str )
162199 print (ec )
163200 print (out )
164201 continue
0 commit comments