Add markers to event stream
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
use std::collections::HashMap;
|
||||
use std::{borrow::Cow, collections::HashMap};
|
||||
|
||||
use fxprof_processed_profile::{
|
||||
CategoryHandle, CpuDelta, Frame, FrameFlags, FrameInfo, ProcessHandle, Profile,
|
||||
ReferenceTimestamp, SamplingInterval, StackHandle, ThreadHandle, Timestamp,
|
||||
CategoryHandle, CpuDelta, Frame, FrameFlags, FrameInfo, MarkerTiming, ProcessHandle, Profile,
|
||||
ReferenceTimestamp, SamplingInterval, StackHandle, StaticSchemaMarker, StringHandle,
|
||||
ThreadHandle, Timestamp,
|
||||
};
|
||||
|
||||
use crate::profiler::state::{ProgramState, RESET_CODE, StackFrame};
|
||||
@@ -72,6 +73,15 @@ impl Recording {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn track_marker(&mut self, name: Cow<'static, str>) {
|
||||
let Some(thread) = self.threads.get(&RESET_CODE) else {
|
||||
return;
|
||||
};
|
||||
let timing = MarkerTiming::Instant(Timestamp::from_nanos_since_reference(self.now * 50));
|
||||
let marker = SimpleMarker(name);
|
||||
self.profile.add_marker(*thread, timing, marker);
|
||||
}
|
||||
|
||||
pub fn finish(self) -> Vec<u8> {
|
||||
serde_json::to_vec(&self.profile).expect("could not serialize profile")
|
||||
}
|
||||
@@ -92,6 +102,29 @@ impl Recording {
|
||||
}
|
||||
}
|
||||
|
||||
struct SimpleMarker(Cow<'static, str>);
|
||||
|
||||
impl StaticSchemaMarker for SimpleMarker {
|
||||
const UNIQUE_MARKER_TYPE_NAME: &'static str = "Simple";
|
||||
const FIELDS: &'static [fxprof_processed_profile::StaticSchemaMarkerField] = &[];
|
||||
|
||||
fn name(&self, profile: &mut Profile) -> StringHandle {
|
||||
profile.intern_string(&self.0)
|
||||
}
|
||||
|
||||
fn category(&self, _profile: &mut Profile) -> CategoryHandle {
|
||||
CategoryHandle::OTHER
|
||||
}
|
||||
|
||||
fn string_field_value(&self, _field_index: u32) -> StringHandle {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
fn number_field_value(&self, _field_index: u32) -> f64 {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
fn thread_name_for_code(code: u16) -> std::borrow::Cow<'static, str> {
|
||||
match code {
|
||||
RESET_CODE => "Main".into(),
|
||||
|
||||
Reference in New Issue
Block a user