Skip to content

Commit 4807bff

Browse files
authored
triage_version.py: added --perf to collect performance data in CSV format (#4833)
* removed old timing tracking code * tools/triage_py/README.md: updated * triage_version.py: fixed output when when stderr and stdout are not empty * triage_version.py: added `--perf` to collect performance data in CSV format * triage_version.py: added TODO about providing additional options * triage_version.py: added `--start` to specify the first tag/commit to execute
1 parent 5a2c31a commit 4807bff

6 files changed

Lines changed: 49 additions & 165 deletions

File tree

tools/times-tags.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

tools/times-vs.py

Lines changed: 0 additions & 58 deletions
This file was deleted.

tools/times.c

Lines changed: 0 additions & 47 deletions
This file was deleted.

tools/times.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

tools/triage_py/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ A script to run a code sample against a given set of Cppcheck versions.
55
## Usage
66

77
```
8-
usage: triage_version.py [-h] [--compare] [--verbose] [--debug] [--debug-warnings] [--check-library] [--timeout TIMEOUT]
9-
[--compact]
10-
dir infile [repo]
8+
usage: triage_version.py [-h] [--compare] [--verbose] [--debug] [--debug-warnings] [--check-library]
9+
[--timeout TIMEOUT] [--compact] [--no-quiet] [--perf] [--start START]
10+
[--no-stderr | --no-stdout]
11+
dir infile [repo]
1112
1213
positional arguments:
1314
dir directory with versioned folders
@@ -23,6 +24,11 @@ options:
2324
--check-library passed through to binary if supported
2425
--timeout TIMEOUT the amount of seconds to wait for the analysis to finish
2526
--compact only print versions with changes with --compare
27+
--no-quiet do not specify -q
28+
--perf output duration of execution in seconds (CSV format)
29+
--start START specify the start version/commit
30+
--no-stderr do not display stdout
31+
--no-stdout do not display stderr
2632
```
2733

2834
### Structure of `dir`

tools/triage_py/triage_version.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import subprocess
44
import sys
55
import argparse
6+
import time
67

78
from packaging.version import Version
89

@@ -18,6 +19,8 @@
1819
parser.add_argument('--timeout', type=int, default=2, help='the amount of seconds to wait for the analysis to finish')
1920
parser.add_argument('--compact', action='store_true', help='only print versions with changes with --compare')
2021
parser.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')
2124
package_group = parser.add_mutually_exclusive_group()
2225
package_group.add_argument('--no-stderr', action='store_true', default=False, help='do not display stdout')
2326
package_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

4353
directory = args.dir
4454
input_file = args.infile
@@ -91,7 +101,17 @@ def sort_commit_hashes(commits):
91101
last_ec = None
92102
last_out = None
93103

104+
if args.perf:
105+
print('version,time')
106+
107+
start_entry = args.start
108+
94109
for 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

Comments
 (0)