[libFuzzer] add option -report_slow_units=Nsec to control when slow units are printed
authorKostya Serebryany <kcc@google.com>
Wed, 5 Aug 2015 21:43:48 +0000 (21:43 +0000)
committerKostya Serebryany <kcc@google.com>
Wed, 5 Aug 2015 21:43:48 +0000 (21:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244152 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/FuzzerDriver.cpp
lib/Fuzzer/FuzzerFlags.def
lib/Fuzzer/FuzzerInternal.h
lib/Fuzzer/FuzzerLoop.cpp

index c0f8220ad655da99676b6a237aaca763ce9b7b0c..7f3ec7ba2ed1ee5567742e08e6cb669c90397745 100644 (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;
   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)
   Fuzzer F(USF, Options);
 
   if (Flags.apply_tokens)
index 742f672e2012f25e2f11a2a4ecee7aa6587923ff..ac3ac6ef3f8f404f23eddd17142153bd58d17ba9 100644 (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.")
                                  "\"<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.")
index cc86c361460aa2b127504107f18bee74bc3dda8c..610b4375f24266f6a3d0ec62caca6b8386ff676b 100644 (file)
@@ -79,6 +79,7 @@ class Fuzzer {
     int PreferSmallDuringInitialShuffle = -1;
     size_t MaxNumberOfRuns = ULONG_MAX;
     int SyncTimeout = 600;
     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;
     std::string OutputCorpus;
     std::string SyncCommand;
     std::vector<std::string> Tokens;
index 5e8e2e4aae34a12c4fe34a91c9d5be0361a6ebdf..69b49b025a032794a2e52fd2d93c44e0ccbf1979 100644 (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();
   auto UnitStopTime = system_clock::now();
   auto TimeOfUnit =
       duration_cast<seconds>(UnitStopTime - UnitStartTime).count();
-  if (TimeOfUnit > TimeOfLongestUnitInSeconds) {
+  if (TimeOfUnit > TimeOfLongestUnitInSeconds &&
+      TimeOfUnit >= Options.ReportSlowUnits) {
     TimeOfLongestUnitInSeconds = TimeOfUnit;
     TimeOfLongestUnitInSeconds = TimeOfUnit;
-    Printf("Longest unit: %zd s:\n", TimeOfLongestUnitInSeconds);
+    Printf("Slowest unit: %zd s:\n", TimeOfLongestUnitInSeconds);
     if (U.size() <= kMaxUnitSizeToPrint)
       Print(U, "\n");
     if (U.size() <= kMaxUnitSizeToPrint)
       Print(U, "\n");
-    WriteUnitToFileWithPrefix(U, "long-running-unit-");
+    WriteUnitToFileWithPrefix(U, "slow-unit-");
   }
   return Res;
 }
   }
   return Res;
 }