Skip to content

Commit b75080b

Browse files
committed
Bug 1876415 - Make timestamp formats consistent between Jitdump and the marker file. r=glandium
On Linux and Android, both jitdump and the marker file will keep using `CLOCK_MONOTONIC` nanoseconds, as before. On macOS, both jitdump and the marker file will now be using `TimeStamp::RawMachAbsoluteTimeNanoseconds()` , i.e. "nanoseconds since mach_absolute_time origin". This value has the advantage that it is also relatively easy to obtain in other browser engines, because their internal timestamp value is stored in milliseconds or nanoseconds rather than in `mach_absolute_time` ticks. In the past, on macOS, Firefox was using `CLOCK_MONOTONIC` nanoseconds for jitdump and `TimeStamp::RawMachAbsoluteTimeValue()` for the marker file. This inconsistency is now fixed. I will update samply to change how it treats jitdump timestamps on macOS. There are no other consumers of jitdump files on macOS that I know of. On Windows, we will keep using raw QPC values for the marker file - this matches what's in the ETW events. Jitdump on Windows is mostly unused but I'm updating it to match. Furthermore, this fixes the order in mozglue/misc/moz.build to make sure we always use the TimeStamp_darwin implementation on Darwin (and not just due to a broken configure check, see bug 1681445), and it fixes the #ifdef in TimeStamp.h to match the Darwin check. Differential Revision: https://phabricator.services.mozilla.com/D199592
1 parent 2dd0f93 commit b75080b

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

dom/performance/Performance.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,8 @@ void Performance::MaybeEmitExternalProfilerMarker(
615615
uint64_t rawStart = startTimeStamp.RawQueryPerformanceCounterValue().value();
616616
uint64_t rawEnd = endTimeStamp.RawQueryPerformanceCounterValue().value();
617617
#elif XP_MACOSX
618-
uint64_t rawStart = startTimeStamp.RawMachAbsoluteTimeValue();
619-
uint64_t rawEnd = endTimeStamp.RawMachAbsoluteTimeValue();
618+
uint64_t rawStart = startTimeStamp.RawMachAbsoluteTimeNanoseconds();
619+
uint64_t rawEnd = endTimeStamp.RawMachAbsoluteTimeNanoseconds();
620620
#else
621621
uint64_t rawStart = 0;
622622
uint64_t rawEnd = 0;

js/src/jit/PerfSpewer.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,16 @@ AutoLockPerfSpewer::~AutoLockPerfSpewer() { PerfMutex.unlock(); }
123123

124124
#ifdef JS_ION_PERF
125125
static uint64_t GetMonotonicTimestamp() {
126-
struct timespec ts = {};
127-
clock_gettime(CLOCK_MONOTONIC, &ts);
128-
return ts.tv_sec * 1000000000 + ts.tv_nsec;
126+
using mozilla::TimeStamp;
127+
# ifdef XP_LINUX
128+
return TimeStamp::Now().RawClockMonotonicNanosecondsSinceBoot();
129+
# elif XP_WIN
130+
return TimeStamp::Now().RawQueryPerformanceCounterValue().value();
131+
# elif XP_MACOSX
132+
return TimeStamp::Now().RawMachAbsoluteTimeNanoseconds();
133+
# else
134+
MOZ_CRASH("no timestamp");
135+
# endif
129136
}
130137

131138
// values are from /usr/include/elf.h

mozglue/misc/TimeStamp.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,9 @@ class TimeStamp {
474474
}
475475
#endif
476476

477-
#ifdef XP_MACOSX
478-
uint64_t RawMachAbsoluteTimeValue() { return static_cast<uint64_t>(mValue); }
477+
#ifdef XP_DARWIN
478+
// Returns the number of nanoseconds since the mach_absolute_time origin.
479+
MFBT_API uint64_t RawMachAbsoluteTimeNanoseconds() const;
479480
#endif
480481

481482
#ifdef XP_WIN

mozglue/misc/TimeStamp_darwin.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ void TimeStamp::Startup() {
136136
;
137137

138138
gInitialized = true;
139-
140-
return;
141139
}
142140

143141
void TimeStamp::Shutdown() {}
@@ -146,6 +144,10 @@ TimeStamp TimeStamp::Now(bool aHighResolution) {
146144
return TimeStamp(ClockTime());
147145
}
148146

147+
uint64_t TimeStamp::RawMachAbsoluteTimeNanoseconds() const {
148+
return static_cast<uint64_t>(double(mValue) * sNsPerTick);
149+
}
150+
149151
// Computes and returns the process uptime in microseconds.
150152
// Returns 0 if an error was encountered.
151153
uint64_t TimeStamp::ComputeProcessUptime() {

mozglue/misc/moz.build

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ if CONFIG["OS_ARCH"] == "WINNT":
110110
"PreXULSkeletonUI.cpp",
111111
]
112112

113-
elif CONFIG["HAVE_CLOCK_MONOTONIC"]:
114-
SOURCES += [
115-
"TimeStamp_posix.cpp",
116-
]
117113
elif CONFIG["OS_ARCH"] == "Darwin":
118114
SOURCES += [
119115
"TimeStamp_darwin.cpp",
120116
]
117+
elif CONFIG["HAVE_CLOCK_MONOTONIC"]:
118+
SOURCES += [
119+
"TimeStamp_posix.cpp",
120+
]
121121
elif CONFIG["COMPILE_ENVIRONMENT"]:
122122
error("No TimeStamp implementation on this platform. Build will not succeed")
123123

0 commit comments

Comments
 (0)