Skip to content

Commit 8683c68

Browse files
authored
* incroyable * lolg
1 parent fb8939e commit 8683c68

File tree

3 files changed

+29
-43
lines changed

3 files changed

+29
-43
lines changed

libafl/src/monitors/stats/manager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl ClientStatsManager {
187187
let mut total_process_timing = ProcessTiming::new();
188188
total_process_timing.exec_speed = execs_per_sec_pretty;
189189
total_process_timing.total_execs = total_execs;
190-
if self.client_stats().len() > 1 {
190+
if !self.client_stats().is_empty() {
191191
let mut new_path_time = Duration::default();
192192
let mut new_objectives_time = Duration::default();
193193
for (_, stat) in self
@@ -199,10 +199,10 @@ impl ClientStatsManager {
199199
new_objectives_time = stat.last_objective_time().max(new_objectives_time);
200200
}
201201
if new_path_time > self.start_time() {
202-
total_process_timing.last_new_entry = new_path_time - self.start_time();
202+
total_process_timing.last_new_entry = current_time() - new_path_time;
203203
}
204204
if new_objectives_time > self.start_time() {
205-
total_process_timing.last_saved_solution = new_objectives_time - self.start_time();
205+
total_process_timing.last_saved_solution = current_time() - new_objectives_time;
206206
}
207207
}
208208
total_process_timing

libafl/src/monitors/stats/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,13 @@ impl ClientStats {
329329
pub fn process_timing(&mut self) -> ProcessTiming {
330330
let client_start_time = self.start_time();
331331
let last_new_entry = if self.last_corpus_time() > self.start_time() {
332-
self.last_corpus_time() - self.start_time()
332+
current_time() - self.last_corpus_time()
333333
} else {
334334
Duration::default()
335335
};
336336

337337
let last_saved_solution = if self.last_objective_time() > self.start_time() {
338-
self.last_objective_time() - self.start_time()
338+
current_time() - self.last_objective_time()
339339
} else {
340340
Duration::default()
341341
};

libafl/src/monitors/tui/ui.rs

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct TuiUi {
2626
version: String,
2727
enhanced_graphics: bool,
2828
show_logs: bool,
29-
clients_idx: usize,
29+
client_idx: usize,
3030
clients: usize,
3131
charts_tab_idx: usize,
3232
graph_data: Vec<(f64, f64)>,
@@ -48,7 +48,7 @@ impl TuiUi {
4848
version,
4949
enhanced_graphics,
5050
show_logs: true,
51-
clients_idx: 1,
51+
client_idx: 0,
5252
..TuiUi::default()
5353
}
5454
}
@@ -67,29 +67,15 @@ impl TuiUi {
6767
}
6868
}
6969

70-
//pub fn on_up(&mut self) {}
71-
72-
//pub fn on_down(&mut self) {}
73-
7470
pub fn on_right(&mut self) {
75-
if self.clients != 0 {
76-
// clients_idx never 0
77-
if self.clients - 1 != 0 {
78-
// except for when it is ;)
79-
self.clients_idx = 1 + self.clients_idx % (self.clients - 1);
80-
}
71+
if self.clients > 0 && self.client_idx < self.clients - 1 {
72+
self.client_idx += 1;
8173
}
8274
}
8375

8476
pub fn on_left(&mut self) {
85-
if self.clients != 0 {
86-
// clients_idx never 0
87-
if self.clients_idx == 1 {
88-
self.clients_idx = self.clients - 1;
89-
} else if self.clients - 1 != 0 {
90-
// don't wanna be dividing by 0
91-
self.clients_idx = 1 + (self.clients_idx - 2) % (self.clients - 1);
92-
}
77+
if self.client_idx > 0 {
78+
self.client_idx -= 1;
9379
}
9480
}
9581

@@ -248,7 +234,7 @@ impl TuiUi {
248234
fn draw_client_ui(&mut self, f: &mut Frame, app: &Arc<RwLock<TuiContext>>, area: Rect) {
249235
let client_block = Block::default()
250236
.title(Span::styled(
251-
format!("client #{} (l/r arrows to switch)", self.clients_idx),
237+
format!("client #{} (←/→ arrows to switch)", self.client_idx),
252238
Style::default()
253239
.fg(Color::LightCyan)
254240
.add_modifier(Modifier::BOLD),
@@ -431,16 +417,16 @@ impl TuiUi {
431417
let empty_geometry: ItemGeometry = ItemGeometry::new();
432418
let item_geometry: &ItemGeometry = if is_overall {
433419
&tui_context.total_item_geometry
434-
} else if self.clients < 2 {
420+
} else if self.clients == 0 {
435421
&empty_geometry
436422
} else {
437423
let clients = &tui_context.clients;
438-
let client = clients.get(&self.clients_idx);
424+
let client = clients.get(&self.client_idx);
439425
let client = client.as_ref();
440426
if let Some(client) = client {
441427
&client.item_geometry
442428
} else {
443-
log::warn!("Client {} was `None`. Race condition?", &self.clients_idx);
429+
log::warn!("Client {} was `None`. Race condition?", &self.client_idx);
444430
&empty_geometry
445431
}
446432
};
@@ -508,41 +494,41 @@ impl TuiUi {
508494
let empty_timing: ProcessTiming = ProcessTiming::new();
509495
let tup: (Duration, &ProcessTiming) = if is_overall {
510496
(tui_context.start_time, &tui_context.total_process_timing)
511-
} else if self.clients < 2 {
497+
} else if self.clients == 0 {
512498
(current_time(), &empty_timing)
513499
} else {
514500
let clients = &tui_context.clients;
515-
let client = clients.get(&self.clients_idx);
501+
let client = clients.get(&self.client_idx);
516502
let client = client.as_ref();
517503
if let Some(client) = client {
518504
(
519505
client.process_timing.client_start_time,
520506
&client.process_timing,
521507
)
522508
} else {
523-
log::warn!("Client {} was `None`. Race condition?", &self.clients_idx);
509+
log::warn!("Client {} was `None`. Race condition?", &self.client_idx);
524510
(current_time(), &empty_timing)
525511
}
526512
};
527513
let items = vec![
528514
Row::new(vec![
529-
Cell::from(Span::raw("run time")),
515+
Cell::from(Span::raw("global run time")),
530516
Cell::from(Span::raw(format_duration_hms(&(current_time() - tup.0)))),
531517
]),
532518
Row::new(vec![
533-
Cell::from(Span::raw("exec speed")),
519+
Cell::from(Span::raw("global exec speed")),
534520
Cell::from(Span::raw(&tup.1.exec_speed)),
535521
]),
536522
Row::new(vec![
537-
Cell::from(Span::raw("total execs")),
523+
Cell::from(Span::raw("global total execs")),
538524
Cell::from(Span::raw(format_big_number(tup.1.total_execs))),
539525
]),
540526
Row::new(vec![
541-
Cell::from(Span::raw("last new entry")),
527+
Cell::from(Span::raw("global last new entry")),
542528
Cell::from(Span::raw(format_duration_hms(&(tup.1.last_new_entry)))),
543529
]),
544530
Row::new(vec![
545-
Cell::from(Span::raw("last solution")),
531+
Cell::from(Span::raw("global last solution")),
546532
Cell::from(Span::raw(format_duration_hms(&(tup.1.last_saved_solution)))),
547533
]),
548534
];
@@ -642,7 +628,7 @@ impl TuiUi {
642628
Cell::from(Span::raw(format!(
643629
"{}",
644630
app.clients
645-
.get(&self.clients_idx)
631+
.get(&self.client_idx)
646632
.map_or(0, |x| x.cycles_done)
647633
))),
648634
]),
@@ -651,7 +637,7 @@ impl TuiUi {
651637
Cell::from(Span::raw(format!(
652638
"{}",
653639
app.clients
654-
.get(&self.clients_idx)
640+
.get(&self.client_idx)
655641
.map_or(0, |x| x.objectives)
656642
))),
657643
]),
@@ -686,22 +672,22 @@ impl TuiUi {
686672
Row::new(vec![
687673
Cell::from(Span::raw("corpus count")),
688674
Cell::from(Span::raw(format_big_number(
689-
app.clients.get(&self.clients_idx).map_or(0, |x| x.corpus),
675+
app.clients.get(&self.client_idx).map_or(0, |x| x.corpus),
690676
))),
691677
]),
692678
Row::new(vec![
693679
Cell::from(Span::raw("total execs")),
694680
Cell::from(Span::raw(format_big_number(
695681
app.clients
696-
.get(&self.clients_idx)
682+
.get(&self.client_idx)
697683
.map_or(0, |x| x.executions),
698684
))),
699685
]),
700686
Row::new(vec![
701687
Cell::from(Span::raw("map density")),
702688
Cell::from(Span::raw(
703689
app.clients
704-
.get(&self.clients_idx)
690+
.get(&self.client_idx)
705691
.map_or("0%".to_string(), |x| x.map_density.to_string()),
706692
)),
707693
]),
@@ -734,7 +720,7 @@ impl TuiUi {
734720
let mut items = vec![];
735721
{
736722
let ctx = app.read().unwrap();
737-
if let Some(client) = ctx.introspection.get(&self.clients_idx) {
723+
if let Some(client) = ctx.introspection.get(&self.client_idx) {
738724
items.push(Row::new(vec![
739725
Cell::from(Span::raw("scheduler")),
740726
Cell::from(Span::raw(format!("{:.2}%", client.scheduler * 100.0))),

0 commit comments

Comments
 (0)