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
This commit is contained in:
Markus Stange 2024-01-26 03:38:54 +00:00
parent 2dd0f93ca6
commit b75080bb8b
5 changed files with 23 additions and 13 deletions

View File

@ -615,8 +615,8 @@ void Performance::MaybeEmitExternalProfilerMarker(
uint64_t rawStart = startTimeStamp.RawQueryPerformanceCounterValue().value();
uint64_t rawEnd = endTimeStamp.RawQueryPerformanceCounterValue().value();
#elif XP_MACOSX
uint64_t rawStart = startTimeStamp.RawMachAbsoluteTimeValue();
uint64_t rawEnd = endTimeStamp.RawMachAbsoluteTimeValue();
uint64_t rawStart = startTimeStamp.RawMachAbsoluteTimeNanoseconds();
uint64_t rawEnd = endTimeStamp.RawMachAbsoluteTimeNanoseconds();
#else
uint64_t rawStart = 0;
uint64_t rawEnd = 0;

View File

@ -123,9 +123,16 @@ AutoLockPerfSpewer::~AutoLockPerfSpewer() { PerfMutex.unlock(); }
#ifdef JS_ION_PERF
static uint64_t GetMonotonicTimestamp() {
struct timespec ts = {};
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec * 1000000000 + ts.tv_nsec;
using mozilla::TimeStamp;
# ifdef XP_LINUX
return TimeStamp::Now().RawClockMonotonicNanosecondsSinceBoot();
# elif XP_WIN
return TimeStamp::Now().RawQueryPerformanceCounterValue().value();
# elif XP_MACOSX
return TimeStamp::Now().RawMachAbsoluteTimeNanoseconds();
# else
MOZ_CRASH("no timestamp");
# endif
}
// values are from /usr/include/elf.h

View File

@ -474,8 +474,9 @@ class TimeStamp {
}
#endif
#ifdef XP_MACOSX
uint64_t RawMachAbsoluteTimeValue() { return static_cast<uint64_t>(mValue); }
#ifdef XP_DARWIN
// Returns the number of nanoseconds since the mach_absolute_time origin.
MFBT_API uint64_t RawMachAbsoluteTimeNanoseconds() const;
#endif
#ifdef XP_WIN

View File

@ -136,8 +136,6 @@ void TimeStamp::Startup() {
;
gInitialized = true;
return;
}
void TimeStamp::Shutdown() {}
@ -146,6 +144,10 @@ TimeStamp TimeStamp::Now(bool aHighResolution) {
return TimeStamp(ClockTime());
}
uint64_t TimeStamp::RawMachAbsoluteTimeNanoseconds() const {
return static_cast<uint64_t>(double(mValue) * sNsPerTick);
}
// Computes and returns the process uptime in microseconds.
// Returns 0 if an error was encountered.
uint64_t TimeStamp::ComputeProcessUptime() {

View File

@ -110,14 +110,14 @@ if CONFIG["OS_ARCH"] == "WINNT":
"PreXULSkeletonUI.cpp",
]
elif CONFIG["HAVE_CLOCK_MONOTONIC"]:
SOURCES += [
"TimeStamp_posix.cpp",
]
elif CONFIG["OS_ARCH"] == "Darwin":
SOURCES += [
"TimeStamp_darwin.cpp",
]
elif CONFIG["HAVE_CLOCK_MONOTONIC"]:
SOURCES += [
"TimeStamp_posix.cpp",
]
elif CONFIG["COMPILE_ENVIRONMENT"]:
error("No TimeStamp implementation on this platform. Build will not succeed")