Skip to content

Commit ce01f4a

Browse files
authored
Move start_time to ClientStatsManager (#2948)
* Move start_time to ClientStatsManager * Remove unnessary &self * Make clippy happy * Make clippy happy
1 parent c03dfd9 commit ce01f4a

10 files changed

Lines changed: 88 additions & 253 deletions

File tree

libafl/src/events/simple.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ where
330330
self.staterestorer.reset();
331331
self.staterestorer.save(&(
332332
state,
333-
self.inner.monitor.start_time(),
333+
self.inner.client_stats_manager.start_time(),
334334
self.inner.client_stats_manager.client_stats(),
335335
))
336336
}
@@ -435,7 +435,7 @@ where
435435
/// Launch the simple restarting manager.
436436
/// This `EventManager` is simple and single threaded,
437437
/// but can still used shared maps to recover from crashes and timeouts.
438-
pub fn launch(mut monitor: MT, shmem_provider: &mut SP) -> Result<(Option<S>, Self), Error>
438+
pub fn launch(monitor: MT, shmem_provider: &mut SP) -> Result<(Option<S>, Self), Error>
439439
where
440440
S: DeserializeOwned + Serialize + HasSolutions<I>,
441441
MT: Debug,
@@ -546,8 +546,8 @@ where
546546
staterestorer.reset();
547547

548548
// reload the state of the monitor to display the correct stats after restarts
549-
monitor.set_start_time(start_time);
550549
let mut this = SimpleRestartingEventManager::launched(monitor, staterestorer);
550+
this.inner.client_stats_manager.set_start_time(start_time);
551551
this.inner
552552
.client_stats_manager
553553
.update_all_client_stats(clients_stats);

