Optionally collect fuzzer statistics across runs - #9073
Conversation
When a new BINARYEN_FUZZ_STATS environment variable is set, collect statistics about fuzzer patterns and events. Save these statistics to a file, where they can be accumulated and updated across several fuzzer runs. The API is designed to make it easy to add new patterns and events for one-off local experiments. Include sample patterns collecting frequencies of various cast instructions as an example.
4816e63 to
fcdfa85
Compare
| @@ -0,0 +1,323 @@ | |||
| /* | |||
| * Copyright 2024 WebAssembly Community Group participants | |||
There was a problem hiding this comment.
| * Copyright 2024 WebAssembly Community Group participants | |
| * Copyright 2026 WebAssembly Community Group participants |
| namespace { | ||
|
|
||
| struct FuzzStatsVisitor : public FuzzStats::Visitor<FuzzStatsVisitor> { | ||
| void visitBrOn(BrOn* curr) { |
There was a problem hiding this comment.
Please comment as to why we collect these and not others.
| #define RECORD_EVENT(name, outcome) \ | ||
| ::wasm::FuzzStats::recordEvent((name), __FILE__, __LINE__, (outcome)) | ||
|
|
||
| #define RECORD_FUZZ_EVENT(name, outcome) RECORD_EVENT(name, outcome) |
There was a problem hiding this comment.
No one in the PR. I could add an example usage like we have for the patterns.
There was a problem hiding this comment.
Let me know if this is something you would want to see.
| const std::map<std::string, uint64_t>& funcMatches); | ||
|
|
||
| // CRTP base class for visitors that collect fuzzing pattern statistics. | ||
| template<typename SubType> struct Visitor : public PostWalker<SubType> { |
There was a problem hiding this comment.
The name Visitor is maybe confusing. Walker is contrasted against Visitor in wasm-traversal.h (one visits one node, the other walks all the nodes)
kripken
left a comment
There was a problem hiding this comment.
Can we add some kind of test for these stats themselves?
|
|
||
| namespace { | ||
|
|
||
| struct FileLock { |
There was a problem hiding this comment.
Let's put this under support/ as a general file utility?
| #define RECORD_EVENT(name, outcome) \ | ||
| ::wasm::FuzzStats::recordEvent((name), __FILE__, __LINE__, (outcome)) | ||
|
|
||
| #define RECORD_FUZZ_EVENT(name, outcome) RECORD_EVENT(name, outcome) |
|
Moved FileLock to src/support and added tests. |
When a new BINARYEN_FUZZ_STATS environment variable is set, collect statistics about fuzzer patterns and events. Save these statistics to a file, where they can be accumulated and updated across several fuzzer runs. The API is designed to make it easy to add new patterns and events for one-off local experiments. Include sample patterns collecting frequencies of various cast instructions as an example.