|
1 | | -// !!!!!!!!!!!!!!!!!!!!!!!! |
2 | | -// !! DO NOT TOUCH BELOW !! |
3 | | -// !!!!!!!!!!!!!!!!!!!!!!!! |
4 | | -// Has to be in sync with `perf-parser`. |
5 | | -// |
6 | | - |
7 | | -use std::{collections::HashMap, path::Path}; |
8 | | - |
| 1 | +use anyhow::Context; |
9 | 2 | use serde::{Deserialize, Serialize}; |
| 3 | +use std::path::Path; |
| 4 | + |
| 5 | +use crate::fifo::MarkerType; |
10 | 6 |
|
11 | 7 | #[derive(Serialize, Deserialize)] |
12 | 8 | pub struct PerfMetadata { |
| 9 | + /// The version of this metadata format. |
| 10 | + /// Only available in version 1+ |
| 11 | + #[serde(default)] |
| 12 | + pub version: u64, |
| 13 | + |
13 | 14 | /// Name and version of the integration |
14 | 15 | pub integration: (String, String), |
15 | 16 |
|
16 | | - /// The URIs of the benchmarks in the order they were executed. |
17 | | - pub bench_order_by_pid: HashMap<u32, Vec<String>>, |
| 17 | + /// The URIs of the benchmarks with the timestamps they were executed at. |
| 18 | + pub uri_by_ts: Vec<(u64, String)>, |
18 | 19 |
|
19 | 20 | /// Modules that should be ignored and removed from the folded trace and callgraph (e.g. python interpreter) |
20 | 21 | pub ignored_modules: Vec<(String, u64, u64)>, |
| 22 | + |
| 23 | + /// Marker for certain regions in the profiling data |
| 24 | + /// Only available in version 1+ |
| 25 | + #[serde(default)] |
| 26 | + pub markers: Vec<MarkerType>, |
21 | 27 | } |
22 | 28 |
|
23 | 29 | impl PerfMetadata { |
| 30 | + pub fn from_reader<R: std::io::Read>(reader: R) -> anyhow::Result<Self> { |
| 31 | + serde_json::from_reader(reader).context("Could not parse perf metadata from JSON") |
| 32 | + } |
| 33 | + |
24 | 34 | pub fn save_to<P: AsRef<Path>>(&self, path: P) -> anyhow::Result<()> { |
25 | 35 | let file = std::fs::File::create(path.as_ref().join("perf.metadata"))?; |
26 | 36 | serde_json::to_writer(file, self)?; |
|
0 commit comments