0ad/libraries/source/spidermonkey/patches/FixProfiling.diff
2024-12-30 09:13:06 +01:00

159 lines
5.4 KiB
Diff

# HG changeset patch
# User Markus Stange <mstange.moz@gmail.com>
# Date 1706240334 0
# Node ID a412d893c38f632f34b44a9c5b3fd8cc30bb87be
# Parent 2a507cc2cf84980ce9f160d1ef80107ee7474ae4
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
diff --git a/js/src/jit/PerfSpewer.cpp b/js/src/jit/PerfSpewer.cpp
--- a/js/src/jit/PerfSpewer.cpp
+++ b/js/src/jit/PerfSpewer.cpp
@@ -118,19 +118,26 @@ static bool IsPerfProfiling() { return J
#endif
AutoLockPerfSpewer::AutoLockPerfSpewer() { PerfMutex.lock(); }
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
static uint32_t GetMachineEncoding() {
# if defined(JS_CODEGEN_X86)
return 3; // EM_386
# elif defined(JS_CODEGEN_X64)
return 62; // EM_X86_64
diff --git a/mozglue/misc/TimeStamp.h b/mozglue/misc/TimeStamp.h
--- a/mozglue/misc/TimeStamp.h
+++ b/mozglue/misc/TimeStamp.h
@@ -469,18 +469,19 @@ class TimeStamp {
static MFBT_API void RecordProcessRestart();
#ifdef XP_LINUX
uint64_t RawClockMonotonicNanosecondsSinceBoot() {
return static_cast<uint64_t>(mValue);
}
#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
Maybe<uint64_t> RawQueryPerformanceCounterValue() {
// mQPC is stored in `mt` i.e. QueryPerformanceCounter * 1000
// so divide out the 1000
return mValue.mHasQPC ? Some(mValue.mQPC / 1000ULL) : Nothing();
}
diff --git a/mozglue/misc/TimeStamp_darwin.cpp b/mozglue/misc/TimeStamp_darwin.cpp
--- a/mozglue/misc/TimeStamp_darwin.cpp
+++ b/mozglue/misc/TimeStamp_darwin.cpp
@@ -131,26 +131,28 @@ void TimeStamp::Startup() {
// find the number of significant digits in sResolution, for the
// sake of ToSecondsSigDigits()
for (sResolutionSigDigs = 1; !(sResolutionSigDigs == sResolution ||
10 * sResolutionSigDigs > sResolution);
sResolutionSigDigs *= 10)
;
gInitialized = true;
-
- return;
}
void TimeStamp::Shutdown() {}
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() {
struct timeval tv;
int rv = gettimeofday(&tv, nullptr);
if (rv == -1) {
return 0;
diff --git a/mozglue/misc/moz.build b/mozglue/misc/moz.build
--- a/mozglue/misc/moz.build
+++ b/mozglue/misc/moz.build
@@ -105,24 +105,24 @@ if CONFIG["OS_ARCH"] == "WINNT":
if not CONFIG["JS_STANDALONE"]:
SOURCES += [
"/ipc/mscom/COMWrappers.cpp",
"/ipc/mscom/ProcessRuntime.cpp",
"PreXULSkeletonUI.cpp",
]
+elif CONFIG["OS_ARCH"] == "Darwin":
+ SOURCES += [
+ "TimeStamp_darwin.cpp",
+ ]
elif CONFIG["HAVE_CLOCK_MONOTONIC"]:
SOURCES += [
"TimeStamp_posix.cpp",
]
-elif CONFIG["OS_ARCH"] == "Darwin":
- SOURCES += [
- "TimeStamp_darwin.cpp",
- ]
elif CONFIG["COMPILE_ENVIRONMENT"]:
error("No TimeStamp implementation on this platform. Build will not succeed")
if CONFIG["OS_ARCH"] == "WINNT":
SOURCES += [
"ConditionVariable_windows.cpp",
"Mutex_windows.cpp",
"RWLock_windows.cpp",