Skip to content

Commit 1035e98

Browse files
committed
fixed #14609 - valueflow.cpp: added iteration count to timer results [skip ci]
1 parent 498b2c6 commit 1035e98

2 files changed

Lines changed: 50 additions & 12 deletions

File tree

lib/valueflow.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7200,7 +7200,7 @@ struct ValueFlowPassRunner {
72007200
bool run_once(std::initializer_list<ValuePtr<ValueFlowPass>> passes) const
72017201
{
72027202
return std::any_of(passes.begin(), passes.end(), [&](const ValuePtr<ValueFlowPass>& pass) {
7203-
return run(pass);
7203+
return run(pass, 0);
72047204
});
72057205
}
72067206

@@ -7210,10 +7210,11 @@ struct ValueFlowPassRunner {
72107210
std::size_t n = state.settings.vfOptions.maxIterations;
72117211
while (n > 0 && values != getTotalValues()) {
72127212
values = getTotalValues();
7213-
const std::string passnum = std::to_string(state.settings.vfOptions.maxIterations - n + 1);
7213+
const std::size_t passnum = state.settings.vfOptions.maxIterations - n + 1;
7214+
const std::string passnum_s = std::to_string(passnum);
72147215
if (std::any_of(passes.begin(), passes.end(), [&](const ValuePtr<ValueFlowPass>& pass) {
7215-
ProgressReporter progressReporter(state.errorLogger, state.settings.reportProgress >= 0, state.tokenlist.getSourceFilePath(), std::string("ValueFlow::") + pass->name() + (' ' + passnum));
7216-
return run(pass);
7216+
ProgressReporter progressReporter(state.errorLogger, state.settings.reportProgress >= 0, state.tokenlist.getSourceFilePath(), std::string("ValueFlow::") + pass->name() + (' ' + passnum_s));
7217+
return run(pass, passnum);
72177218
}))
72187219
return true;
72197220
--n;
@@ -7233,7 +7234,7 @@ struct ValueFlowPassRunner {
72337234
return false;
72347235
}
72357236

7236-
bool run(const ValuePtr<ValueFlowPass>& pass) const
7237+
bool run(const ValuePtr<ValueFlowPass>& pass, std::size_t it) const
72377238
{
72387239
auto start = Clock::now();
72397240
if (start > stop) {
@@ -7243,7 +7244,12 @@ struct ValueFlowPassRunner {
72437244
if (!state.tokenlist.isCPP() && pass->cpp())
72447245
return false;
72457246
if (timerResults) {
7246-
Timer t(pass->name(), state.settings.showtime, timerResults);
7247+
std::string name = pass->name();
7248+
if (it > 0) {
7249+
name += ' ';
7250+
name += std::to_string(it);
7251+
}
7252+
Timer t(name, state.settings.showtime, timerResults);
72477253
pass->run(state);
72487254
} else {
72497255
pass->run(state);
@@ -7382,7 +7388,7 @@ void ValueFlow::setValues(TokenList& tokenlist,
73827388
VFA(valueFlowArray(tokenlist, settings)),
73837389
VFA(valueFlowUnknownFunctionReturn(tokenlist, settings)),
73847390
VFA(valueFlowGlobalConstVar(tokenlist, settings)),
7385-
VFA(valueFlowEnumValue(symboldatabase, settings)),
7391+
VFA(valueFlowEnumValue(symboldatabase, settings)), // TODO
73867392
VFA(valueFlowGlobalStaticVar(tokenlist, settings)),
73877393
VFA(valueFlowPointerAlias(tokenlist, settings)),
73887394
VFA(valueFlowLifetime(tokenlist, errorLogger, settings)),

test/cli/other_test.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ def __test_showtime(tmp_path, showtime, exp_len, exp_last, extra_args=None):
984984
assert len(lines) == exp_len
985985
idx_last = exp_len-1
986986
if idx_last:
987-
assert lines[0] == ''
987+
assert lines[0] == '' # TODO: get rid of the empty line
988988
for i in range(1, idx_last):
989989
assert 'avg.' in lines[i]
990990
assert lines[idx_last].startswith(exp_last)
@@ -1013,30 +1013,62 @@ def test_showtime_top5_summary_j_process(tmp_path):
10131013

10141014

10151015
def test_showtime_file(tmp_path):
1016-
__test_showtime(tmp_path, 'file', 79, 'Check time: ')
1016+
__test_showtime(tmp_path, 'file', 80, 'Check time: ')
10171017

10181018

10191019
# TODO: remove extra args when --executor=process works works
10201020
def test_showtime_summary(tmp_path):
1021-
__test_showtime(tmp_path, 'summary', 79, 'Overall time: ', ['-j1'])
1021+
__test_showtime(tmp_path, 'summary', 80, 'Overall time: ', ['-j1'])
10221022

10231023

10241024
# TODO: remove when --executor=process works works
10251025
def test_showtime_summary_j_thread(tmp_path):
1026-
__test_showtime(tmp_path, 'summary', 79, 'Overall time: ', ['-j2', '--executor=thread'])
1026+
__test_showtime(tmp_path, 'summary', 80, 'Overall time: ', ['-j2', '--executor=thread'])
10271027

10281028

10291029
# TODO: remove override when fixed
10301030
@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor")
10311031
@pytest.mark.xfail(strict=True) # TODO: need to transfer the timer results to parent process - see #4452
10321032
def test_showtime_summary_j_process(tmp_path):
1033-
__test_showtime(tmp_path, 'summary', 79, 'Overall time: ', ['-j2', '--executor=process'])
1033+
__test_showtime(tmp_path, 'summary', 80, 'Overall time: ', ['-j2', '--executor=process'])
10341034

10351035

10361036
def test_showtime_file_total(tmp_path):
10371037
__test_showtime(tmp_path, 'file-total', 1, 'Check time: ')
10381038

10391039

1040+
def test_showtime_unique(tmp_path):
1041+
test_file = tmp_path / 'test.cpp'
1042+
with open(test_file, 'wt') as f:
1043+
f.write(
1044+
"""
1045+
void f()
1046+
{
1047+
(void)(*((int*)0)); // cppcheck-suppress nullPointer
1048+
}
1049+
""")
1050+
1051+
args = [
1052+
f'--showtime=summary',
1053+
'--quiet',
1054+
'--inline-suppr',
1055+
str(test_file)
1056+
]
1057+
1058+
exitcode, stdout, stderr = cppcheck(args)
1059+
assert exitcode == 0
1060+
multi_res = []
1061+
for line in stdout.splitlines():
1062+
# TODO: get rid of empty line
1063+
if not line:
1064+
continue
1065+
if any(i in line for i in ['1 result(s)', 'Overall time:']):
1066+
continue
1067+
multi_res.append(line)
1068+
assert multi_res == []
1069+
assert stderr == ''
1070+
1071+
10401072
def test_missing_addon(tmpdir):
10411073
args = ['--addon=misra3', '--addon=misra', '--addon=misra2', 'file.c']
10421074

0 commit comments

Comments
 (0)