Skip to content

Commit

Permalink
Creat Mock Histogram, HistogramBatch and HistogramBuilder. Revert cha…
Browse files Browse the repository at this point in the history
…nges on histogram.rs and guard it behind unstable flag
  • Loading branch information
Owen-CH-Leung committed Oct 16, 2024
1 parent 86f019f commit 64f626d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
27 changes: 12 additions & 15 deletions tokio/src/runtime/metrics/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,31 @@ pub(crate) struct HistogramBatch {
resolution: u64,
}

/// Whether the histogram used to aggregate a metric uses a linear or
/// logarithmic scale.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[non_exhaustive]
#[allow(unreachable_pub)]
pub enum HistogramScale {
/// Linear bucket scale
Linear,

/// Logarithmic bucket scale
#[allow(dead_code)]
Log,
cfg_unstable! {
/// Whether the histogram used to aggregate a metric uses a linear or
/// logarithmic scale.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum HistogramScale {
/// Linear bucket scale
Linear,

/// Logarithmic bucket scale
Log,
}
}

impl Histogram {
#[allow(dead_code)]
pub(crate) fn num_buckets(&self) -> usize {
self.buckets.len()
}

cfg_64bit_metrics! {
#[allow(dead_code)]
pub(crate) fn get(&self, bucket: usize) -> u64 {
self.buckets[bucket].load(Relaxed)
}
}

#[allow(dead_code)]
pub(crate) fn bucket_range(&self, bucket: usize) -> Range<u64> {
match self.scale {
HistogramScale::Log => Range {
Expand Down
24 changes: 24 additions & 0 deletions tokio/src/runtime/metrics/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,27 @@ impl SchedulerMetrics {
/// Increment the number of tasks scheduled externally
pub(crate) fn inc_remote_schedule_count(&self) {}
}

#[derive(Debug)]
pub(crate) struct Histogram {}

pub(crate) struct HistogramBatch {}

#[derive(Debug, Clone, Default)]
pub(crate) struct HistogramBuilder {}

impl HistogramBuilder {
pub(crate) fn build(&self) -> Histogram {
Histogram {}
}
}

impl HistogramBatch {
pub(crate) fn from_histogram(_histogram: &Histogram) -> HistogramBatch {
HistogramBatch {}
}

pub(crate) fn submit(&self, _histogram: &Histogram) {}

pub(crate) fn measure(&mut self, _value: u64, _count: u64) {}
}
9 changes: 5 additions & 4 deletions tokio/src/runtime/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ pub(crate) use worker::WorkerMetrics;
mod batch;
pub(crate) use batch::MetricsBatch;

mod histogram;
pub(crate) use histogram::{Histogram, HistogramBatch, HistogramBuilder};

cfg_unstable_metrics! {
#[allow(unreachable_pub)] // rust-lang/rust#57411
pub use histogram::HistogramScale;
Expand All @@ -32,10 +29,14 @@ cfg_unstable_metrics! {
mod io;
pub(crate) use io::IoDriverMetrics;
}

mod histogram;
pub(crate) use histogram::{Histogram, HistogramBatch, HistogramBuilder};
}

cfg_not_unstable_metrics! {
mod mock;

pub(crate) use mock::SchedulerMetrics;
pub(crate) use mock::{SchedulerMetrics, Histogram, HistogramBatch, HistogramBuilder};

}

0 comments on commit 64f626d

Please sign in to comment.