mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-31 14:45:40 +00:00
[subsystem-benchmarks] Save results to json (#3829)
Here we add the ability to save subsystem benchmark results in JSON format to display them as graphs To draw graphs, CI team will use [github-action-benchmark](https://github.com/benchmark-action/github-action-benchmark). Since we are using custom benchmarks, we need to prepare [a specific data type](https://github.com/benchmark-action/github-action-benchmark?tab=readme-ov-file#examples): ``` [ { "name": "CPU Load", "unit": "Percent", "value": 50 } ] ``` Then we'll get graphs like this:  [A live page with graphs](https://benchmark-action.github.io/github-action-benchmark/dev/bench/) --------- Co-authored-by: ordian <write@reusable.software>
This commit is contained in:
@@ -82,6 +82,27 @@ impl BenchmarkUsage {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
// Prepares a json string for a graph representation
|
||||
// See: https://github.com/benchmark-action/github-action-benchmark?tab=readme-ov-file#examples
|
||||
pub fn to_chart_json(&self) -> color_eyre::eyre::Result<String> {
|
||||
let chart = self
|
||||
.network_usage
|
||||
.iter()
|
||||
.map(|v| ChartItem {
|
||||
name: v.resource_name.clone(),
|
||||
unit: "KiB".to_string(),
|
||||
value: v.per_block,
|
||||
})
|
||||
.chain(self.cpu_usage.iter().map(|v| ChartItem {
|
||||
name: v.resource_name.clone(),
|
||||
unit: "seconds".to_string(),
|
||||
value: v.per_block,
|
||||
}))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Ok(serde_json::to_string(&chart)?)
|
||||
}
|
||||
}
|
||||
|
||||
fn check_usage(
|
||||
@@ -151,3 +172,10 @@ impl ResourceUsage {
|
||||
}
|
||||
|
||||
type ResourceUsageCheck<'a> = (&'a str, f64, f64);
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct ChartItem {
|
||||
pub name: String,
|
||||
pub unit: String,
|
||||
pub value: f64,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user