Skip to content

Commit

Permalink
Merge branch 'stats_stage' of https://github.com/AFLplusplus/LibAFL
Browse files Browse the repository at this point in the history
  • Loading branch information
toseven authored and toseven committed Jul 16, 2023
2 parents 686529b + 7211c5e commit 29b1122
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libafl/src/stages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub use power::{PowerMutationalStage, StdPowerMutationalStage};
pub mod generalization;
pub use generalization::GeneralizationStage;

pub mod stats;
pub use stats::AFLStatsStage;

pub mod owned;
pub use owned::StagesOwnedList;

Expand Down
56 changes: 56 additions & 0 deletions libafl/src/stages/stats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! Stage to compute/report AFL stats

use core::{marker::PhantomData, time::Duration};

use crate::{
corpus::CorpusId,
stages::Stage,
state::UsesState,
Error,
};

const STATS_REPORT_INTERVAL: Duration = Duration::from_secs(15); // change this as you want.

pub struct AFLStatsStage<E, EM, Z>
where
E: UsesState,
EM: UsesState<State = E::State>,
Z: UsesState<State = E::State>,
{
pending: usize,
pending_favored: usize,
imported: usize,
own_finds: usize,
phantom: PhantomData<(E, EM, Z)>,
}


impl<E, EM, Z> UsesState for AFLStatsStage<E, EM, Z>
where
E: UsesState,
EM: UsesState<State = E::State>,
Z: UsesState<State = E::State>,
{
type State = E::State;
}

impl<E, EM, Z> Stage<E, EM, Z> for AFLStatsStage<E, EM, Z>
where
E: UsesState,
EM: UsesState<State = E::State>,
Z: UsesState<State = E::State>,
{
fn perform(
&mut self,
fuzzer: &mut Z,
executor: &mut E,
state: &mut E::State,
manager: &mut EM,
corpus_idx: CorpusId,
) -> Result<(), Error> {
// Report your stats every `STATS_REPORT_INTERVAL`
// compute pending, pending_favored, imported, own_finds

Ok(())
}
}

0 comments on commit 29b1122

Please sign in to comment.