Skip to content

Commit 840b39c

Browse files
committed
deprecated --showtime=top5 and introduced the modes top5_file and top5_summary / temporarily disabled collecting of timing information in daca
1 parent a27b655 commit 840b39c

File tree

12 files changed

+196
-37
lines changed

12 files changed

+196
-37
lines changed

cli/cmdlineparser.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -814,12 +814,22 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
814814
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_FILE;
815815
else if (showtimeMode == "summary")
816816
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_SUMMARY;
817-
else if (showtimeMode == "top5")
818-
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_TOP5;
819-
else if (showtimeMode.empty())
817+
else if (showtimeMode == "top5") {
818+
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_TOP5_FILE;
819+
printMessage("--showtime=top5 is deprecated and will be removed in Cppcheck 2.13. Please use --showtime=top5_file or --showtime=top5_summary instead.");
820+
}
821+
else if (showtimeMode == "top5_file")
822+
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_TOP5_FILE;
823+
else if (showtimeMode == "top5_summary")
824+
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY;
825+
else if (showtimeMode == "none")
820826
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_NONE;
827+
else if (showtimeMode.empty()) {
828+
printError("no mode provided for --showtime");
829+
return false;
830+
}
821831
else {
822-
printError("unrecognized showtime mode: \"" + showtimeMode + "\". Supported modes: file, summary, top5.");
832+
printError("unrecognized --showtime mode: '" + showtimeMode + "'");
823833
return false;
824834
}
825835
}
@@ -1287,7 +1297,20 @@ void CmdLineParser::printHelp()
12871297
" --rule-file=<file> Use given rule file. For more information, see:\n"
12881298
" http://sourceforge.net/projects/cppcheck/files/Articles/\n"
12891299
#endif
1290-
// TODO: document --showtime
1300+
" --showtime=<mode> Show timing information.\n"
1301+
" The available modes are:\n"
1302+
" * none\n"
1303+
" Show nothing (default)\n"
1304+
" * file\n"
1305+
" Show for each processed file\n"
1306+
" * summary\n"
1307+
" Show a summary at the end\n"
1308+
" * top5_file\n"
1309+
" Show the top 5 for each processed file\n"
1310+
" * top5_summary\n"
1311+
" Show the top 5 summary at the end\n"
1312+
" * top5\n"
1313+
" Alias for top5_file (deprecated)\n"
12911314
" --std=<id> Set standard.\n"
12921315
" The available options are:\n"
12931316
" * c89\n"

cli/threadexecutor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ unsigned int ThreadExecutor::check()
194194
return v + f.get();
195195
});
196196

197-
if (mSettings.showtime == SHOWTIME_MODES::SHOWTIME_SUMMARY)
198-
CppCheck::printTimerResultsSummary();
197+
if (mSettings.showtime == SHOWTIME_MODES::SHOWTIME_SUMMARY || mSettings.showtime == SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY)
198+
CppCheck::printTimerResults(mSettings.showtime);
199199

200200
return result;
201201
}

lib/cppcheck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ CppCheck::~CppCheck()
406406
mFileInfo.pop_back();
407407
}
408408

409-
if (mSettings.showtime != SHOWTIME_MODES::SHOWTIME_SUMMARY)
410-
s_timerResults.showResults(mSettings.showtime);
409+
if (mSettings.showtime == SHOWTIME_MODES::SHOWTIME_FILE || mSettings.showtime == SHOWTIME_MODES::SHOWTIME_TOP5_FILE)
410+
printTimerResults(mSettings.showtime);
411411

412412
if (mPlistFile.is_open()) {
413413
mPlistFile << ErrorLogger::plistFooter();
@@ -1859,7 +1859,7 @@ void CppCheck::resetTimerResults()
18591859
s_timerResults.reset();
18601860
}
18611861

1862-
void CppCheck::printTimerResultsSummary()
1862+
void CppCheck::printTimerResults(SHOWTIME_MODES mode)
18631863
{
1864-
s_timerResults.showResults(SHOWTIME_MODES::SHOWTIME_SUMMARY);
1864+
s_timerResults.showResults(mode);
18651865
}

lib/cppcheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
148148
void removeCtuInfoFiles(const std::map<std::string, std::size_t>& files);
149149

150150
static void resetTimerResults();
151-
static void printTimerResultsSummary();
151+
static void printTimerResults(SHOWTIME_MODES mode);
152152

