Compute profiling time range from samples and markers
Overview
This PR adds profilingStartTime and profilingEndTime fields to the profile metadata, computed from all sample timestamps and marker start/end times across all threads.
Tests
I've updated all of the existing tests to check these values, but it doesn't have full coverage of the edge cases I've encountered, where marker times may be before/after sample times, or the converse, on multiple threads, etc.
I did manually verify that it fixes the issues I was seeing in #710 related to the profiling time range.
Example Before: https://share.firefox.dev/4oSRnGW
Notice that much of the right-most
Fib(14)is truncated.
Example After: https://share.firefox.dev/4p5vUux
Notice that every Fibonacci call is wholly present. The profile ends exactly at the end of the markers.
However, I'm not entirely sure if the current behavior is correct for every scenario.
For example, I'm not sure if the following start and end time of 10.0, which is the computed result for one of the current test cases, makes sense:
"startTime": 1636162232627.0,
"profilingStartTime": 10.0,
"profilingEndTime": 10.0,
"symbolicated": false,
"symbolicated": false,
"pausedRanges": [],
"pausedRanges": [],
"version": 24,
"version": 24,
I didn't add any additional test cases because I'm still very much a novice when it comes to the internals of the profiles. I bet an LLM could generate more test cases pretty well, given the context, but I wouldn't be able to accurately review whether it represents a realistic profile.
I'm not sure how extensive you want the test coverage, since these cases are pretty long, but I'm happy to try to add more cases if desired.
Additional Thoughts
I considered utilizing rayon for the compute_profiling_time_range() function, because it seems like a natural use case, and probably would drastically reduce the time to process large profiles. However, I didn't want to introduce a new dependency to this crate without asking.
Related Work
This PR was implemented as an alternative to https://github.com/firefox-devtools/profiler/pull/5682.