Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[subsystem-benchmarks] Save results to json #3829

Merged
merged 12 commits into from
Mar 26, 2024
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fn main() -> Result<(), String> {
messages.extend(usage.check_cpu_usage(&[("availability-recovery", 11.500, 0.05)]));

if messages.is_empty() {
usage.save_as_json("charts.json").map_err(|e| e.to_string())?;
Ok(())
} else {
eprintln!("{}", messages.join("\n"));
Expand Down
1 change: 1 addition & 0 deletions polkadot/node/subsystem-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ prometheus_endpoint = { package = "substrate-prometheus-endpoint", path = "../..
prometheus = { version = "0.13.0", default-features = false }
serde = { workspace = true, default-features = true }
serde_yaml = { workspace = true }
serde_json = { workspace = true }

polkadot-node-core-approval-voting = { path = "../core/approval-voting" }
polkadot-approval-distribution = { path = "../network/approval-distribution" }
Expand Down
2 changes: 1 addition & 1 deletion polkadot/node/subsystem-bench/src/lib/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ impl TestEnvironment {
let total_cpu = test_env_cpu_metrics.sum_by("substrate_tasks_polling_duration_sum");

usage.push(ResourceUsage {
resource_name: "Test environment".to_string(),
resource_name: "test-environment".to_string(),
total: total_cpu,
per_block: total_cpu / num_blocks,
});
Expand Down
41 changes: 40 additions & 1 deletion polkadot/node/subsystem-bench/src/lib/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

use colored::Colorize;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use serde_json::json;
use std::{collections::HashMap, fs::File, io::Write};

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BenchmarkUsage {
Expand Down Expand Up @@ -75,6 +76,44 @@ impl BenchmarkUsage {
_ => None,
}
}

pub fn save_as_json(&self, path: &str) -> std::io::Result<()> {
let mut file = File::create(path)?;
file.write_all(self.to_json().as_bytes())?;
Ok(())
}

fn to_json(&self) -> String {
let mut res: Vec<String> = vec![];
res.extend(
self.network_usage
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
.iter()
.map(|v| {
json!({
"name": v.resource_name,
"unit": "KiB",
"value": v.per_block
})
.to_string()
})
.collect::<Vec<_>>(),
);
res.extend(
self.cpu_usage
.iter()
.map(|v| {
json!({
"name": v.resource_name,
"unit": "seconds",
"value": v.per_block
})
.to_string()
})
.collect::<Vec<_>>(),
);

format!("[{}]", res.join(","))
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
}
}

fn check_usage(
Expand Down
Loading