[libFuzzer] add option -report_slow_units=Nsec to control when slow units are printed

llvm-svn: 244152
This commit is contained in:
Kostya Serebryany 2015-08-05 21:43:48 +00:00
parent 5be4cb583e
commit 80051e17c0
4 changed files with 8 additions and 3 deletions

View File

@ -247,6 +247,7 @@ int FuzzerDriver(int argc, char **argv, UserSuppliedFuzzer &USF) {
if (Flags.sync_command)
Options.SyncCommand = Flags.sync_command;
Options.SyncTimeout = Flags.sync_timeout;
Options.ReportSlowUnits = Flags.report_slow_units;
Fuzzer F(USF, Options);
if (Flags.apply_tokens)

View File

@ -58,3 +58,5 @@ FUZZER_FLAG_STRING(sync_command, "Execute an external command "
"\"<sync_command> <test_corpus>\" "
"to synchronize the test corpus.")
FUZZER_FLAG_INT(sync_timeout, 600, "Minimum timeout between syncs.")
FUZZER_FLAG_INT(report_slow_units, 10,
"Report slowest units if they run for more than this number of seconds.")

View File

@ -79,6 +79,7 @@ class Fuzzer {
int PreferSmallDuringInitialShuffle = -1;
size_t MaxNumberOfRuns = ULONG_MAX;
int SyncTimeout = 600;
int ReportSlowUnits = 10;
std::string OutputCorpus;
std::string SyncCommand;
std::vector<std::string> Tokens;

View File

@ -159,12 +159,13 @@ size_t Fuzzer::RunOne(const Unit &U) {
auto UnitStopTime = system_clock::now();
auto TimeOfUnit =
duration_cast<seconds>(UnitStopTime - UnitStartTime).count();
if (TimeOfUnit > TimeOfLongestUnitInSeconds) {
if (TimeOfUnit > TimeOfLongestUnitInSeconds &&
TimeOfUnit >= Options.ReportSlowUnits) {
TimeOfLongestUnitInSeconds = TimeOfUnit;
Printf("Longest unit: %zd s:\n", TimeOfLongestUnitInSeconds);
Printf("Slowest unit: %zd s:\n", TimeOfLongestUnitInSeconds);
if (U.size() <= kMaxUnitSizeToPrint)
Print(U, "\n");
WriteUnitToFileWithPrefix(U, "long-running-unit-");
WriteUnitToFileWithPrefix(U, "slow-unit-");
}
return Res;
}