Dedup CentralizedEventManager's serialize_observers() (#2034)
* why * clp
This commit is contained in:
parent
374f8735fa
commit
0d5c6219d8
@ -10,8 +10,6 @@
|
||||
use alloc::{boxed::Box, string::String, vec::Vec};
|
||||
use core::{marker::PhantomData, num::NonZeroUsize, time::Duration};
|
||||
|
||||
#[cfg(feature = "adaptive_serialization")]
|
||||
use libafl_bolts::current_time;
|
||||
#[cfg(feature = "llmp_compression")]
|
||||
use libafl_bolts::{
|
||||
compress::GzipCompressor,
|
||||
@ -332,7 +330,6 @@ where
|
||||
self.inner.log(state, severity_level, message)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "adaptive_serialization"))]
|
||||
fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Option<Vec<u8>>, Error>
|
||||
where
|
||||
OT: ObserversTuple<Self::State> + Serialize,
|
||||
@ -340,47 +337,6 @@ where
|
||||
self.inner.serialize_observers(observers)
|
||||
}
|
||||
|
||||
#[cfg(feature = "adaptive_serialization")]
|
||||
fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Option<Vec<u8>>, Error>
|
||||
where
|
||||
OT: ObserversTuple<Self::State> + Serialize,
|
||||
{
|
||||
const SERIALIZE_TIME_FACTOR: u32 = 4;
|
||||
const SERIALIZE_PERCENTAGE_TRESHOLD: usize = 80;
|
||||
|
||||
let exec_time = observers
|
||||
.match_name::<crate::observers::TimeObserver>("time")
|
||||
.map(|o| o.last_runtime().unwrap_or(Duration::ZERO))
|
||||
.unwrap();
|
||||
|
||||
let mut must_ser = (self.serialization_time() + self.deserialization_time())
|
||||
* SERIALIZE_TIME_FACTOR
|
||||
< exec_time;
|
||||
if must_ser {
|
||||
*self.should_serialize_cnt_mut() += 1;
|
||||
}
|
||||
|
||||
if self.serializations_cnt() > 32 {
|
||||
must_ser = (self.should_serialize_cnt() * 100 / self.serializations_cnt())
|
||||
> SERIALIZE_PERCENTAGE_TRESHOLD;
|
||||
}
|
||||
|
||||
if self.inner.serialization_time() == Duration::ZERO
|
||||
|| must_ser
|
||||
|| self.serializations_cnt().trailing_zeros() >= 8
|
||||
{
|
||||
let start = current_time();
|
||||
let ser = postcard::to_allocvec(observers)?;
|
||||
*self.inner.serialization_time_mut() = current_time() - start;
|
||||
|
||||
*self.serializations_cnt_mut() += 1;
|
||||
Ok(Some(ser))
|
||||
} else {
|
||||
*self.serializations_cnt_mut() += 1;
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
fn configuration(&self) -> EventConfig {
|
||||
self.inner.configuration()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user