Skip to content

Commit

Permalink
Merge pull request #767 from taikiy/narrow_tracing
Browse files Browse the repository at this point in the history
collect step tracing each time a step is narrowed
  • Loading branch information
akoshelev authored Aug 10, 2023
2 parents 23a112c + 0003dda commit 00e80cc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/protocol/step/descriptive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::{Step, StepNarrow};
#[cfg(feature = "step-trace")]
use crate::telemetry::{labels::STEP, metrics::STEP_NARROWED};
use std::fmt::{Debug, Display, Formatter};

/// A descriptive representation of a unique step in protocol execution.
Expand Down Expand Up @@ -53,6 +55,10 @@ impl<S: Step + ?Sized> StepNarrow<S> for Descriptive {
id += [std::any::type_name::<S>(), "::"].concat().as_ref();
}
id += step.as_ref();
#[cfg(feature = "step-trace")]
{
metrics::increment_counter!(STEP_NARROWED, STEP => id.clone());
}

Self { id }
}
Expand Down
7 changes: 7 additions & 0 deletions src/telemetry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod metrics {
pub const BYTES_SENT: &str = "bytes.sent";
pub const INDEXED_PRSS_GENERATED: &str = "i.prss.gen";
pub const SEQUENTIAL_PRSS_GENERATED: &str = "s.prss.gen";
pub const STEP_NARROWED: &str = "step.narrowed";

#[cfg(feature = "web-app")]
pub mod web {
Expand Down Expand Up @@ -98,5 +99,11 @@ pub mod metrics {
Unit::Count,
"Number of times PRSS is used as CPRNG to generate a random value"
);

describe_counter!(
STEP_NARROWED,
Unit::Count,
"Number of times the step is narrowed"
);
}
}
11 changes: 7 additions & 4 deletions src/telemetry/step_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
use crate::telemetry::{
labels,
metrics::{BYTES_SENT, INDEXED_PRSS_GENERATED, RECORDS_SENT, SEQUENTIAL_PRSS_GENERATED},
metrics::{
BYTES_SENT, INDEXED_PRSS_GENERATED, RECORDS_SENT, SEQUENTIAL_PRSS_GENERATED, STEP_NARROWED,
},
stats::Metrics,
};
use std::{
Expand Down Expand Up @@ -38,18 +40,19 @@ impl CsvExporter for Metrics {
if self.print_header {
writeln!(
w,
"Step,Records sent,Bytes sent,Indexed PRSS,Sequential PRSS"
"Step,Records sent,Bytes sent,Indexed PRSS,Sequential PRSS,Step narrowed"
)?;
}
for (step, stats) in steps_stats.all_steps() {
writeln!(
w,
"{},{},{},{},{}",
"{},{},{},{},{},{}",
step,
stats.get(RECORDS_SENT),
stats.get(BYTES_SENT),
stats.get(INDEXED_PRSS_GENERATED),
stats.get(SEQUENTIAL_PRSS_GENERATED)
stats.get(SEQUENTIAL_PRSS_GENERATED),
stats.get(STEP_NARROWED),
)?;
}

Expand Down

0 comments on commit 00e80cc

Please sign in to comment.