Skip to content

Add OnDiskJsonAggregateMonitor #2845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions libafl/src/monitors/disk_aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ use crate::monitors::{Aggregator, ClientStats, Monitor};

/// A monitor that wraps another monitor and logs aggregated stats to a JSON file.
#[derive(Clone)]
pub struct OnDiskJsonAggregateMonitor<M>
where
M: Monitor,
{
pub struct OnDiskJsonAggregateMonitor<M> {
base: M,
aggregator: Aggregator,
json_path: PathBuf,
Expand All @@ -27,7 +24,7 @@ where

impl<M> Debug for OnDiskJsonAggregateMonitor<M>
where
M: Monitor + Debug,
M: Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_struct("OnDiskJsonAggregateMonitor")
Expand Down Expand Up @@ -103,10 +100,7 @@ where
}
}

impl<M> OnDiskJsonAggregateMonitor<M>
where
M: Monitor,
{
impl<M> OnDiskJsonAggregateMonitor<M> {
/// Creates a new [`OnDiskJsonAggregateMonitor`]
pub fn new<P>(base: M, json_path: P) -> Self
where
Expand Down
45 changes: 26 additions & 19 deletions libafl/src/monitors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,39 @@
pub mod multi;
pub use multi::MultiMonitor;

#[cfg(feature = "std")]
pub mod disk;

#[cfg(feature = "std")]
pub mod disk_aggregate;

#[cfg(all(feature = "tui_monitor", feature = "std"))]
pub mod tui;

#[cfg(all(feature = "prometheus_monitor", feature = "std"))]
pub mod prometheus;
use alloc::string::ToString;

#[cfg(all(feature = "prometheus_monitor", feature = "std"))]
pub use prometheus::PrometheusMonitor;
#[cfg(feature = "std")]
pub mod disk;
use alloc::{borrow::Cow, fmt::Debug, string::String, vec::Vec};
use alloc::{
borrow::Cow,
fmt::Debug,
string::{String, ToString},
vec::Vec,
};
use core::{fmt, fmt::Write, time::Duration};

#[cfg(feature = "std")]
pub use disk::{OnDiskJsonMonitor, OnDiskTomlMonitor};

// Add our new module
#[cfg(feature = "std")]
pub mod disk_aggregate;
#[cfg(feature = "std")]
pub use disk_aggregate::OnDiskJsonAggregateMonitor;

use hashbrown::HashMap;
use libafl_bolts::{current_time, format_duration_hms, ClientId};
#[cfg(all(feature = "prometheus_monitor", feature = "std"))]
pub use prometheus::PrometheusMonitor;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
#[cfg(all(feature = "tui_monitor", feature = "std"))]
pub use tui::TuiMonitor;
#[cfg(feature = "std")]
pub use {
disk::{OnDiskJsonMonitor, OnDiskTomlMonitor},
disk_aggregate::OnDiskJsonAggregateMonitor,
};

#[cfg(feature = "afl_exec_sec")]
const CLIENT_STATS_TIME_WINDOW_SECS: u64 = 5; // 5 seconds
Expand Down Expand Up @@ -320,15 +327,15 @@ impl fmt::Display for UserStatsValue {
/// Prettifies float values for human-readable output
fn prettify_float(value: f64) -> String {
let (value, suffix) = match value {
value if value >= 1_000_000.0 => (value / 1_000_000.0, "M"),
value if value >= 1_000.0 => (value / 1_000.0, "k"),
value if value >= 1000000.0 => (value / 1000000.0, "M"),
value if value >= 1000.0 => (value / 1000.0, "k"),
value => (value, ""),
};
match value {
value if value >= 1_000_000.0 => {
value if value >= 1000000.0 => {
format!("{value:.2}{suffix}")
}
value if value >= 1_000.0 => {
value if value >= 1000.0 => {
format!("{value:.1}{suffix}")
}
value if value >= 100.0 => {
Expand Down
Loading