about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAmit Elkabetz <12958411+amitelka@users.noreply.github.com>2023-03-05 18:16:21 +0200
committerAmit Elkabetz <12958411+amitelka@users.noreply.github.com>2023-03-05 18:16:21 +0200
commit07cf27cddc6f0189ee9b21f888595c84549b5b93 (patch)
treed0bebabef7a714f54295610448fc4637f2f408dd
parent2ff0ff7a903c57f9df5ed1e97370c187ec45a31e (diff)
downloadafl++-07cf27cddc6f0189ee9b21f888595c84549b5b93.tar.gz
Added flag -u to allow custom interval to update fuzzer_stats file
-rw-r--r--include/afl-fuzz.h1
-rw-r--r--src/afl-fuzz-state.c1
-rw-r--r--src/afl-fuzz-stats.c2
-rw-r--r--src/afl-fuzz.c17
4 files changed, 17 insertions, 4 deletions
diff --git a/include/afl-fuzz.h b/include/afl-fuzz.h
index 9bf91faf..62d71968 100644
--- a/include/afl-fuzz.h
+++ b/include/afl-fuzz.h
@@ -693,6 +693,7 @@ typedef struct afl_state {
 
   /* statistics file */
   double last_bitmap_cvg, last_stability, last_eps;
+  u64 stats_file_update_freq_msecs;     /* Stats update frequency (msecs)   */
 
   /* plot file saves from last run */
   u32 plot_prev_qp, plot_prev_pf, plot_prev_pnf, plot_prev_ce, plot_prev_md;
diff --git a/src/afl-fuzz-state.c b/src/afl-fuzz-state.c
index 6d8c8758..e319c512 100644
--- a/src/afl-fuzz-state.c
+++ b/src/afl-fuzz-state.c
@@ -100,6 +100,7 @@ void afl_state_init(afl_state_t *afl, uint32_t map_size) {
   afl->hang_tmout = EXEC_TIMEOUT;
   afl->exit_on_time = 0;
   afl->stats_update_freq = 1;
+  afl->stats_file_update_freq_msecs = STATS_UPDATE_SEC * 1000;
   afl->stats_avg_exec = 0;
   afl->skip_deterministic = 1;
   afl->sync_time = SYNC_TIME;
diff --git a/src/afl-fuzz-stats.c b/src/afl-fuzz-stats.c
index bfd30845..0e36227f 100644
--- a/src/afl-fuzz-stats.c
+++ b/src/afl-fuzz-stats.c
@@ -613,7 +613,7 @@ void show_stats_normal(afl_state_t *afl) {
 
   if (unlikely(!afl->non_instrumented_mode &&
                (afl->force_ui_update ||
-                cur_ms - afl->stats_last_stats_ms > STATS_UPDATE_SEC * 1000))) {
+                cur_ms - afl->stats_last_stats_ms > afl->stats_file_update_freq_msecs))) {
 
     afl->stats_last_stats_ms = cur_ms;
     write_stats_file(afl, t_bytes, t_byte_ratio, stab_ratio,
diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c
index 4914ce0b..efbab289 100644
--- a/src/afl-fuzz.c
+++ b/src/afl-fuzz.c
@@ -210,7 +210,10 @@ static void usage(u8 *argv0, int more_help) {
       "  -b cpu_id     - bind the fuzzing process to the specified CPU core "
       "(0-...)\n"
       "  -e ext        - file extension for the fuzz test input file (if "
-      "needed)\n\n",
+      "needed)\n"
+      "  -u            - interval to update fuzzer_stats file in seconds, "
+      "defaults to 60 sec\n"
+      "\n",
       argv0, EXEC_TIMEOUT, MEM_LIMIT, MAX_FILE, FOREIGN_SYNCS_MAX);
 
   if (more_help > 1) {
@@ -501,7 +504,7 @@ fail:
 int main(int argc, char **argv_orig, char **envp) {
 
   s32 opt, auto_sync = 0 /*, user_set_cache = 0*/;
-  u64 prev_queued = 0;
+  u64 prev_queued = 0, stats_update_freq_sec = 0;
   u32 sync_interval_cnt = 0, seek_to = 0, show_help = 0, default_output = 1,
       map_size = get_map_size();
   u8 *extras_dir[4];
@@ -553,7 +556,7 @@ int main(int argc, char **argv_orig, char **envp) {
   while (
       (opt = getopt(
            argc, argv,
-           "+Ab:B:c:CdDe:E:hi:I:f:F:g:G:l:L:m:M:nNOo:p:RQs:S:t:T:UV:WXx:YZ")) >
+           "+Ab:B:c:CdDe:E:hi:I:f:F:g:G:l:L:m:M:nNOo:p:RQs:S:t:T:u:UV:WXx:YZ")) >
       0) {
 
     switch (opt) {
@@ -665,6 +668,14 @@ int main(int argc, char **argv_orig, char **envp) {
 
         break;
 
+      case 'u':
+        if (sscanf(optarg, "%llu", &stats_update_freq_sec) < 1) {
+          FATAL("Bad syntax used for -u");
+        }
+
+        afl->stats_file_update_freq_msecs = stats_update_freq_sec * 1000;
+        break;
+
       case 'i':                                                /* input dir */
 
         if (afl->in_dir) { FATAL("Multiple -i options not supported"); }