Skip to content

Commit 4f7d34a

Browse files
committed
Store platform-specific timestamps in the profile.
This will make it easier to merge profiles from different sources that were collected at the same time with different collection mechanisms.
1 parent 6205b9a commit 4f7d34a

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

fxprof-processed-profile/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub use profile::{
9191
FrameHandle, FrameSymbolInfo, Profile, SamplingInterval, SourceLocation, StackHandle,
9292
StringHandle, TimelineUnit,
9393
};
94-
pub use reference_timestamp::ReferenceTimestamp;
94+
pub use reference_timestamp::{PlatformSpecificReferenceTimestamp, ReferenceTimestamp};
9595
pub use sample_table::WeightType;
9696
pub use thread::ProcessHandle;
9797
pub use timestamp::Timestamp;

fxprof-processed-profile/src/profile.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::sample_table::WeightType;
3131
use crate::string_table::{GlobalStringIndex, GlobalStringTable};
3232
use crate::thread::{ProcessHandle, Thread};
3333
use crate::timestamp::Timestamp;
34-
use crate::{FrameFlags, Symbol};
34+
use crate::{FrameFlags, PlatformSpecificReferenceTimestamp, Symbol};
3535

3636
/// The sampling interval used during profile recording.
3737
///
@@ -181,6 +181,7 @@ pub struct Profile {
181181
pub(crate) initial_visible_threads: Vec<ThreadHandle>,
182182
pub(crate) initial_selected_threads: Vec<ThreadHandle>,
183183
pub(crate) reference_timestamp: ReferenceTimestamp,
184+
pub(crate) platform_specific_reference_timestamp: Option<PlatformSpecificReferenceTimestamp>,
184185
pub(crate) string_table: GlobalStringTable,
185186
pub(crate) marker_schemas: Vec<InternalMarkerSchema>,
186187
static_schema_marker_types: FastHashMap<&'static str, MarkerTypeHandle>,
@@ -214,6 +215,7 @@ impl Profile {
214215
global_libs: GlobalLibTable::new(),
215216
kernel_libs: LibMappings::new(),
216217
reference_timestamp,
218+
platform_specific_reference_timestamp: None,
217219
processes: Vec::new(),
218220
string_table: GlobalStringTable::new(),
219221
marker_schemas: Vec::new(),
@@ -236,6 +238,14 @@ impl Profile {
236238
self.reference_timestamp = reference_timestamp;
237239
}
238240

241+
/// Set an additional reference timestamp with a platform-specific unit.
242+
pub fn set_platform_specific_reference_timestamp(
243+
&mut self,
244+
platform_specific_reference_timestamp: PlatformSpecificReferenceTimestamp,
245+
) {
246+
self.platform_specific_reference_timestamp = Some(platform_specific_reference_timestamp);
247+
}
248+
239249
/// Change the product name.
240250
pub fn set_product(&mut self, product: &str) {
241251
self.product = product.to_string();
@@ -1355,6 +1365,18 @@ impl Serialize for SerializableProfileMeta<'_> {
13551365
}),
13561366
)?;
13571367
map.serialize_entry("startTime", &self.0.reference_timestamp)?;
1368+
match &self.0.platform_specific_reference_timestamp {
1369+
Some(PlatformSpecificReferenceTimestamp::ClockMonotonicNanosecondsSinceBoot(val)) => {
1370+
map.serialize_entry("startTimeAsClockMonotonicNanosecondsSinceBoot", &val)?;
1371+
}
1372+
Some(PlatformSpecificReferenceTimestamp::MachAbsoluteTimeNanoseconds(val)) => {
1373+
map.serialize_entry("startTimeAsMachAbsoluteTimeNanoseconds", &val)?;
1374+
}
1375+
Some(PlatformSpecificReferenceTimestamp::QueryPerformanceCounterValue(val)) => {
1376+
map.serialize_entry("startTimeAsQueryPerformanceCounterValue", &val)?;
1377+
}
1378+
None => {}
1379+
}
13581380
map.serialize_entry("symbolicated", &self.0.symbolicated)?;
13591381
map.serialize_entry("pausedRanges", &[] as &[()])?;
13601382
map.serialize_entry("version", &24)?; // this version is ignored, only "preprocessedProfileVersion" is used

fxprof-processed-profile/src/reference_timestamp.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,12 @@ impl Serialize for ReferenceTimestamp {
4242
self.ms_since_unix_epoch.serialize(serializer)
4343
}
4444
}
45+
46+
/// An additional reference timestamp in a platform-specific unit.
47+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48+
#[non_exhaustive]
49+
pub enum PlatformSpecificReferenceTimestamp {
50+
ClockMonotonicNanosecondsSinceBoot(u64),
51+
MachAbsoluteTimeNanoseconds(u64),
52+
QueryPerformanceCounterValue(u64),
53+
}

samply/src/linux_shared/converter.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use debugid::DebugId;
88
use framehop::{ExplicitModuleSectionInfo, FrameAddress, Module, Unwinder};
99
use fxprof_processed_profile::{
1010
Category, CategoryColor, CategoryHandle, CpuDelta, FrameFlags, LibraryHandle, LibraryInfo,
11-
MarkerFieldFlags, MarkerFieldFormat, MarkerTiming, Profile, ReferenceTimestamp,
12-
SamplingInterval, StaticSchemaMarker, StaticSchemaMarkerField, StringHandle, SubcategoryHandle,
13-
SymbolTable, ThreadHandle,
11+
MarkerFieldFlags, MarkerFieldFormat, MarkerTiming, PlatformSpecificReferenceTimestamp, Profile,
12+
ReferenceTimestamp, SamplingInterval, StaticSchemaMarker, StaticSchemaMarkerField,
13+
StringHandle, SubcategoryHandle, SymbolTable, ThreadHandle,
1414
};
1515
use linux_perf_data::linux_perf_event_reader::TaskWasPreempted;
1616
use linux_perf_data::simpleperf_dso_type::{DSO_DEX_FILE, DSO_KERNEL, DSO_KERNEL_MODULE};
@@ -164,6 +164,12 @@ where
164164
raw_to_ns_factor: 1,
165165
};
166166

167+
profile.set_platform_specific_reference_timestamp(
168+
PlatformSpecificReferenceTimestamp::ClockMonotonicNanosecondsSinceBoot(
169+
timestamp_converter.reference_raw,
170+
),
171+
);
172+
167173
let cpus = if profile_creation_props.create_per_cpu_threads {
168174
let start_timestamp = timestamp_converter.convert_time(first_sample_time);
169175
Some(Cpus::new(start_timestamp, &mut profile))

0 commit comments

Comments
 (0)