fix a bit exec sec in stats

This commit is contained in:
Andrea Fioraldi 2021-02-12 10:50:06 +01:00
parent 27cc1d8af6
commit 177135d330
6 changed files with 41 additions and 29 deletions

View File

@ -101,13 +101,17 @@ where
corpus_size: usize, corpus_size: usize,
/// The client config for this observers/testcase combination /// The client config for this observers/testcase combination
client_config: String, client_config: String,
/// The time of generation of the event
time: Duration,
/// The executions of this client
executions: usize,
}, },
/// New stats. /// New stats.
UpdateStats { UpdateStats {
/// The time of generation of the event
time: Duration,
/// The executions of this client /// The executions of this client
executions: usize, executions: usize,
/// The execs per sec for this client
execs_over_sec: u64,
phantom: PhantomData<I>, phantom: PhantomData<I>,
}, },
/// A crash was found /// A crash was found
@ -146,10 +150,12 @@ where
client_config: _, client_config: _,
corpus_size: _, corpus_size: _,
observers_buf: _, observers_buf: _,
time: _,
executions: _,
} => "New Testcase", } => "New Testcase",
Event::UpdateStats { Event::UpdateStats {
time: _,
executions: _, executions: _,
execs_over_sec: _,
phantom: _, phantom: _,
} => "Stats", } => "Stats",
Event::Crash { input: _ } => "Crash", Event::Crash { input: _ } => "Crash",
@ -332,18 +338,21 @@ where
client_config: _, client_config: _,
corpus_size, corpus_size,
observers_buf: _, observers_buf: _,
time,
executions,
} => { } => {
stats.client_stats_mut()[0].corpus_size = *corpus_size as u64; stats.client_stats_mut()[0].update_corpus_size(*corpus_size as u64);
stats.client_stats_mut()[0].update_executions(*executions as u64, *time);
stats.display(event.name().to_string()); stats.display(event.name().to_string());
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
} }
Event::UpdateStats { Event::UpdateStats {
time,
executions, executions,
execs_over_sec: _,
phantom: _, phantom: _,
} => { } => {
// TODO: The stats buffer should be added on client add. // TODO: The stats buffer should be added on client add.
stats.client_stats_mut()[0].executions = *executions as u64; stats.client_stats_mut()[0].update_executions(*executions as u64, *time);
stats.display(event.name().to_string()); stats.display(event.name().to_string());
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
} }
@ -568,20 +577,23 @@ where
client_config: _, client_config: _,
corpus_size, corpus_size,
observers_buf: _, observers_buf: _,
time,
executions
} => { } => {
let client = stats.client_stats_mut_for(sender_id); let client = stats.client_stats_mut_for(sender_id);
client.corpus_size = *corpus_size as u64; client.update_corpus_size(*corpus_size as u64);
client.update_executions(*executions as u64, *time);
stats.display(event.name().to_string() + " #" + &sender_id.to_string()); stats.display(event.name().to_string() + " #" + &sender_id.to_string());
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
} }
Event::UpdateStats { Event::UpdateStats {
time,
executions, executions,
execs_over_sec: _,
phantom: _, phantom: _,
} => { } => {
// TODO: The stats buffer should be added on client add. // TODO: The stats buffer should be added on client add.
let client = stats.client_stats_mut_for(sender_id); let client = stats.client_stats_mut_for(sender_id);
client.executions = *executions as u64; client.update_executions(*executions as u64, *time);
stats.display(event.name().to_string() + " #" + &sender_id.to_string()); stats.display(event.name().to_string() + " #" + &sender_id.to_string());
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
} }
@ -626,6 +638,8 @@ where
client_config: _, client_config: _,
corpus_size: _, corpus_size: _,
observers_buf, observers_buf,
time: _,
executions: _
} => { } => {
// TODO: here u should match client_config, if equal to the current one do not re-execute // TODO: here u should match client_config, if equal to the current one do not re-execute
// we need to pass engine to process() too, TODO // we need to pass engine to process() too, TODO
@ -946,6 +960,7 @@ mod tests {
use crate::inputs::bytes::BytesInput; use crate::inputs::bytes::BytesInput;
use crate::observers::ObserversTuple; use crate::observers::ObserversTuple;
use crate::observers::StdMapObserver; use crate::observers::StdMapObserver;
use crate::utils::current_time;
static mut MAP: [u32; 4] = [0; 4]; static mut MAP: [u32; 4] = [0; 4];
@ -961,6 +976,8 @@ mod tests {
observers_buf, observers_buf,
corpus_size: 123, corpus_size: 123,
client_config: "conf".into(), client_config: "conf".into(),
time: current_time(),
executions: 0
}; };
let serialized = postcard::to_allocvec(&e).unwrap(); let serialized = postcard::to_allocvec(&e).unwrap();
@ -972,6 +989,8 @@ mod tests {
observers_buf, observers_buf,
corpus_size: _, corpus_size: _,
client_config: _, client_config: _,
time: _,
executions: _
} => { } => {
let o = map.deserialize(&observers_buf).unwrap(); let o = map.deserialize(&observers_buf).unwrap();
let test_observer = o.match_name_type::<StdMapObserver<u32>>("test").unwrap(); let test_observer = o.match_name_type::<StdMapObserver<u32>>("test").unwrap();

View File

@ -27,13 +27,19 @@ impl ClientStats {
/// We got a new information about executions for this client, insert them. /// We got a new information about executions for this client, insert them.
pub fn update_executions(&mut self, executions: u64, cur_time: time::Duration) { pub fn update_executions(&mut self, executions: u64, cur_time: time::Duration) {
self.executions = executions; self.executions = executions;
if (cur_time - self.last_window_time).as_secs() > CLIENT_STATS_TIME_WINDOW_SECS { let diff = cur_time.checked_sub(self.last_window_time).map_or(0, |d| d.as_secs());
if diff > CLIENT_STATS_TIME_WINDOW_SECS {
self.last_execs_per_sec = self.execs_per_sec(cur_time); self.last_execs_per_sec = self.execs_per_sec(cur_time);
self.last_window_time = cur_time; self.last_window_time = cur_time;
self.last_window_executions = executions; self.last_window_executions = executions;
} }
} }
/// We got a new information about corpus size for this client, insert them.
pub fn update_corpus_size(&mut self, corpus_size: u64) {
self.corpus_size = corpus_size;
}
/// Get the calculated executions per second for this client /// Get the calculated executions per second for this client
pub fn execs_per_sec(&self, cur_time: time::Duration) -> u64 { pub fn execs_per_sec(&self, cur_time: time::Duration) -> u64 {
if self.executions == 0 { if self.executions == 0 {

View File

@ -32,7 +32,7 @@ use inputs::Input;
use observers::ObserversTuple; use observers::ObserversTuple;
use stages::StagesTuple; use stages::StagesTuple;
use state::{HasCorpus, State}; use state::{HasCorpus, State};
use utils::{current_milliseconds, Rand}; use utils::{current_milliseconds, current_time, Rand};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::{env::VarError, io, num::ParseIntError, string::FromUtf8Error}; use std::{env::VarError, io, num::ParseIntError, string::FromUtf8Error};
@ -86,7 +86,7 @@ where
state, state,
Event::UpdateStats { Event::UpdateStats {
executions: state.executions(), executions: state.executions(),
execs_over_sec: state.executions_over_seconds(), time: current_time(),
phantom: PhantomData, phantom: PhantomData,
}, },
)? )?

View File

@ -307,9 +307,7 @@ where
scheduled.add_mutation(mutation_tokeninsert); scheduled.add_mutation(mutation_tokeninsert);
scheduled.add_mutation(mutation_tokenreplace); scheduled.add_mutation(mutation_tokenreplace);
*/ */
// TODO: custom dictionary (redqueen etc.)
scheduled.add_mutation(mutation_splice); scheduled.add_mutation(mutation_splice);
HavocBytesMutator { HavocBytesMutator {

View File

@ -86,6 +86,8 @@ where
observers_buf, observers_buf,
corpus_size: state.corpus().count() + 1, corpus_size: state.corpus().count() + 1,
client_config: "TODO".into(), client_config: "TODO".into(),
time: crate::utils::current_time(),
executions: state.executions(),
}, },
)?; )?;
state.add_if_interesting(input_mut, fitness)?; state.add_if_interesting(input_mut, fitness)?;

View File

@ -68,6 +68,7 @@ where
executions: usize, executions: usize,
/// The corpus /// The corpus
corpus: C, corpus: C,
// TODO use Duration
/// At what time the fuzzing started /// At what time the fuzzing started
start_time: u64, start_time: u64,
/// Metadata stored for this state by one of the components /// Metadata stored for this state by one of the components
@ -218,20 +219,6 @@ where
pub fn set_start_time(&mut self, ms: u64) { pub fn set_start_time(&mut self, ms: u64) {
self.start_time = ms self.start_time = ms
} }
// TODO as this is done in the event manager, we can remove it
#[inline]
pub fn executions_over_seconds(&self) -> u64 {
let elapsed = current_milliseconds() - self.start_time();
if elapsed == 0 {
return 0;
}
let elapsed = elapsed / 1000;
if elapsed == 0 {
0
} else {
(self.executions() as u64) / elapsed
}
}
/// Returns vector of feebacks /// Returns vector of feebacks
#[inline] #[inline]