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

metrics: create MetricAtomicUsize for usized-metrics #6598

Merged
merged 3 commits into from
Jun 6, 2024

Conversation

rcoh
Copy link
Contributor

@rcoh rcoh commented May 29, 2024

Motivation

#6556 (comment)

Metrics should not use Loom atomics. This clarifies this in code and also gives the opportunity to make a cleaner interface for metrics. We could potentially use this interface in the future to track things like the maximum value etc.

Solution

Introduce MetricAtomicUsize as the equivalent of MetricAtomicU64

@mox692 mox692 added A-tokio Area: The main tokio crate M-metrics Module: tokio/runtime/metrics labels May 31, 2024
Comment on lines 49 to 56
cfg_rt! {
/// `AtomicUsize` for use in metrics.
///
/// This exposes simplified APIs for use in metrics & uses `std::sync` instead of Loom to avoid polluting loom logs with metric information.
#[derive(Debug, Default)]
pub(crate) struct MetricAtomicUsize {
value: std::sync::atomic::AtomicUsize,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be gated on cfg_rt!? Is the file not already gated on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are only used from the rt module (by coincidence, the other metrics are all u64) so I gated on rt to avoid dead code warnings.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add an #[cfg_attr(not(feature = "rt"), allow(dead_code))] on the module instead? The cfg_rt! blocks break rustfmt, so I try to avoid wrapping large blocks in them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe it'd be better to split the file into two and wrap the mod statement in cfg_rt!.

@rcoh rcoh force-pushed the metric-atomic-usize branch 2 times, most recently from 75a6719 to 6839427 Compare June 5, 2024 20:00
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thank you.

@Darksonn Darksonn merged commit 8e15c23 into tokio-rs:master Jun 6, 2024
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-metrics Module: tokio/runtime/metrics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants