Skip to content

Commit

Permalink
feat(report): add flows report mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Nov 11, 2023
1 parent e5c7fad commit bb4294b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub enum Mode {
Json,
/// Generate a Graphviz DOT file for N cycles.
Dot,
/// Display all flows.
Flows,
/// Do not generate any tracing output for N cycles.
Silent,
}
Expand Down Expand Up @@ -500,9 +502,13 @@ impl TryFrom<(Args, &Platform)> for TrippyConfig {
let dns_timeout = humantime::parse_duration(&dns_timeout)?;
let max_rounds = match mode {
Mode::Stream | Mode::Tui => None,
Mode::Pretty | Mode::Markdown | Mode::Csv | Mode::Json | Mode::Dot | Mode::Silent => {
Some(report_cycles)
}
Mode::Pretty
| Mode::Markdown
| Mode::Csv
| Mode::Json
| Mode::Dot
| Mode::Flows
| Mode::Silent => Some(report_cycles),
};
let tui_max_addrs = match tui_max_addrs {
Some(n) if n > 0 => Some(n),
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ fn run_frontend(
Mode::Pretty => report::run_report_table_pretty(&traces[0], args.report_cycles, &resolver)?,
Mode::Markdown => report::run_report_table_md(&traces[0], args.report_cycles, &resolver)?,
Mode::Dot => report::run_report_dot(&traces[0], args.report_cycles)?,
Mode::Flows => report::run_report_flows(&traces[0], args.report_cycles)?,
Mode::Silent => report::run_report_silent(&traces[0], args.report_cycles)?,
}
Ok(())
Expand Down
10 changes: 10 additions & 0 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@ pub fn run_report_dot(info: &TraceInfo, report_cycles: usize) -> anyhow::Result<
Ok(())
}

/// Run a trace and report all flows observed.
pub fn run_report_flows(info: &TraceInfo, report_cycles: usize) -> anyhow::Result<()> {
wait_for_round(&info.data, report_cycles)?;
let trace = info.data.read().clone();
for (flow, flow_id) in trace.flows() {
println!("flow {flow_id}: {flow}");
}
Ok(())
}

/// Block until trace data for round `round` is available.
fn wait_for_round(trace_data: &Arc<RwLock<Trace>>, report_cycles: usize) -> anyhow::Result<Trace> {
let mut trace = trace_data.read().clone();
Expand Down
1 change: 1 addition & 0 deletions trippy-config-sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# csv - Generate a CSV report for N cycles
# json - Generate a JSON report for N cycles
# dot - Generate a Graphviz DOT report for N cycles
# flows - Display all flows
# silent - Do not generate any output for N cycles
mode = "tui"

Expand Down

0 comments on commit bb4294b

Please sign in to comment.