Skip to content
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

Add StatsD monitor #2969

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions libafl/src/monitors/stats/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ impl ClientStatsManager {
}

/// Get item geometry
#[allow(clippy::cast_precision_loss)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this should be expect

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will create a PR quickly

Copy link
Contributor Author

@Evian-Zhang Evian-Zhang Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[cfg(feature = "std")]
#[must_use]
pub fn item_geometry(&self) -> ItemGeometry {
Expand Down Expand Up @@ -248,10 +249,10 @@ impl ClientStatsManager {
ratio_b += b;
}
}
total_item_geometry.stability_in_percent = if ratio_b == 0 {
total_item_geometry.stability = if ratio_b == 0 {
None
} else {
Some((ratio_a * 100 / ratio_b) as u8)
Some((ratio_a as f64) / (ratio_b as f64))
};
total_item_geometry
}
Expand Down
13 changes: 7 additions & 6 deletions libafl/src/monitors/stats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ pub struct ItemGeometry {
pub own_finds: u64,
/// How much entries were imported
pub imported: u64,
/// The stability in percent, ranges from 0 to 100.
/// The stability, ranges from 0.0 to 1.0.
///
/// If there is no such data, this field will be `None`.
pub stability_in_percent: Option<u8>,
pub stability: Option<f64>,
}

impl ItemGeometry {
Expand Down Expand Up @@ -363,6 +363,7 @@ impl ClientStats {
}

/// Get item geometry of current client
#[allow(clippy::cast_precision_loss)]
#[cfg(feature = "std")]
#[must_use]
pub fn item_geometry(&self) -> ItemGeometry {
Expand All @@ -388,11 +389,11 @@ impl ClientStats {
Clone::clone,
);

let stability_in_percent = if let UserStatsValue::Ratio(a, b) = stability.value() {
let stability = if let UserStatsValue::Ratio(a, b) = stability.value() {
if *b == 0 {
Some(0)
Some(0.0)
} else {
Some((*a * 100 / *b) as u8)
Some((*a as f64) / (*b as f64))
}
} else {
None
Expand All @@ -403,7 +404,7 @@ impl ClientStats {
pend_fav,
own_finds,
imported,
stability_in_percent,
stability,
}
}
}
Expand Down
11 changes: 5 additions & 6 deletions libafl/src/monitors/statsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl StatsdMonitor {
self.statsd_client = Some(client);
}

#[allow(clippy::cast_precision_loss)]
fn try_display(&mut self, client_stats_manager: &mut ClientStatsManager) -> Option<()> {
if self.statsd_client.is_none() {
self.setup_statsd_client();
Expand All @@ -133,7 +134,7 @@ impl StatsdMonitor {
pend_fav,
own_finds,
imported,
stability_in_percent,
stability,
} = client_stats_manager.item_geometry();
let edges_coverage = client_stats_manager.edges_coverage();

Expand All @@ -151,10 +152,8 @@ impl StatsdMonitor {
statsd_client.gauge("corpus_count", corpus_size).ok()?;
statsd_client.gauge("corpus_found", own_finds).ok()?;
statsd_client.gauge("corpus_imported", imported).ok()?;
if let Some(stability_in_percent) = stability_in_percent {
statsd_client
.gauge("stability", u64::from(stability_in_percent))
.ok()?; // Newly added
if let Some(stability) = stability {
statsd_client.gauge("stability", stability).ok()?; // Newly added
}
statsd_client.gauge("pending_favs", pend_fav).ok()?;
statsd_client.gauge("pending_total", pending).ok()?;
Expand All @@ -168,7 +167,7 @@ impl StatsdMonitor {
{
statsd_client.gauge("edges_found", edges_hit).ok()?;
statsd_client
.gauge("map_density", edges_hit * 100 / edges_total)
.gauge("map_density", (edges_hit as f64) / (edges_total as f64))
.ok()?; // Newly added
}

Expand Down
4 changes: 2 additions & 2 deletions libafl/src/monitors/tui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ impl TuiUi {
Row::new(vec![
Cell::from(Span::raw("stability")),
Cell::from(Span::raw(format!(
"{}%",
item_geometry.stability_in_percent.unwrap_or(0)
"{:.2}%",
item_geometry.stability.unwrap_or(0.0) * 100.0
))),
]),
];
Expand Down
Loading