From 17d18668f113081a1b6c5952c133577575d10c98 Mon Sep 17 00:00:00 2001 From: keroro Date: Fri, 30 Jul 2021 19:15:09 +0800 Subject: [PATCH] feat(ckb-bench): log metrics in json --- ckb-bench/src/main.rs | 12 ++++++------ ckb-bench/src/stat.rs | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ckb-bench/src/main.rs b/ckb-bench/src/main.rs index 8db801a..0c3ca99 100644 --- a/ckb-bench/src/main.rs +++ b/ckb-bench/src/main.rs @@ -283,20 +283,20 @@ pub fn entrypoint(clap_arg_match: ArgMatches<'static>) { } } - let stat_time = t_bench.div(2); + let t_stat = t_bench.div(2); let fixed_tip_number = watcher.get_fixed_header().number(); - let metrics = stat::stat(&nodes[0], zero_load_number, fixed_tip_number, stat_time); - ckb_testkit::info!("{:?}", metrics); + let metrics = stat::stat(&nodes[0], zero_load_number, fixed_tip_number, t_stat, Some(t_delay)); + ckb_testkit::info!("metrics: {}", serde_json::json!(metrics)); } ("stat", Some(arguments)) => { let rpc_urls = values_t_or_exit!(arguments, "rpc-urls", Url); let from_number = value_t_or_exit!(arguments, "from_number", BlockNumber); let to_number = value_t_or_exit!(arguments, "to_number", BlockNumber); let stat_time_ms = value_t_or_exit!(arguments, "stat_time_ms", u64); - let stat_time = Duration::from_millis(stat_time_ms); + let t_stat = Duration::from_millis(stat_time_ms); let node = Node::init_from_url(rpc_urls[0].as_str(), Default::default()); - let metrics = stat::stat(&node, from_number, to_number, stat_time); - ckb_testkit::info!("{:?}", metrics); + let metrics = stat::stat(&node, from_number, to_number, t_stat, None); + ckb_testkit::info!("metrics: {}", serde_json::json!(metrics)); } _ => { eprintln!("wrong usage"); diff --git a/ckb-bench/src/stat.rs b/ckb-bench/src/stat.rs index 9f6ef23..2738c26 100644 --- a/ckb-bench/src/stat.rs +++ b/ckb-bench/src/stat.rs @@ -17,6 +17,7 @@ pub struct Metrics { pub n_nodes: usize, pub n_outputs: usize, pub ckb_version: String, + pub delay_time_ms: Option, } pub fn stat( @@ -24,6 +25,7 @@ pub fn stat( from_number: BlockNumber, to_number: BlockNumber, stat_time: Duration, + delay_time: Option, ) -> Metrics { assert_ne!(from_number, 0); assert!(from_number < to_number); @@ -94,5 +96,6 @@ pub fn stat( best_metrics.ckb_version = local_node_info.version; best_metrics.n_nodes = local_node_info.connections.value() as usize + 1; best_metrics.n_outputs = n_outputs; + best_metrics.delay_time_ms = delay_time.map(|t| t.as_millis() as u64); best_metrics }