Skip to content

Commit

Permalink
feat(ckb-bench): log metrics in json
Browse files Browse the repository at this point in the history
  • Loading branch information
keroro520 committed Jul 30, 2021
1 parent 05707ad commit 17d1866
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ckb-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions ckb-bench/src/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ pub struct Metrics {
pub n_nodes: usize,
pub n_outputs: usize,
pub ckb_version: String,
pub delay_time_ms: Option<u64>,
}

pub fn stat(
node: &Node,
from_number: BlockNumber,
to_number: BlockNumber,
stat_time: Duration,
delay_time: Option<Duration>,
) -> Metrics {
assert_ne!(from_number, 0);
assert!(from_number < to_number);
Expand Down Expand Up @@ -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
}

0 comments on commit 17d1866

Please sign in to comment.