libafl/src/monitors/disk.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,6 @@ impl<M> Monitor for OnDiskTomlMonitor<M>
3232
where
3333
M: Monitor,
3434
{
35-
/// Time this fuzzing run stated
36-
fn start_time(&self) -> Duration {
37-
self.base.start_time()
38-
}
39-
40-
/// Set creation time
41-
fn set_start_time(&mut self, time: Duration) {
42-
self.base.set_start_time(time);
43-
}
44-
4535
fn display(
4636
&mut self,
4737
client_stats_manager: &mut ClientStatsManager,
@@ -66,7 +56,7 @@ objectives = {}
6656
executions = {}
6757
exec_sec = {}
6858
",
69-
format_duration_hms(&(cur_time - self.start_time())),
59+
format_duration_hms(&(cur_time - client_stats_manager.start_time())),
7060
client_stats_manager.client_stats_count(),
7161
client_stats_manager.corpus_size(),
7262
client_stats_manager.objective_size(),
@@ -193,14 +183,6 @@ where
193183
F: FnMut(&mut M) -> bool,
194184
M: Monitor,
195185
{
196-
fn start_time(&self) -> Duration {
197-
self.base.start_time()
198-
}
199-
200-
fn set_start_time(&mut self, time: Duration) {
201-
self.base.set_start_time(time);
202-
}
203-
204186
fn display(
205187
&mut self,
206188
client_stats_manager: &mut ClientStatsManager,
@@ -215,7 +197,7 @@ where
215197
.expect("Failed to open logging file");
216198

217199
let line = json!({
218-
"run_time": current_time() - self.base.start_time(),
200+
"run_time": current_time() - client_stats_manager.start_time(),
219201
"clients": client_stats_manager.client_stats_count(),
220202
"corpus": client_stats_manager.corpus_size(),
221203
"objectives": client_stats_manager.objective_size(),

libafl/src/monitors/disk_aggregate.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ impl<M> Monitor for OnDiskJsonAggregateMonitor<M>
3838
where
3939
M: Monitor,
4040
{
41-
fn set_start_time(&mut self, time: Duration) {
42-
self.base.set_start_time(time);
43-
}
44-
45-
fn start_time(&self) -> Duration {
46-
self.base.start_time()
47-
}
48-
4941
fn display(
5042
&mut self,
5143
client_stats_manager: &mut ClientStatsManager,
@@ -68,7 +60,7 @@ where
6860
.expect("Failed to open JSON logging file");
6961

7062
let mut json_value = json!({
71-
"run_time": (cur_time - self.start_time()).as_secs(),
63+
"run_time": (cur_time - client_stats_manager.start_time()).as_secs(),
7264
"clients": client_stats_manager.client_stats_count(),
7365
"corpus": client_stats_manager.corpus_size(),
7466
"objectives": client_stats_manager.objective_size(),

libafl/src/monitors/mod.rs

Lines changed: 15 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ use crate::statistics::manager::ClientStatsManager;
3434

3535
/// The monitor trait keeps track of all the client's monitor, and offers methods to display them.
3636
pub trait Monitor {
37-
/// Creation time
38-
fn start_time(&self) -> Duration;
39-
40-
/// Set creation time
41-
fn set_start_time(&mut self, time: Duration);
42-
4337
/// Show the monitor to the user
4438
fn display(
4539
&mut self,
@@ -52,21 +46,9 @@ pub trait Monitor {
5246
/// Monitor that print exactly nothing.
5347
/// Not good for debugging, very good for speed.
5448
#[derive(Debug, Clone)]
55-
pub struct NopMonitor {
56-
start_time: Duration,
57-
}
49+
pub struct NopMonitor {}
5850

5951
impl Monitor for NopMonitor {
60-
/// Time this fuzzing run stated
61-
fn start_time(&self) -> Duration {
62-
self.start_time
63-
}
64-
65-
/// Time this fuzzing run stated
66-
fn set_start_time(&mut self, time: Duration) {
67-
self.start_time = time;
68-
}
69-
7052
#[inline]
7153
fn display(
7254
&mut self,
@@ -81,9 +63,7 @@ impl NopMonitor {
8163
/// Create new [`NopMonitor`]
8264
#[must_use]
8365
pub fn new() -> Self {
84-
Self {
85-
start_time: current_time(),
86-
}
66+
Self {}
8767
}
8868
}
8969

@@ -95,19 +75,8 @@ impl Default for NopMonitor {
9575

9676
/// Tracking monitor during fuzzing that just prints to `stdout`.
9777
#[cfg(feature = "std")]
98-
#[derive(Debug, Clone)]
99-
pub struct SimplePrintingMonitor {
100-
start_time: Duration,
101-
}
102-
103-
#[cfg(feature = "std")]
104-
impl Default for SimplePrintingMonitor {
105-
fn default() -> Self {
106-
Self {
107-
start_time: current_time(),
108-
}
109-
}
110-
}
78+
#[derive(Debug, Clone, Default)]
79+
pub struct SimplePrintingMonitor {}
11180

11281
#[cfg(feature = "std")]
11382
impl SimplePrintingMonitor {
@@ -120,16 +89,6 @@ impl SimplePrintingMonitor {
12089

12190
#[cfg(feature = "std")]
12291
impl Monitor for SimplePrintingMonitor {
123-
/// Time this fuzzing run stated
124-
fn start_time(&self) -> Duration {
125-
self.start_time
126-
}
127-
128-
/// Time this fuzzing run stated
129-
fn set_start_time(&mut self, time: Duration) {
130-
self.start_time = time;
131-
}
132-
13392
fn display(
13493
&mut self,
13594
client_stats_manager: &mut ClientStatsManager,
@@ -146,7 +105,7 @@ impl Monitor for SimplePrintingMonitor {
146105
"[{} #{}] run time: {}, clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}, {}",
147106
event_msg,
148107
sender_id.0,
149-
format_duration_hms(&(current_time() - self.start_time)),
108+
format_duration_hms(&(current_time() - client_stats_manager.start_time())),
150109
client_stats_manager.client_stats_count(),
151110
client_stats_manager.corpus_size(),
152111
client_stats_manager.objective_size(),
@@ -177,7 +136,6 @@ where
177136
F: FnMut(&str),
178137
{
179138
print_fn: F,
180-
start_time: Duration,
181139
print_user_monitor: bool,
182140
}
183141

@@ -186,26 +144,14 @@ where
186144
F: FnMut(&str),
187145
{
188146
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
189-
f.debug_struct("SimpleMonitor")
190-
.field("start_time", &self.start_time)
191-
.finish_non_exhaustive()
147+
f.debug_struct("SimpleMonitor").finish_non_exhaustive()
192148
}
193149
}
194150

195151
impl<F> Monitor for SimpleMonitor<F>
196152
where
197153
F: FnMut(&str),
198154
{
199-
/// Time this fuzzing run stated
200-
fn start_time(&self) -> Duration {
201-
self.start_time
202-
}
203-
204-
/// Set creation time
205-
fn set_start_time(&mut self, time: Duration) {
206-
self.start_time = time;
207-
}
208-
209155
fn display(
210156
&mut self,
211157
client_stats_manager: &mut ClientStatsManager,
@@ -216,7 +162,7 @@ where
216162
"[{} #{}] run time: {}, clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}",
217163
event_msg,
218164
sender_id.0,
219-
format_duration_hms(&(current_time() - self.start_time)),
165+
format_duration_hms(&(current_time() - client_stats_manager.start_time())),
220166
client_stats_manager.client_stats_count(),
221167
client_stats_manager.corpus_size(),
222168
client_stats_manager.objective_size(),
@@ -259,25 +205,23 @@ where
259205
pub fn new(print_fn: F) -> Self {
260206
Self {
261207
print_fn,
262-
start_time: current_time(),
263208
print_user_monitor: false,
264209
}
265210
}
266211

267212
/// Creates the monitor with a given `start_time`.
268-
pub fn with_time(print_fn: F, start_time: Duration) -> Self {
269-
Self {
270-
print_fn,
271-
start_time,
272-
print_user_monitor: false,
273-
}
213+
#[deprecated(
214+
since = "0.16.0",
215+
note = "Please use new to create. start_time is useless here."
216+
)]
217+
pub fn with_time(print_fn: F, _start_time: Duration) -> Self {
218+
Self::new(print_fn)
274219
}
275220

276221
/// Creates the monitor that also prints the user monitor
277222
pub fn with_user_monitor(print_fn: F) -> Self {
278223
Self {
279224
print_fn,
280-
start_time: current_time(),
281225
print_user_monitor: true,
282226
}
283227
}
@@ -320,34 +264,16 @@ macro_rules! mark_feedback_time {
320264
pub struct CombinedMonitor<A, B> {
321265
first: A,
322266
second: B,
323-
start_time: Duration,
324267
}
325268

326269
impl<A: Monitor, B: Monitor> CombinedMonitor<A, B> {
327270
/// Create a new combined monitor
328-
pub fn new(mut first: A, mut second: B) -> Self {
329-
let start_time = current_time();
330-
first.set_start_time(start_time);
331-
second.set_start_time(start_time);
332-
Self {
333-
first,
334-
second,
335-
start_time,
336-
}
271+
pub fn new(first: A, second: B) -> Self {
272+
Self { first, second }
337273
}
338274
}
339275

340276
impl<A: Monitor, B: Monitor> Monitor for CombinedMonitor<A, B> {
341-
fn start_time(&self) -> Duration {
342-
self.start_time
343-
}
344-
345-
fn set_start_time(&mut self, time: Duration) {
346-
self.start_time = time;
347-
self.first.set_start_time(time);
348-
self.second.set_start_time(time);
349-
}
350-
351277
fn display(
352278
&mut self,
353279
client_stats_manager: &mut ClientStatsManager,

libafl/src/monitors/multi.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,21 @@ where
1717
F: FnMut(&str),
1818
{
1919
print_fn: F,
20-
start_time: Duration,
2120
}
2221

2322
impl<F> Debug for MultiMonitor<F>
2423
where
2524
F: FnMut(&str),
2625
{
2726
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
28-
f.debug_struct("MultiMonitor")
29-
.field("start_time", &self.start_time)
30-
.finish_non_exhaustive()
27+
f.debug_struct("MultiMonitor").finish_non_exhaustive()
3128
}
3229
}
3330

3431
impl<F> Monitor for MultiMonitor<F>
3532
where
3633
F: FnMut(&str),
3734
{
38-
/// Set creation time
39-
fn set_start_time(&mut self, time: Duration) {
40-
self.start_time = time;
41-
}
42-
43-
/// Time this fuzzing run stated
44-
fn start_time(&self) -> Duration {
45-
self.start_time
46-
}
47-
4835
fn display(
4936
&mut self,
5037
client_stats_manager: &mut ClientStatsManager,
@@ -61,7 +48,7 @@ where
6148
let mut global_fmt = format!(
6249
"[{}] (GLOBAL) run time: {}, clients: {}, corpus: {}, objectives: {}, executions: {}, exec/sec: {}",
6350
head,
64-
format_duration_hms(&(current_time() - self.start_time)),
51+
format_duration_hms(&(current_time() - client_stats_manager.start_time())),
6552
client_stats_manager.client_stats_count(),
6653
client_stats_manager.corpus_size(),
6754
client_stats_manager.objective_size(),
@@ -116,17 +103,15 @@ where
116103
{
117104
/// Creates the monitor, using the `current_time` as `start_time`.
118105
pub fn new(print_fn: F) -> Self {
119-
Self {
120-
print_fn,
121-
start_time: current_time(),
122-
}
106+
Self { print_fn }
123107
}
124108

125109
/// Creates the monitor with a given `start_time`.
126-
pub fn with_time(print_fn: F, start_time: Duration) -> Self {
127-
Self {
128-
print_fn,
129-
start_time,
130-
}
110+
#[deprecated(
111+
since = "0.16.0",
112+
note = "Please use new to create. start_time is useless here."
113+
)]
114+
pub fn with_time(print_fn: F, _start_time: Duration) -> Self {
115+
Self::new(print_fn)
131116
}
132117
}

0 commit comments

Comments
 (0)