From c966307a9882bc04b684ed3e72d69cd66c530289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ko=C5=82aczkowski?= Date: Sat, 18 Dec 2021 18:30:41 +0100 Subject: [PATCH] Add optional custom tags in hdr output --- src/config.rs | 4 ++++ src/main.rs | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index f20acf2..0b9735e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -262,6 +262,10 @@ pub struct HdrCommand { /// Output file; if not given, the hdr log gets printed to stdout #[clap(short('o'), long, value_name = "PATH")] pub output: Option, + + /// Optional tag prefix to add to each histogram + #[clap(long, value_name = "STRING")] + pub tag: Option, } #[derive(Parser, Debug)] diff --git a/src/main.rs b/src/main.rs index 93b997b..5c4a126 100644 --- a/src/main.rs +++ b/src/main.rs @@ -296,6 +296,12 @@ async fn show(conf: ShowCommand) -> Result<()> { /// Reads histograms from the report and dumps them to an hdr log async fn export_hdr_log(conf: HdrCommand) -> Result<()> { + let tag_prefix = conf.tag.map(|t| t + ".").unwrap_or_else(|| "".to_string()); + if tag_prefix.chars().any(|c| ", \n\t".contains(c)) { + eprintln!("error: Hdr histogram tags are not allowed to contain commas nor whitespace."); + exit(255); + } + let report = load_report_or_abort(&conf.report); let stdout = stdout(); let output_file: File; @@ -327,13 +333,13 @@ async fn export_hdr_log(conf: HdrCommand) -> Result<()> { &sample.cycle_time_histogram_ns.0, interval_start_time, interval_duration, - Tag::new("cycles"), + Tag::new(format!("{}cycles", tag_prefix).as_str()), )?; log_writer.write_histogram( &sample.resp_time_histogram_ns.0, interval_start_time, interval_duration, - Tag::new("requests"), + Tag::new(format!("{}requests", tag_prefix).as_str()), )?; } Ok(())