153153
private:
154154
/** Are there "simple" rules */

lib/timer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void TimerResults::showResults(SHOWTIME_MODES mode) const
5555
const double sec = iter->second.seconds();
5656
const double secAverage = sec / (double)(iter->second.mNumberOfResults);
5757
overallData.mClocks += iter->second.mClocks;
58-
if ((mode != SHOWTIME_MODES::SHOWTIME_TOP5) || (ordinal<=5)) {
58+
if ((mode != SHOWTIME_MODES::SHOWTIME_TOP5_FILE && mode != SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY) || (ordinal<=5)) {
5959
std::cout << iter->first << ": " << sec << "s (avg. " << secAverage << "s - " << iter->second.mNumberOfResults << " result(s))" << std::endl;
6060
}
6161
++ordinal;

lib/timer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ enum class SHOWTIME_MODES {
3131
SHOWTIME_NONE = 0,
3232
SHOWTIME_FILE,
3333
SHOWTIME_SUMMARY,
34-
SHOWTIME_TOP5
34+
SHOWTIME_TOP5_SUMMARY,
35+
SHOWTIME_TOP5_FILE
3536
};
3637

3738
class CPPCHECKLIB TimerResultsIntf {

man/cppcheck.1.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
189189
<arg choice="opt">
190190
<option>--rule-file=&lt;file&gt;</option>
191191
</arg>
192+
<arg choice="opt">
193+
<option>--showtime=&lt;mode&gt;</option>
194+
</arg>
192195
<arg choice="opt">
193196
<option>--std=&lt;id&gt;</option>
194197
</arg>
@@ -543,6 +546,16 @@ There are false positives with this option. Each result must be carefully invest
543546
<para>Use given rule XML file. See https://sourceforge.net/projects/cppcheck/files/Articles/ for more info about the syntax. This command is only available if cppcheck was compiled with HAVE_RULES=yes.</para>
544547
</listitem>
545548
</varlistentry>
549+
<varlistentry>
550+
<term>
551+
<option>--showtime=&lt;mode&gt;</option>
552+
</term>
553+
<listitem>
554+
<para>Show timing information. The available mode are:
555+
<glosslist><glossentry><glossterm>none</glossterm><glossdef><para>Show nothing (default)</para></glossdef></glossentry><glossentry><glossterm>file</glossterm><glossdef><para>Show for each processed file</para></glossdef></glossentry><glossentry><glossterm>summary</glossterm><glossdef><para>Show a summary at the end</para></glossdef></glossentry><glossentry><glossterm>top5_file</glossterm><glossdef><para>Show the top 5 for each processed file</para></glossdef></glossentry><glossentry><glossterm>top5_summary</glossterm><glossdef><para>Show the top 5 summary at the end</para></glossdef></glossentry><glossentry><glossterm>top5</glossterm><glossdef><para>Alias for top5_file (deprecated)</para></glossdef></glossentry></glosslist>
556+
</para>
557+
</listitem>
558+
</varlistentry>
546559
<varlistentry>
547560
<term>
548561
<option>--std=&lt;id&gt;</option>

releasenotes.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ release notes for cppcheck-2.11
55
- "missingInclude" and "missingIncludeSystem" are reported with "-j" is > 1 and processes are used in the backend (default in non-Windows binaries)
66
- "missingInclude" and "missingIncludeSystem" will now cause the "--error-exitcode" to be applied
77
- "--enable=information" will no longer implicitly enable "missingInclude" starting with 2.16. Please enable it explicitly if you require it.
8-
- "--showtime=summary" will now show a single summary at the end instead of showing it after each file when using the thread execution (default on Windows)
8+
- "--showtime=summary" will now show a single summary at the end instead of showing it after each file when using the thread execution (default on Windows)
9+
- "--showtime=top5" has been deprecated and will be removed in Cppcheck 2.13. Please use --showtime=top5_file or --showtime=top5_summary instead.
10+
- added "--showtime=none" to disable any previously specified showtime report. "--showtime=" without parameter is no longer valid.

test/testcmdlineparser.cpp

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,13 @@ class TestCmdlineParser : public TestFixture {
169169
TEST_CASE(xmlverunknown);
170170
TEST_CASE(xmlverinvalid);
171171
TEST_CASE(doc);
172-
TEST_CASE(showtime);
172+
TEST_CASE(showtimeFile);
173+
TEST_CASE(showtimeTop5);
174+
TEST_CASE(showtimeTop5File);
175+
TEST_CASE(showtimeTop5Summary);
176+
TEST_CASE(showtimeNone);
177+
TEST_CASE(showtimeEmpty);
178+
TEST_CASE(showtimeInvalid);
173179
TEST_CASE(errorlist1);
174180
TEST_CASE(errorlistverbose1);
175181
TEST_CASE(errorlistverbose2);
@@ -1354,7 +1360,7 @@ class TestCmdlineParser : public TestFixture {
13541360
ASSERT(GET_REDIRECT_OUTPUT.find("## ") == 0);
13551361
}
13561362

1357-
void showtime() {
1363+
void showtimeSummary() {
13581364
REDIRECT;
13591365
const char * const argv[] = {"cppcheck", "--showtime=summary"};
13601366
settings.showtime = SHOWTIME_MODES::SHOWTIME_NONE;
@@ -1363,6 +1369,65 @@ class TestCmdlineParser : public TestFixture {
13631369
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
13641370
}
13651371

1372+
void showtimeFile() {
1373+
REDIRECT;
1374+
const char * const argv[] = {"cppcheck", "--showtime=file"};
1375+
settings.showtime = SHOWTIME_MODES::SHOWTIME_NONE;
1376+
ASSERT(defParser.parseFromArgs(2, argv));
1377+
ASSERT(settings.showtime == SHOWTIME_MODES::SHOWTIME_FILE);
1378+
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1379+
}
1380+
1381+
void showtimeTop5() {
1382+
REDIRECT;
1383+
const char * const argv[] = {"cppcheck", "--showtime=top5"};
1384+
settings.showtime = SHOWTIME_MODES::SHOWTIME_NONE;
1385+
ASSERT(defParser.parseFromArgs(2, argv));
1386+
ASSERT(settings.showtime == SHOWTIME_MODES::SHOWTIME_TOP5_FILE);
1387+
ASSERT_EQUALS("cppcheck: --showtime=top5 is deprecated and will be removed in Cppcheck 2.13. Please use --showtime=top5_file or --showtime=top5_summary instead.\n", GET_REDIRECT_OUTPUT);
1388+
}
1389+
1390+
void showtimeTop5File() {
1391+
REDIRECT;
1392+
const char * const argv[] = {"cppcheck", "--showtime=top5_file"};
1393+
settings.showtime = SHOWTIME_MODES::SHOWTIME_NONE;
1394+
ASSERT(defParser.parseFromArgs(2, argv));
1395+
ASSERT(settings.showtime == SHOWTIME_MODES::SHOWTIME_TOP5_FILE);
1396+
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1397+
}
1398+
1399+
void showtimeTop5Summary() {
1400+
REDIRECT;
1401+
const char * const argv[] = {"cppcheck", "--showtime=top5_summary"};
1402+
settings.showtime = SHOWTIME_MODES::SHOWTIME_NONE;
1403+
ASSERT(defParser.parseFromArgs(2, argv));
1404+
ASSERT(settings.showtime == SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY);
1405+
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1406+
}
1407+
1408+
void showtimeNone() {
1409+
REDIRECT;
1410+
const char * const argv[] = {"cppcheck", "--showtime=none"};
1411+
settings.showtime = SHOWTIME_MODES::SHOWTIME_FILE;
1412+
ASSERT(defParser.parseFromArgs(2, argv));
1413+
ASSERT(settings.showtime == SHOWTIME_MODES::SHOWTIME_NONE);
1414+
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
1415+
}
1416+
1417+
void showtimeEmpty() {
1418+
REDIRECT;
1419+
const char * const argv[] = {"cppcheck", "--showtime="};
1420+
ASSERT(!defParser.parseFromArgs(2, argv));
1421+
ASSERT_EQUALS("cppcheck: error: no mode provided for --showtime\n", GET_REDIRECT_OUTPUT);
1422+
}
1423+
1424+
void showtimeInvalid() {
1425+
REDIRECT;
1426+
const char * const argv[] = {"cppcheck", "--showtime=top10"};
1427+
ASSERT(!defParser.parseFromArgs(2, argv));
1428+
ASSERT_EQUALS("cppcheck: error: unrecognized --showtime mode: 'top10'\n", GET_REDIRECT_OUTPUT);
1429+
}
1430+
13661431
void errorlist1() {
13671432
REDIRECT;
13681433
const char * const argv[] = {"cppcheck", "--errorlist"};

test/testprocessexecutor.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ class TestProcessExecutor : public TestFixture {
8282
TEST_CASE(no_errors_equal_amount_files);
8383
TEST_CASE(one_error_less_files);
8484
TEST_CASE(one_error_several_files);
85-
TEST_CASE(showtime_top5);
85+
TEST_CASE(showtime_top5_file);
86+
TEST_CASE(showtime_top5_summary);
8687
TEST_CASE(showtime_file);
8788
TEST_CASE(showtime_summary);
88-
TEST_CASE(showtime_top5_j);
89+
TEST_CASE(showtime_top5_file_j);
90+
TEST_CASE(showtime_top5_summary_j);
8991
TEST_CASE(showtime_file_j);
9092
TEST_CASE(showtime_summary_j);
9193
#endif // !WIN32
@@ -180,17 +182,29 @@ class TestProcessExecutor : public TestFixture {
180182

181183
// TODO: provide data which actually shows values above 0
182184

183-
// TODO: should this be logged only once like summary?
184-
void showtime_top5() {
185+
void showtime_top5_file() {
185186
REDIRECT;
186187
check(1, 2, 0,
187188
"int main() {}",
188-
true, SHOWTIME_MODES::SHOWTIME_TOP5);
189-
// for each file: top5 results + overall + empty line
189+
true, SHOWTIME_MODES::SHOWTIME_TOP5_FILE);
190190
const std::string output_s = GET_REDIRECT_OUTPUT;
191+
// for each file: top5 results + overall + empty line
191192
TODO_ASSERT_EQUALS((5 + 1 + 1) * 2, 0, cppcheck::find_all_of(output_s, '\n'));
192193
}
193194

195+
void showtime_top5_summary() {
196+
REDIRECT;
197+
check(1, 2, 0,
198+
"int main() {}",
199+
true, SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY);
200+
const std::string output_s = GET_REDIRECT_OUTPUT;
201+
// once: top5 results + overall + empty line
202+
TODO_ASSERT_EQUALS(5 + 1 + 1, 0, cppcheck::find_all_of(output_s, '\n'));
203+
// should only report the top5 once
204+
ASSERT(output_s.find("1 result(s)") == std::string::npos);
205+
TODO_ASSERT(output_s.find("2 result(s)") != std::string::npos);
206+
}
207+
194208
void showtime_file() {
195209
REDIRECT;
196210
check(1, 2, 0,
@@ -211,16 +225,29 @@ class TestProcessExecutor : public TestFixture {
211225
TODO_ASSERT(output_s.find("2 result(s)") != std::string::npos);
212226
}
213227

214-
void showtime_top5_j() {
228+
void showtime_top5_file_j() {
215229
REDIRECT; // should not cause TSAN failures as the showtime logging is synchronized
216230
check(2, 2, 0,
217231
"int main() {}",
218-
true, SHOWTIME_MODES::SHOWTIME_TOP5);
219-
// for each file: top5 results + overall + empty line
232+
true, SHOWTIME_MODES::SHOWTIME_TOP5_FILE);
220233
const std::string output_s = GET_REDIRECT_OUTPUT;
234+
// for each file: top5 results + overall + empty line
221235
TODO_ASSERT_EQUALS((5 + 1 + 1) * 2, 0, cppcheck::find_all_of(output_s, '\n'));
222236
}
223237

238+
void showtime_top5_summary_j() {
239+
REDIRECT; // should not cause TSAN failures as the showtime logging is synchronized
240+
check(2, 2, 0,
241+
"int main() {}",
242+
true, SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY);
243+
const std::string output_s = GET_REDIRECT_OUTPUT;
244+
// once: top5 results + overall + empty line
245+
TODO_ASSERT_EQUALS(5 + 1 + 1, 0, cppcheck::find_all_of(output_s, '\n'));
246+
// should only report the top5 once
247+
ASSERT(output_s.find("1 result(s)") == std::string::npos);
248+
TODO_ASSERT(output_s.find("2 result(s)") != std::string::npos);
249+
}
250+
224251
void showtime_file_j() {
225252
REDIRECT; // should not cause TSAN failures as the showtime logging is synchronized
226253
check(2, 2, 0,

0 commit comments

Comments
 (0)