зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1573273: Add ProfilerLabelBegin and ProfilerLabelEnd to mozglue; r=gerald
While mozglue continues to be the correct location for calling the affected code in this patch, the calls requiring profiler labels will soon be originating from firefox.exe via the launcher process. mozglue will be supplying the launcher process with an interface that consists of what are effectively "OnBeginDllLoad" and "OnEndDllLoad" callback notifications; obviously an RAII class is not going to be useful for that case. We still want to keep the RAII stuff around, however, since we still need it for cases where we need to fall back to using the legacy DLL blocklist. Differential Revision: https://phabricator.services.mozilla.com/D41807 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
097aa52411
Коммит
a69086ea54
|
@ -30,6 +30,8 @@ class MOZ_RAII AutoProfilerLabelData {
|
|||
const uint32_t& GenerationCRef() const { return sGeneration; }
|
||||
uint32_t& GenerationRef() { return sGeneration; }
|
||||
|
||||
static bool RacyIsProfilerPresent() { return !!sGeneration; }
|
||||
|
||||
private:
|
||||
// Thin shell around mozglue PlatformMutex, for local internal use.
|
||||
// Does not preserve behavior in JS record/replay.
|
||||
|
@ -69,26 +71,43 @@ void RegisterProfilerLabelEnterExit(ProfilerLabelEnter aEnter,
|
|||
++data.GenerationRef();
|
||||
}
|
||||
|
||||
bool IsProfilerPresent() {
|
||||
return AutoProfilerLabelData::RacyIsProfilerPresent();
|
||||
}
|
||||
|
||||
ProfilerLabel ProfilerLabelBegin(const char* aLabelName,
|
||||
const char* aDynamicString, void* aSp) {
|
||||
const AutoProfilerLabelData data;
|
||||
void* entryContext = (data.EnterCRef())
|
||||
? data.EnterCRef()(aLabelName, aDynamicString, aSp)
|
||||
: nullptr;
|
||||
uint32_t generation = data.GenerationCRef();
|
||||
|
||||
return MakeTuple(entryContext, generation);
|
||||
}
|
||||
|
||||
void ProfilerLabelEnd(const ProfilerLabel& aLabel) {
|
||||
if (!IsValidProfilerLabel(aLabel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const AutoProfilerLabelData data;
|
||||
if (data.ExitCRef() && (Get<1>(aLabel) == data.GenerationCRef())) {
|
||||
data.ExitCRef()(Get<0>(aLabel));
|
||||
}
|
||||
}
|
||||
|
||||
AutoProfilerLabel::AutoProfilerLabel(
|
||||
const char* aLabel,
|
||||
const char* aDynamicString MOZ_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL) {
|
||||
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
||||
|
||||
const AutoProfilerLabelData data;
|
||||
mEntryContext = (data.EnterCRef())
|
||||
? data.EnterCRef()(aLabel, aDynamicString, this)
|
||||
: nullptr;
|
||||
mGeneration = data.GenerationCRef();
|
||||
Tie(mEntryContext, mGeneration) =
|
||||
ProfilerLabelBegin(aLabel, aDynamicString, this);
|
||||
}
|
||||
|
||||
AutoProfilerLabel::~AutoProfilerLabel() {
|
||||
if (!mEntryContext) {
|
||||
return;
|
||||
}
|
||||
const AutoProfilerLabelData data;
|
||||
if (data.ExitCRef() && (mGeneration == data.GenerationCRef())) {
|
||||
data.ExitCRef()(mEntryContext);
|
||||
}
|
||||
ProfilerLabelEnd(MakeTuple(mEntryContext, mGeneration));
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/GuardObjects.h"
|
||||
#include "mozilla/Tuple.h"
|
||||
#include "mozilla/Types.h"
|
||||
|
||||
// The Gecko Profiler defines AutoProfilerLabel, an RAII class for
|
||||
|
@ -54,6 +55,17 @@ class MOZ_RAII AutoProfilerLabel {
|
|||
uint32_t mGeneration;
|
||||
};
|
||||
|
||||
using ProfilerLabel = Tuple<void*, uint32_t>;
|
||||
|
||||
bool IsProfilerPresent();
|
||||
ProfilerLabel ProfilerLabelBegin(const char* aLabelName,
|
||||
const char* aDynamicString, void* aSp);
|
||||
void ProfilerLabelEnd(const ProfilerLabel& aLabel);
|
||||
|
||||
inline bool IsValidProfilerLabel(const ProfilerLabel& aLabel) {
|
||||
return !!Get<0>(aLabel);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
Загрузка…
Ссылка в новой задаче