Commit bb860b8
Fix Perfetto JS event timestamps on Apple platforms (#57095)
Summary:
`highResTimeStampToPerfettoTraceTime` returned the raw `HighResTimeStamp` nanoseconds as the Perfetto trace timestamp. That is only correct on Android, where Perfetto's clock and the `std::chrono::steady_clock` backing `HighResTimeStamp` happen to share an epoch. On Apple platforms the assumption is false: `HighResTimeStamp` is backed by `mach_absolute_time` (`CLOCK_UPTIME_RAW`, which excludes time the device spent asleep) while Perfetto stamps native events with `CLOCK_MONOTONIC` (which includes time asleep). The two clocks have different epochs, so JS/Web-Performance events were placed far off the native timeline, producing a nonsensical trace bounds span.
This converts JS timestamps into Perfetto's clock domain on Apple by capturing the offset between `CLOCK_MONOTONIC` and the steady clock once and applying it. Slice durations were already correct (both endpoints live in the same domain); only the absolute placement of JS events was wrong, and that is what this fixes. The captured offset is exact while the device is awake and can drift across sleep, which is negligible for short cold-start traces; a fully sleep-proof approach would register a custom Perfetto clock with a `ClockSnapshot` and let `trace_processor` reconcile.
Changelog: [Internal]
Differential Revision: D1077152561 parent 2ff3b81 commit bb860b8
1 file changed
Lines changed: 35 additions & 3 deletions
Lines changed: 35 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
| |||
79 | 84 | | |
80 | 85 | | |
81 | 86 | | |
82 | | - | |
83 | | - | |
84 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
85 | 96 | | |
86 | 97 | | |
87 | 98 | | |
88 | 99 | | |
89 | 100 | | |
90 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
91 | 122 | | |
| 123 | + | |
92 | 124 | | |
93 | 125 | | |
94 | 126 | | |
| |||
0 commit comments