| 33 | } |
| 34 | |
| 35 | fn end(&self) { |
| 36 | let end = Instant::now(); |
| 37 | // SAFETY: FFI call |
| 38 | let path = format!("cloud-hypervisor-{}.trace", unsafe { libc::getpid() }); |
| 39 | let mut file = File::create(&path).unwrap(); |
| 40 | |
| 41 | #[derive(Serialize)] |
| 42 | struct TraceReport { |
| 43 | duration: Duration, |
| 44 | events: Arc<Mutex<HashMap<String, Vec<TraceEvent>>>>, |
| 45 | } |
| 46 | |
| 47 | let trace_report = TraceReport { |
| 48 | duration: end.duration_since(self.start), |
| 49 | events: self.events.clone(), |
| 50 | }; |
| 51 | |
| 52 | serde_json::to_writer_pretty(&file, &trace_report).unwrap(); |
| 53 | |
| 54 | file.flush().unwrap(); |
| 55 | |
| 56 | warn!("Trace output: {path}"); |
| 57 | } |
| 58 | |
| 59 | fn add_event(&mut self, event: TraceEvent) { |
| 60 | let current = std::thread::current(); |