Skip to content

Commit

Permalink
Add optional custom tags in hdr output
Browse files Browse the repository at this point in the history
  • Loading branch information
pkolaczk committed Dec 18, 2021
1 parent 88d42bd commit c966307
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,

/// Optional tag prefix to add to each histogram
#[clap(long, value_name = "STRING")]
pub tag: Option<String>,
}

#[derive(Parser, Debug)]
Expand Down
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit c966307

Please sign in to comment.