16
16
#include " FuzzerUtil.h"
17
17
18
18
#include < atomic>
19
+ #include < fstream>
19
20
#include < mutex>
20
- #include < thread>
21
21
#include < queue>
22
+ #include < sstream>
23
+ #include < thread>
22
24
23
25
namespace fuzzer {
24
26
27
+ struct Stats {
28
+ size_t number_of_executed_units = 0 ;
29
+ size_t peak_rss_mb = 0 ;
30
+ size_t average_exec_per_sec = 0 ;
31
+ };
32
+
33
+ static Stats ParseFinalStatsFromLog (const std::string &LogPath) {
34
+ std::ifstream In (LogPath);
35
+ std::string Line;
36
+ Stats Res;
37
+ struct {
38
+ const char *Name;
39
+ size_t *Var;
40
+ } NameVarPairs[] = {
41
+ {" stat::number_of_executed_units:" , &Res.number_of_executed_units },
42
+ {" stat::peak_rss_mb:" , &Res.peak_rss_mb },
43
+ {" stat::average_exec_per_sec:" , &Res.average_exec_per_sec },
44
+ {nullptr , nullptr },
45
+ };
46
+ while (std::getline (In, Line, ' \n ' )) {
47
+ if (Line.find (" stat::" ) != 0 ) continue ;
48
+ std::istringstream ISS (Line);
49
+ std::string Name;
50
+ size_t Val;
51
+ ISS >> Name >> Val;
52
+ for (size_t i = 0 ; NameVarPairs[i].Name ; i++)
53
+ if (Name == NameVarPairs[i].Name )
54
+ *NameVarPairs[i].Var = Val;
55
+ }
56
+ return Res;
57
+ }
58
+
25
59
struct FuzzJob {
26
60
// Inputs.
27
61
Command Cmd;
@@ -43,12 +77,15 @@ struct GlobalEnv {
43
77
Random *Rand;
44
78
int Verbosity = 0 ;
45
79
80
+ size_t NumRuns = 0 ;
81
+
46
82
FuzzJob *CreateNewJob (size_t JobId) {
47
83
Command Cmd (Args);
48
84
Cmd.removeFlag (" fork" );
49
85
for (auto &C : CorpusDirs) // Remove all corpora from the args.
50
86
Cmd.removeArgument (C);
51
87
Cmd.addFlag (" reload" , " 0" ); // working in an isolated dir, no reload.
88
+ Cmd.addFlag (" print_final_stats" , " 1" );
52
89
Cmd.addFlag (" max_total_time" , std::to_string (std::min ((size_t )300 , JobId)));
53
90
54
91
auto Job = new FuzzJob;
@@ -95,12 +132,14 @@ struct GlobalEnv {
95
132
WriteToFile (U, NewPath);
96
133
Files.push_back (NewPath);
97
134
}
98
- Printf (" Removing %s\n " , Job->CorpusDir .c_str ());
99
135
RmDirRecursive (Job->CorpusDir );
100
136
Features.insert (NewFeatures.begin (), NewFeatures.end ());
101
- Printf (" INFO: temp_files: %zd files_added: %zd newft: %zd ft: %zd\n " ,
102
- TempFiles.size (), FilesToAdd.size (), NewFeatures.size (),
103
- Features.size ());
137
+ auto Stats = ParseFinalStatsFromLog (Job->LogPath );
138
+ NumRuns += Stats.number_of_executed_units ;
139
+ if (!FilesToAdd.empty ())
140
+ Printf (" #%zd: ft: %zd corp: %zd exec/s %zd\n " , NumRuns,
141
+ Features.size (), Files.size (),
142
+ Stats.average_exec_per_sec );
104
143
}
105
144
};
106
145
0 commit comments