[llvm] r262084 - [libFuzzer] add -print_final_stats=1 flag
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 26 14:42:23 PST 2016
Author: kcc
Date: Fri Feb 26 16:42:23 2016
New Revision: 262084
URL: http://llvm.org/viewvc/llvm-project?rev=262084&view=rev
Log:
[libFuzzer] add -print_final_stats=1 flag
Modified:
llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp
llvm/trunk/lib/Fuzzer/FuzzerFlags.def
llvm/trunk/lib/Fuzzer/FuzzerInternal.h
llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
llvm/trunk/lib/Fuzzer/FuzzerUtil.cpp
llvm/trunk/lib/Fuzzer/test/fuzzer.test
Modified: llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp?rev=262084&r1=262083&r2=262084&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp Fri Feb 26 16:42:23 2016
@@ -301,6 +301,7 @@ static int FuzzerDriver(const std::vecto
Printf("Dictionary: %zd entries\n", Dictionary.size());
Options.SaveArtifacts = !Flags.test_single_input;
Options.PrintNewCovPcs = Flags.print_new_cov_pcs;
+ Options.PrintFinalStats = Flags.print_final_stats;
unsigned Seed = Flags.seed;
// Initialize Seed.
@@ -369,6 +370,7 @@ static int FuzzerDriver(const std::vecto
if (Flags.verbosity)
Printf("Done %d runs in %zd second(s)\n", F.getTotalNumberOfRuns(),
F.secondsSinceProcessStartUp());
+ F.PrintFinalStats();
exit(0); // Don't let F destroy itself.
}
Modified: llvm/trunk/lib/Fuzzer/FuzzerFlags.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerFlags.def?rev=262084&r1=262083&r2=262084&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerFlags.def (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerFlags.def Fri Feb 26 16:42:23 2016
@@ -74,4 +74,5 @@ FUZZER_FLAG_INT(drill, 0, "Experimental:
"corpus, then merge with the initial corpus")
FUZZER_FLAG_INT(output_csv, 0, "Enable pulse output in CSV format.")
FUZZER_FLAG_INT(print_new_cov_pcs, 0, "If 1, print out new covered pcs.")
+FUZZER_FLAG_INT(print_final_stats, 0, "If 1, print statistics at exit.")
Modified: llvm/trunk/lib/Fuzzer/FuzzerInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerInternal.h?rev=262084&r1=262083&r2=262084&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerInternal.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerInternal.h Fri Feb 26 16:42:23 2016
@@ -85,6 +85,7 @@ std::string Hash(const Unit &U);
void SetTimer(int Seconds);
std::string Base64(const Unit &U);
int ExecuteCommand(const std::string &Command);
+size_t GetPeakRSSMb();
// Private copy of SHA1 implementation.
static const int kSHA1NumBytes = 20;
@@ -295,6 +296,7 @@ public:
bool PrintNEW = true; // Print a status line when new units are found;
bool OutputCSV = false;
bool PrintNewCovPcs = false;
+ bool PrintFinalStats = false;
};
Fuzzer(UserCallback CB, MutationDispatcher &MD, FuzzingOptions Options);
void AddToCorpus(const Unit &U) {
@@ -321,6 +323,10 @@ public:
return duration_cast<seconds>(system_clock::now() - ProcessStartTime)
.count();
}
+ size_t execPerSec() {
+ size_t Seconds = secondsSinceProcessStartUp();
+ return Seconds ? TotalNumberOfRuns / Seconds : 0;
+ }
size_t getTotalNumberOfRuns() { return TotalNumberOfRuns; }
@@ -331,6 +337,7 @@ public:
// Merge Corpora[1:] into Corpora[0].
void Merge(const std::vector<std::string> &Corpora);
MutationDispatcher &GetMD() { return MD; }
+ void PrintFinalStats();
private:
void AlarmCallback();
@@ -372,6 +379,7 @@ private:
size_t TotalNumberOfRuns = 0;
size_t TotalNumberOfExecutedTraceBasedMutations = 0;
+ size_t NumberOfNewUnitsAdded = 0;
std::vector<Unit> Corpus;
std::unordered_set<std::string> UnitHashesAddedToCorpus;
Modified: llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp?rev=262084&r1=262083&r2=262084&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp Fri Feb 26 16:42:23 2016
@@ -92,6 +92,7 @@ void Fuzzer::DeathCallback() {
}
WriteUnitToFileWithPrefix(
{CurrentUnitData, CurrentUnitData + CurrentUnitSize}, "crash-");
+ PrintFinalStats();
}
void Fuzzer::StaticAlarmCallback() {
@@ -124,6 +125,7 @@ void Fuzzer::AlarmCallback() {
if (__sanitizer_print_stack_trace)
__sanitizer_print_stack_trace();
Printf("SUMMARY: libFuzzer: timeout\n");
+ PrintFinalStats();
if (Options.AbortOnTimeout)
abort();
exit(Options.TimeoutExitCode);
@@ -131,9 +133,7 @@ void Fuzzer::AlarmCallback() {
}
void Fuzzer::PrintStats(const char *Where, const char *End) {
- size_t Seconds = secondsSinceProcessStartUp();
- size_t ExecPerSec = (Seconds ? TotalNumberOfRuns / Seconds : 0);
-
+ size_t ExecPerSec = execPerSec();
if (Options.OutputCSV) {
static bool csvHeaderPrinted = false;
if (!csvHeaderPrinted) {
@@ -163,6 +163,16 @@ void Fuzzer::PrintStats(const char *Wher
Printf("%s", End);
}
+void Fuzzer::PrintFinalStats() {
+ if (!Options.PrintFinalStats) return;
+ size_t ExecPerSec = execPerSec();
+ Printf("stat::number_of_executed_units: %zd\n", TotalNumberOfRuns);
+ Printf("stat::average_exec_per_sec: %zd\n", ExecPerSec);
+ Printf("stat::new_units_added: %zd\n", NumberOfNewUnitsAdded);
+ Printf("stat::slowest_unit_time_sec: %zd\n", TimeOfLongestUnitInSeconds);
+ Printf("stat::peak_rss_mb: %zd\n", GetPeakRSSMb());
+}
+
void Fuzzer::RereadOutputCorpus() {
if (Options.OutputCorpus.empty())
return;
@@ -382,6 +392,7 @@ void Fuzzer::ReportNewCoverage(const Uni
MD.RecordSuccessfulMutationSequence();
PrintStatusForNewUnit(U);
WriteToOutputCorpus(U);
+ NumberOfNewUnitsAdded++;
if (Options.ExitOnFirst)
exit(0);
}
Modified: llvm/trunk/lib/Fuzzer/FuzzerUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerUtil.cpp?rev=262084&r1=262083&r2=262084&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerUtil.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerUtil.cpp Fri Feb 26 16:42:23 2016
@@ -12,6 +12,7 @@
#include "FuzzerInternal.h"
#include <sstream>
#include <iomanip>
+#include <sys/resource.h>
#include <sys/time.h>
#include <cassert>
#include <cstring>
@@ -217,4 +218,11 @@ std::string Base64(const Unit &U) {
return Res;
}
+size_t GetPeakRSSMb() {
+ struct rusage usage;
+ if (getrusage(RUSAGE_SELF, &usage))
+ return 0;
+ return usage.ru_maxrss >> 10;
+}
+
} // namespace fuzzer
Modified: llvm/trunk/lib/Fuzzer/test/fuzzer.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/fuzzer.test?rev=262084&r1=262083&r2=262084&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/fuzzer.test (original)
+++ llvm/trunk/lib/Fuzzer/test/fuzzer.test Fri Feb 26 16:42:23 2016
@@ -69,3 +69,11 @@ RUN: rm %t/NthRunCrashTest.in
RUN: not LLVMFuzzer-CustomMutatorTest 2>&1 | FileCheck %s --check-prefix=LLVMFuzzerCustomMutator
LLVMFuzzerCustomMutator: In LLVMFuzzerCustomMutator
LLVMFuzzerCustomMutator: BINGO
+
+RUN: LLVMFuzzer-SimpleTest -seed=1 -runs=77 -print_final_stats=1 2>&1 | FileCheck %s --check-prefix=FINAL_STATS
+FINAL_STATS: stat::number_of_executed_units: 77
+FINAL_STATS: stat::average_exec_per_sec: 0
+FINAL_STATS: stat::new_units_added:
+FINAL_STATS: stat::slowest_unit_time_sec: 0
+FINAL_STATS: stat::peak_rss_mb:
+
More information about the llvm-commits
mailing list