Skip to content
Draft
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
8 changes: 8 additions & 0 deletions fxprof-processed-profile/src/marker_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ impl MarkerTable {
self
}

pub fn start_times(&self) -> impl Iterator<Item = Timestamp> + use<'_> {
self.marker_starts.iter().copied().flatten()
}

pub fn end_times(&self) -> impl Iterator<Item = Timestamp> + use<'_> {
self.marker_ends.iter().copied().flatten()
}

pub fn as_serializable<'a>(
&'a self,
schemas: &'a [InternalMarkerSchema],
Expand Down
22 changes: 22 additions & 0 deletions fxprof-processed-profile/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,22 @@ impl Profile {
}
}

fn compute_profiling_time_range(&self) -> Option<(Timestamp, Timestamp)> {
self.threads
.iter()
.flat_map(|thread| {
thread
.sample_timestamps()
.chain(thread.marker_start_times())
.chain(thread.marker_end_times())
})
.fold(None, |acc, timestamp| {
acc.map_or(Some((timestamp, timestamp)), |(min, max)| {
Some((min.min(timestamp), max.max(timestamp)))
})
})
}

fn contains_js_frame(&self) -> bool {
self.threads.iter().any(|t| t.contains_js_frame())
}
Expand Down Expand Up @@ -1497,6 +1513,12 @@ impl Serialize for SerializableProfileMeta<'_> {
}
None => {}
}

if let Some((start, end)) = self.0.compute_profiling_time_range() {
map.serialize_entry("profilingStartTime", &start)?;
map.serialize_entry("profilingEndTime", &end)?;
}

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
4 changes: 4 additions & 0 deletions fxprof-processed-profile/src/sample_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ impl SampleTable {
self.sample_weight_type = t;
}

pub fn timestamps(&self) -> impl Iterator<Item = Timestamp> + use<'_> {
self.sample_timestamps.iter().copied()
}

pub fn modify_last_sample(&mut self, timestamp: Timestamp, weight: i32) {
*self.sample_weights.last_mut().unwrap() += weight;
*self.sample_timestamps.last_mut().unwrap() = timestamp;
Expand Down
12 changes: 12 additions & 0 deletions fxprof-processed-profile/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ impl Thread {
self.frame_interner.gather_used_rvas(collector);
}

pub fn sample_timestamps(&self) -> impl Iterator<Item = Timestamp> + use<'_> {
self.samples.timestamps()
}

pub fn marker_start_times(&self) -> impl Iterator<Item = Timestamp> + use<'_> {
self.markers.start_times()
}

pub fn marker_end_times(&self) -> impl Iterator<Item = Timestamp> + use<'_> {
self.markers.end_times()
}

pub fn cmp_for_json_order(&self, other: &Thread) -> Ordering {
let ordering = (!self.is_main).cmp(&(!other.is_main));
if ordering != Ordering::Equal {
Expand Down
8 changes: 8 additions & 0 deletions fxprof-processed-profile/tests/integration_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ fn profile_without_js() {
"time": "ms"
},
"startTime": 1636162232627.0,
"profilingStartTime": 0.0,
"profilingEndTime": 3.0,
"symbolicated": false,
"pausedRanges": [],
"version": 24,
Expand Down Expand Up @@ -1020,6 +1022,8 @@ fn profile_with_js() {
"time": "ms"
},
"startTime": 1636162232627.0,
"profilingStartTime": 1.0,
"profilingEndTime": 1.0,
"symbolicated": false,
"pausedRanges": [],
"version": 24,
Expand Down Expand Up @@ -1277,6 +1281,8 @@ fn profile_counters_with_sorted_processes() {
"time": "ms"
},
"startTime": 1636162232627.0,
"profilingStartTime": 0.0,
"profilingEndTime": 1.0,
"symbolicated": true,
"pausedRanges": [],
"version": 24,
Expand Down Expand Up @@ -1590,6 +1596,8 @@ fn test_flow_marker_fields() {
"time": "ms"
},
"startTime": 1636162232627.0,
"profilingStartTime": 10.0,
"profilingEndTime": 10.0,
"symbolicated": false,
"pausedRanges": [],
"version": 24,
Expand Down
Loading