Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
[libFuzzer] print how much memory is consumed by the outer merge proc…
Browse files Browse the repository at this point in the history
…ess (google/oss-fuzz#445)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297546 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
kcc committed Mar 11, 2017
1 parent e1e162e commit 3210496
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion lib/Fuzzer/FuzzerMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <fstream>
#include <iterator>
#include <set>
#include <sstream>

namespace fuzzer {
Expand Down Expand Up @@ -88,7 +89,7 @@ bool Merger::Parse(std::istream &IS, bool ParseCoverage) {
assert(ExpectedStartMarker < Files.size());
ExpectedStartMarker++;
} else if (Marker == "DONE") {
// DONE FILE_SIZE COV1 COV2 COV3 ...
// DONE FILE_ID COV1 COV2 COV3 ...
size_t CurrentFileIdx = N;
if (CurrentFileIdx != LastSeenStartMarker)
return false;
Expand All @@ -111,6 +112,13 @@ bool Merger::Parse(std::istream &IS, bool ParseCoverage) {
return true;
}

size_t Merger::ApproximateMemoryConsumption() const {
size_t Res = 0;
for (const auto &F: Files)
Res += sizeof(F) + F.Features.size() * sizeof(F.Features[0]);
return Res;
}

// Decides which files need to be merged (add thost to NewFiles).
// Returns the number of new features added.
size_t Merger::Merge(std::vector<std::string> *NewFiles) {
Expand Down Expand Up @@ -262,6 +270,8 @@ void Fuzzer::CrashResistantMerge(const std::vector<std::string> &Args,
IF.seekg(0, IF.beg);
M.ParseOrExit(IF, true);
IF.close();
Printf("MERGE-OUTER: consumed %zd bytes to parse the control file\n",
M.ApproximateMemoryConsumption());
std::vector<std::string> NewFiles;
size_t NumNewFeatures = M.Merge(&NewFiles);
Printf("MERGE-OUTER: %zd new files with %zd new features added\n",
Expand Down
2 changes: 1 addition & 1 deletion lib/Fuzzer/FuzzerMerge.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include "FuzzerDefs.h"

#include <istream>
#include <set>

namespace fuzzer {

Expand All @@ -63,6 +62,7 @@ struct Merger {
bool Parse(const std::string &Str, bool ParseCoverage);
void ParseOrExit(std::istream &IS, bool ParseCoverage);
size_t Merge(std::vector<std::string> *NewFiles);
size_t ApproximateMemoryConsumption() const;
};

} // namespace fuzzer
Expand Down

0 comments on commit 3210496

Please sign in to comment.