-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
tokio/src/util/metric_atomics.rs
Outdated
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, | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
.
75a6719
to
6839427
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
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 ofMetricAtomicU64