|
|
use std::{ |
|
|
borrow::Cow, |
|
|
fmt::{Display, Formatter}, |
|
|
}; |
|
|
|
|
|
use serde::{Deserialize, Serialize}; |
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)] |
|
|
pub enum TraceRow<'a> { |
|
|
|
|
|
Start { |
|
|
|
|
|
ts: u64, |
|
|
|
|
|
id: u64, |
|
|
|
|
|
parent: Option<u64>, |
|
|
|
|
|
#[serde(borrow)] |
|
|
name: Cow<'a, str>, |
|
|
|
|
|
#[serde(borrow)] |
|
|
target: Cow<'a, str>, |
|
|
|
|
|
#[serde(borrow)] |
|
|
values: Vec<(Cow<'a, str>, TraceValue<'a>)>, |
|
|
}, |
|
|
|
|
|
End { |
|
|
|
|
|
ts: u64, |
|
|
|
|
|
id: u64, |
|
|
}, |
|
|
|
|
|
Enter { |
|
|
|
|
|
ts: u64, |
|
|
|
|
|
id: u64, |
|
|
|
|
|
thread_id: u64, |
|
|
}, |
|
|
|
|
|
Exit { |
|
|
|
|
|
ts: u64, |
|
|
|
|
|
id: u64, |
|
|
|
|
|
thread_id: u64, |
|
|
}, |
|
|
|
|
|
Event { |
|
|
|
|
|
ts: u64, |
|
|
|
|
|
parent: Option<u64>, |
|
|
|
|
|
#[serde(borrow)] |
|
|
values: Vec<(Cow<'a, str>, TraceValue<'a>)>, |
|
|
}, |
|
|
|
|
|
Record { |
|
|
|
|
|
id: u64, |
|
|
|
|
|
#[serde(borrow)] |
|
|
values: Vec<(Cow<'a, str>, TraceValue<'a>)>, |
|
|
}, |
|
|
|
|
|
Allocation { |
|
|
|
|
|
ts: u64, |
|
|
|
|
|
thread_id: u64, |
|
|
|
|
|
allocations: u64, |
|
|
|
|
|
allocation_count: u64, |
|
|
|
|
|
deallocations: u64, |
|
|
|
|
|
deallocation_count: u64, |
|
|
}, |
|
|
|
|
|
|
|
|
AllocationCounters { |
|
|
|
|
|
ts: u64, |
|
|
|
|
|
thread_id: u64, |
|
|
|
|
|
allocations: u64, |
|
|
|
|
|
allocation_count: u64, |
|
|
|
|
|
deallocations: u64, |
|
|
|
|
|
deallocation_count: u64, |
|
|
}, |
|
|
} |
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)] |
|
|
pub enum TraceValue<'a> { |
|
|
String(#[serde(borrow)] Cow<'a, str>), |
|
|
Bool(bool), |
|
|
UInt(u64), |
|
|
Int(i64), |
|
|
Float(f64), |
|
|
} |
|
|
|
|
|
impl Display for TraceValue<'_> { |
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
|
|
match self { |
|
|
TraceValue::String(s) => write!(f, "{s}"), |
|
|
TraceValue::Bool(b) => write!(f, "{b}"), |
|
|
TraceValue::UInt(u) => write!(f, "{u}"), |
|
|
TraceValue::Int(i) => write!(f, "{i}"), |
|
|
TraceValue::Float(fl) => write!(f, "{fl}"), |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
impl TraceValue<'_> { |
|
|
pub fn as_u64(&self) -> Option<u64> { |
|
|
match self { |
|
|
TraceValue::UInt(u) => Some(*u), |
|
|
_ => None, |
|
|
} |
|
|
} |
|
|
|
|
|
pub fn as_str(&self) -> Option<&str> { |
|
|
match self { |
|
|
TraceValue::String(s) => Some(s), |
|
|
_ => None, |
|
|
} |
|
|
} |
|
|
|
|
|
pub fn into_static(self) -> TraceValue<'static> { |
|
|
match self { |
|
|
TraceValue::String(s) => TraceValue::String(s.into_owned().into()), |
|
|
TraceValue::Bool(b) => TraceValue::Bool(b), |
|
|
TraceValue::UInt(u) => TraceValue::UInt(u), |
|
|
TraceValue::Int(i) => TraceValue::Int(i), |
|
|
TraceValue::Float(fl) => TraceValue::Float(fl), |
|
|
} |
|
|
} |
|
|
} |
|
|
|