mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 16:22:00 +00:00
Bug 1642726 - maybelocked_profiler_add_marker_for_thread - r=gregtatum
This function can be called whether the profiler mutex is locked or not. If locked, the provided pointer to the profiler mutex is used internally, otherwise the mutex will be locked as needed. Differential Revision: https://phabricator.services.mozilla.com/D79412
This commit is contained in:
parent
b834db3337
commit
8c64fc6990
@ -3496,12 +3496,9 @@ void profiler_add_js_marker(const char* aMarkerName) {
|
||||
profiler_add_marker(aMarkerName, ProfilingCategoryPair::JS);
|
||||
}
|
||||
|
||||
// This logic needs to add a marker for a different thread, so we actually need
|
||||
// to lock here.
|
||||
void profiler_add_marker_for_thread(int aThreadId,
|
||||
ProfilingCategoryPair aCategoryPair,
|
||||
const char* aMarkerName,
|
||||
const ProfilerMarkerPayload& aPayload) {
|
||||
static void maybelocked_profiler_add_marker_for_thread(
|
||||
int aThreadId, ProfilingCategoryPair aCategoryPair, const char* aMarkerName,
|
||||
const ProfilerMarkerPayload& aPayload, const PSAutoLock* aLockOrNull) {
|
||||
MOZ_RELEASE_ASSERT(CorePS::Exists());
|
||||
|
||||
if (!profiler_can_accept_markers()) {
|
||||
@ -3509,16 +3506,15 @@ void profiler_add_marker_for_thread(int aThreadId,
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
PSAutoLock lock;
|
||||
if (!ActivePS::Exists(lock)) {
|
||||
auto checkThreadId = [](int aThreadId, const PSAutoLock& aLock) {
|
||||
if (!ActivePS::Exists(aLock)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Assert that our thread ID makes sense
|
||||
bool realThread = false;
|
||||
const Vector<UniquePtr<RegisteredThread>>& registeredThreads =
|
||||
CorePS::RegisteredThreads(lock);
|
||||
CorePS::RegisteredThreads(aLock);
|
||||
for (auto& thread : registeredThreads) {
|
||||
RefPtr<ThreadInfo> info = thread->Info();
|
||||
if (info->ThreadId() == aThreadId) {
|
||||
@ -3527,6 +3523,13 @@ void profiler_add_marker_for_thread(int aThreadId,
|
||||
}
|
||||
}
|
||||
MOZ_ASSERT(realThread, "Invalid thread id");
|
||||
};
|
||||
|
||||
if (aLockOrNull) {
|
||||
checkThreadId(aThreadId, *aLockOrNull);
|
||||
} else {
|
||||
PSAutoLock lock;
|
||||
checkThreadId(aThreadId, lock);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -3541,6 +3544,14 @@ void profiler_add_marker_for_thread(int aThreadId,
|
||||
static_cast<uint32_t>(aCategoryPair), &aPayload, delta.ToMilliseconds());
|
||||
}
|
||||
|
||||
void profiler_add_marker_for_thread(int aThreadId,
|
||||
ProfilingCategoryPair aCategoryPair,
|
||||
const char* aMarkerName,
|
||||
const ProfilerMarkerPayload& aPayload) {
|
||||
return maybelocked_profiler_add_marker_for_thread(
|
||||
aThreadId, aCategoryPair, aMarkerName, aPayload, nullptr);
|
||||
}
|
||||
|
||||
void profiler_add_marker_for_mainthread(ProfilingCategoryPair aCategoryPair,
|
||||
const char* aMarkerName,
|
||||
const ProfilerMarkerPayload& aPayload) {
|
||||
|
@ -5076,10 +5076,10 @@ void profiler_add_network_marker(
|
||||
std::move(aSource), aContentType));
|
||||
}
|
||||
|
||||
void profiler_add_marker_for_thread(int aThreadId,
|
||||
JS::ProfilingCategoryPair aCategoryPair,
|
||||
const char* aMarkerName,
|
||||
const ProfilerMarkerPayload& aPayload) {
|
||||
static void maybelocked_profiler_add_marker_for_thread(
|
||||
int aThreadId, JS::ProfilingCategoryPair aCategoryPair,
|
||||
const char* aMarkerName, const ProfilerMarkerPayload& aPayload,
|
||||
const PSAutoLock* aLockOrNull) {
|
||||
MOZ_RELEASE_ASSERT(CorePS::Exists());
|
||||
|
||||
if (!profiler_can_accept_markers()) {
|
||||
@ -5087,16 +5087,15 @@ void profiler_add_marker_for_thread(int aThreadId,
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
PSAutoLock lock(gPSMutex);
|
||||
if (!ActivePS::Exists(lock)) {
|
||||
auto checkThreadId = [](int aThreadId, const PSAutoLock& aLock) {
|
||||
if (!ActivePS::Exists(aLock)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Assert that our thread ID makes sense
|
||||
bool realThread = false;
|
||||
const Vector<UniquePtr<RegisteredThread>>& registeredThreads =
|
||||
CorePS::RegisteredThreads(lock);
|
||||
CorePS::RegisteredThreads(aLock);
|
||||
for (auto& thread : registeredThreads) {
|
||||
RefPtr<ThreadInfo> info = thread->Info();
|
||||
if (info->ThreadId() == aThreadId) {
|
||||
@ -5105,6 +5104,13 @@ void profiler_add_marker_for_thread(int aThreadId,
|
||||
}
|
||||
}
|
||||
MOZ_ASSERT(realThread, "Invalid thread id");
|
||||
};
|
||||
|
||||
if (aLockOrNull) {
|
||||
checkThreadId(aThreadId, *aLockOrNull);
|
||||
} else {
|
||||
PSAutoLock lock(gPSMutex);
|
||||
checkThreadId(aThreadId, lock);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -5118,6 +5124,14 @@ void profiler_add_marker_for_thread(int aThreadId,
|
||||
static_cast<uint32_t>(aCategoryPair), &aPayload, delta.ToMilliseconds());
|
||||
}
|
||||
|
||||
void profiler_add_marker_for_thread(int aThreadId,
|
||||
JS::ProfilingCategoryPair aCategoryPair,
|
||||
const char* aMarkerName,
|
||||
const ProfilerMarkerPayload& aPayload) {
|
||||
return maybelocked_profiler_add_marker_for_thread(
|
||||
aThreadId, aCategoryPair, aMarkerName, aPayload, nullptr);
|
||||
}
|
||||
|
||||
void profiler_add_marker_for_mainthread(JS::ProfilingCategoryPair aCategoryPair,
|
||||
const char* aMarkerName,
|
||||
const ProfilerMarkerPayload& aPayload) {
|
||||
|
Loading…
Reference in New Issue
Block a user