[fuzzer] print various stats in a unified way

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233624 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Kostya Serebryany 2015-03-30 22:44:03 +00:00
parent 5ca9ec70fd
commit b0b7c53ee4
2 changed files with 25 additions and 21 deletions

View File

@ -90,6 +90,7 @@ class Fuzzer {
void WriteToOutputCorpus(const Unit &U); void WriteToOutputCorpus(const Unit &U);
static void WriteToCrash(const Unit &U, const char *Prefix); static void WriteToCrash(const Unit &U, const char *Prefix);
bool MutateWithDFSan(Unit *U); bool MutateWithDFSan(Unit *U);
void PrintStats(const char *Where, size_t Cov, const char *End = "\n");
void SetDeathCallback(); void SetDeathCallback();
static void DeathCallback(); static void DeathCallback();

View File

@ -44,21 +44,34 @@ void Fuzzer::AlarmCallback() {
exit(1); exit(1);
} }
void Fuzzer::PrintStats(const char *Where, size_t Cov, const char *End) {
if (!Options.Verbosity) return;
size_t Seconds = secondsSinceProcessStartUp();
size_t ExecPerSec = (Seconds ? TotalNumberOfRuns / Seconds : 0);
std::cerr
<< "#" << TotalNumberOfRuns
<< "\t" << Where
<< " cov " << Cov
<< " bits " << TotalBits()
<< " units " << Corpus.size()
<< " exec/s " << ExecPerSec
<< End;
}
void Fuzzer::ShuffleAndMinimize() { void Fuzzer::ShuffleAndMinimize() {
size_t MaxCov = 0;
bool PreferSmall = bool PreferSmall =
(Options.PreferSmallDuringInitialShuffle == 1 || (Options.PreferSmallDuringInitialShuffle == 1 ||
(Options.PreferSmallDuringInitialShuffle == -1 && rand() % 2)); (Options.PreferSmallDuringInitialShuffle == -1 && rand() % 2));
if (Options.Verbosity) if (Options.Verbosity)
std::cerr << "Shuffle: Size: " << Corpus.size() std::cerr << "PreferSmall: " << PreferSmall << "\n";
<< " prefer small: " << PreferSmall PrintStats("READ ", 0);
<< "\n";
std::vector<Unit> NewCorpus; std::vector<Unit> NewCorpus;
std::random_shuffle(Corpus.begin(), Corpus.end()); std::random_shuffle(Corpus.begin(), Corpus.end());
if (PreferSmall) if (PreferSmall)
std::stable_sort( std::stable_sort(
Corpus.begin(), Corpus.end(), Corpus.begin(), Corpus.end(),
[](const Unit &A, const Unit &B) { return A.size() < B.size(); }); [](const Unit &A, const Unit &B) { return A.size() < B.size(); });
size_t MaxCov = 0;
Unit &U = CurrentUnit; Unit &U = CurrentUnit;
for (const auto &C : Corpus) { for (const auto &C : Corpus) {
for (size_t First = 0; First < 1; First++) { for (size_t First = 0; First < 1; First++) {
@ -77,8 +90,7 @@ void Fuzzer::ShuffleAndMinimize() {
} }
} }
Corpus = NewCorpus; Corpus = NewCorpus;
if (Options.Verbosity) PrintStats("INITED", MaxCov);
std::cerr << "Shuffle done: " << Corpus.size() << " IC: " << MaxCov << "\n";
} }
size_t Fuzzer::RunOne(const Unit &U) { size_t Fuzzer::RunOne(const Unit &U) {
@ -151,14 +163,9 @@ size_t Fuzzer::RunOneMaximizeTotalCoverage(const Unit &U) {
NumNewBits = __sanitizer_update_counter_bitset_and_clear_counters( NumNewBits = __sanitizer_update_counter_bitset_and_clear_counters(
CounterBitmap.data()); CounterBitmap.data());
if (!(TotalNumberOfRuns & (TotalNumberOfRuns - 1)) && Options.Verbosity) { if (!(TotalNumberOfRuns & (TotalNumberOfRuns - 1)) && Options.Verbosity)
size_t Seconds = secondsSinceProcessStartUp(); PrintStats("pulse ", NewCoverage);
std::cerr
<< "#" << TotalNumberOfRuns
<< "\tcov: " << NewCoverage
<< "\tbits: " << TotalBits()
<< "\texec/s: " << (Seconds ? TotalNumberOfRuns / Seconds : 0) << "\n";
}
if (NewCoverage > OldCoverage || NumNewBits) if (NewCoverage > OldCoverage || NumNewBits)
return NewCoverage; return NewCoverage;
return 0; return 0;
@ -198,15 +205,11 @@ size_t Fuzzer::MutateAndTestOne(Unit *U) {
if (NewCoverage) { if (NewCoverage) {
Corpus.push_back(*U); Corpus.push_back(*U);
NewUnits++; NewUnits++;
PrintStats("NEW ", NewCoverage, "");
if (Options.Verbosity) { if (Options.Verbosity) {
std::cerr << "#" << TotalNumberOfRuns std::cerr << " L: " << U->size();
<< "\tNEW: " << NewCoverage
<< " B: " << TotalBits()
<< " L: " << U->size()
<< " S: " << Corpus.size()
<< " I: " << i
<< "\t";
if (U->size() < 30) { if (U->size() < 30) {
std::cerr << " ";
PrintASCII(*U); PrintASCII(*U);
std::cerr << "\t"; std::cerr << "\t";
Print(*U); Print(*U);