From 71414244472d8b14a0dd3b07a4b71fa449b13189 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Wed, 5 Aug 2015 21:43:48 +0000 Subject: [PATCH] [libFuzzer] add option -report_slow_units=Nsec to control when slow units are printed git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244152 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Fuzzer/FuzzerDriver.cpp | 1 + lib/Fuzzer/FuzzerFlags.def | 2 ++ lib/Fuzzer/FuzzerInternal.h | 1 + lib/Fuzzer/FuzzerLoop.cpp | 7 ++++--- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Fuzzer/FuzzerDriver.cpp b/lib/Fuzzer/FuzzerDriver.cpp index c0f8220ad65..7f3ec7ba2ed 100644 --- a/lib/Fuzzer/FuzzerDriver.cpp +++ b/lib/Fuzzer/FuzzerDriver.cpp @@ -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) diff --git a/lib/Fuzzer/FuzzerFlags.def b/lib/Fuzzer/FuzzerFlags.def index 742f672e201..ac3ac6ef3f8 100644 --- a/lib/Fuzzer/FuzzerFlags.def +++ b/lib/Fuzzer/FuzzerFlags.def @@ -58,3 +58,5 @@ FUZZER_FLAG_STRING(sync_command, "Execute an external command " "\" \" " "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.") diff --git a/lib/Fuzzer/FuzzerInternal.h b/lib/Fuzzer/FuzzerInternal.h index cc86c361460..610b4375f24 100644 --- a/lib/Fuzzer/FuzzerInternal.h +++ b/lib/Fuzzer/FuzzerInternal.h @@ -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 Tokens; diff --git a/lib/Fuzzer/FuzzerLoop.cpp b/lib/Fuzzer/FuzzerLoop.cpp index 5e8e2e4aae3..69b49b025a0 100644 --- a/lib/Fuzzer/FuzzerLoop.cpp +++ b/lib/Fuzzer/FuzzerLoop.cpp @@ -159,12 +159,13 @@ size_t Fuzzer::RunOne(const Unit &U) { auto UnitStopTime = system_clock::now(); auto TimeOfUnit = duration_cast(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; } -- 2.34.1