Skip to content

Commit 0d5c621

Browse files
authored
Dedup CentralizedEventManager's serialize_observers() (#2034)
* why * clp
1 parent 374f873 commit 0d5c621

File tree

1 file changed

+0
-44
lines changed

1 file changed

+0
-44
lines changed

libafl/src/events/centralized.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use alloc::{boxed::Box, string::String, vec::Vec};
1111
use core::{marker::PhantomData, num::NonZeroUsize, time::Duration};
1212

13-
#[cfg(feature = "adaptive_serialization")]
14-
use libafl_bolts::current_time;
1513
#[cfg(feature = "llmp_compression")]
1614
use libafl_bolts::{
1715
compress::GzipCompressor,
@@ -332,55 +330,13 @@ where
332330
self.inner.log(state, severity_level, message)
333331
}
334332

335-
#[cfg(not(feature = "adaptive_serialization"))]
336333
fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Option<Vec<u8>>, Error>
337334
where
338335
OT: ObserversTuple<Self::State> + Serialize,
339336
{
340337
self.inner.serialize_observers(observers)
341338
}
342339

343-
#[cfg(feature = "adaptive_serialization")]
344-
fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Option<Vec<u8>>, Error>
345-
where
346-
OT: ObserversTuple<Self::State> + Serialize,
347-
{
348-
const SERIALIZE_TIME_FACTOR: u32 = 4;
349-
const SERIALIZE_PERCENTAGE_TRESHOLD: usize = 80;
350-
351-
let exec_time = observers
352-
.match_name::<crate::observers::TimeObserver>("time")
353-
.map(|o| o.last_runtime().unwrap_or(Duration::ZERO))
354-
.unwrap();
355-
356-
let mut must_ser = (self.serialization_time() + self.deserialization_time())
357-
* SERIALIZE_TIME_FACTOR
358-
< exec_time;
359-
if must_ser {
360-
*self.should_serialize_cnt_mut() += 1;
361-
}
362-
363-
if self.serializations_cnt() > 32 {
364-
must_ser = (self.should_serialize_cnt() * 100 / self.serializations_cnt())
365-
> SERIALIZE_PERCENTAGE_TRESHOLD;
366-
}
367-
368-
if self.inner.serialization_time() == Duration::ZERO
369-
|| must_ser
370-
|| self.serializations_cnt().trailing_zeros() >= 8
371-
{
372-
let start = current_time();
373-
let ser = postcard::to_allocvec(observers)?;
374-
*self.inner.serialization_time_mut() = current_time() - start;
375-
376-
*self.serializations_cnt_mut() += 1;
377-
Ok(Some(ser))
378-
} else {
379-
*self.serializations_cnt_mut() += 1;
380-
Ok(None)
381-
}
382-
}
383-
384340
fn configuration(&self) -> EventConfig {
385341
self.inner.configuration()
386342
}

0 commit comments

Comments
 (0)