Skip to content

Store platform-specific timestamps in the profile. #560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fxprof-processed-profile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub use profile::{
FrameHandle, FrameSymbolInfo, Profile, SamplingInterval, SourceLocation, StackHandle,
StringHandle, TimelineUnit,
};
pub use reference_timestamp::ReferenceTimestamp;
pub use reference_timestamp::{PlatformSpecificReferenceTimestamp, ReferenceTimestamp};
pub use sample_table::WeightType;
pub use thread::ProcessHandle;
pub use timestamp::Timestamp;
24 changes: 23 additions & 1 deletion fxprof-processed-profile/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::sample_table::WeightType;
use crate::string_table::{GlobalStringIndex, GlobalStringTable};
use crate::thread::{ProcessHandle, Thread};
use crate::timestamp::Timestamp;
use crate::{FrameFlags, Symbol};
use crate::{FrameFlags, PlatformSpecificReferenceTimestamp, Symbol};

/// The sampling interval used during profile recording.
///
Expand Down Expand Up @@ -181,6 +181,7 @@ pub struct Profile {
pub(crate) initial_visible_threads: Vec<ThreadHandle>,
pub(crate) initial_selected_threads: Vec<ThreadHandle>,
pub(crate) reference_timestamp: ReferenceTimestamp,
pub(crate) platform_specific_reference_timestamp: Option<PlatformSpecificReferenceTimestamp>,
pub(crate) string_table: GlobalStringTable,
pub(crate) marker_schemas: Vec<InternalMarkerSchema>,
static_schema_marker_types: FastHashMap<&'static str, MarkerTypeHandle>,
Expand Down Expand Up @@ -214,6 +215,7 @@ impl Profile {
global_libs: GlobalLibTable::new(),
kernel_libs: LibMappings::new(),
reference_timestamp,
platform_specific_reference_timestamp: None,
processes: Vec::new(),
string_table: GlobalStringTable::new(),
marker_schemas: Vec::new(),
Expand All @@ -236,6 +238,14 @@ impl Profile {
self.reference_timestamp = reference_timestamp;
}

/// Set an additional reference timestamp with a platform-specific unit.
pub fn set_platform_specific_reference_timestamp(
&mut self,
platform_specific_reference_timestamp: PlatformSpecificReferenceTimestamp,
) {
self.platform_specific_reference_timestamp = Some(platform_specific_reference_timestamp);
}

/// Change the product name.
pub fn set_product(&mut self, product: &str) {
self.product = product.to_string();
Expand Down Expand Up @@ -1355,6 +1365,18 @@ impl Serialize for SerializableProfileMeta<'_> {
}),
)?;
map.serialize_entry("startTime", &self.0.reference_timestamp)?;
match &self.0.platform_specific_reference_timestamp {
Some(PlatformSpecificReferenceTimestamp::ClockMonotonicNanosecondsSinceBoot(val)) => {
map.serialize_entry("startTimeAsClockMonotonicNanosecondsSinceBoot", &val)?;
}
Some(PlatformSpecificReferenceTimestamp::MachAbsoluteTimeNanoseconds(val)) => {
map.serialize_entry("startTimeAsMachAbsoluteTimeNanoseconds", &val)?;
}
Some(PlatformSpecificReferenceTimestamp::QueryPerformanceCounterValue(val)) => {
map.serialize_entry("startTimeAsQueryPerformanceCounterValue", &val)?;
}
None => {}
}
map.serialize_entry("symbolicated", &self.0.symbolicated)?;
map.serialize_entry("pausedRanges", &[] as &[()])?;
map.serialize_entry("version", &24)?; // this version is ignored, only "preprocessedProfileVersion" is used
Expand Down
9 changes: 9 additions & 0 deletions fxprof-processed-profile/src/reference_timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ impl Serialize for ReferenceTimestamp {
self.ms_since_unix_epoch.serialize(serializer)
}
}

/// An additional reference timestamp in a platform-specific unit.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum PlatformSpecificReferenceTimestamp {
ClockMonotonicNanosecondsSinceBoot(u64),
MachAbsoluteTimeNanoseconds(u64),
QueryPerformanceCounterValue(u64),
}
12 changes: 9 additions & 3 deletions samply/src/linux_shared/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use debugid::DebugId;
use framehop::{ExplicitModuleSectionInfo, FrameAddress, Module, Unwinder};
use fxprof_processed_profile::{
Category, CategoryColor, CategoryHandle, CpuDelta, FrameFlags, LibraryHandle, LibraryInfo,
MarkerFieldFlags, MarkerFieldFormat, MarkerTiming, Profile, ReferenceTimestamp,
SamplingInterval, StaticSchemaMarker, StaticSchemaMarkerField, StringHandle, SubcategoryHandle,
SymbolTable, ThreadHandle,
MarkerFieldFlags, MarkerFieldFormat, MarkerTiming, PlatformSpecificReferenceTimestamp, Profile,
ReferenceTimestamp, SamplingInterval, StaticSchemaMarker, StaticSchemaMarkerField,
StringHandle, SubcategoryHandle, SymbolTable, ThreadHandle,
};
use linux_perf_data::linux_perf_event_reader::TaskWasPreempted;
use linux_perf_data::simpleperf_dso_type::{DSO_DEX_FILE, DSO_KERNEL, DSO_KERNEL_MODULE};
Expand Down Expand Up @@ -164,6 +164,12 @@ where
raw_to_ns_factor: 1,
};

profile.set_platform_specific_reference_timestamp(
PlatformSpecificReferenceTimestamp::ClockMonotonicNanosecondsSinceBoot(
timestamp_converter.reference_raw,
),
);

let cpus = if profile_creation_props.create_per_cpu_threads {
let start_timestamp = timestamp_converter.convert_time(first_sample_time);
Some(Cpus::new(start_timestamp, &mut profile))
Expand Down
Loading