Bug 1337189 (part 16) - Move all the bools out of Sampler. r=mstange.

Two of them (mAddMainThreadIO and mPrivacyMode) are now local variables within
profiler_start(), which is nice.

This change also lets us get rid of four sIs* variables.
This commit is contained in:
Nicholas Nethercote 2017-02-08 12:01:41 +11:00
Родитель 7cad4eb2a3
Коммит 8796cadf65
6 изменённых файлов: 91 добавлений и 99 удалений

Просмотреть файл

@ -188,43 +188,10 @@ GetSharedLibraryInfoStringInternal()
return os.str();
}
static bool
hasFeature(const char** aFeatures, uint32_t aFeatureCount, const char* aFeature) {
for(size_t i = 0; i < aFeatureCount; i++) {
if (strcmp(aFeatures[i], aFeature) == 0)
return true;
}
return false;
}
Sampler::Sampler(const char** aFeatures, uint32_t aFeatureCount,
uint32_t aFilterCount)
Sampler::Sampler()
{
MOZ_COUNT_CTOR(Sampler);
mUseStackWalk = hasFeature(aFeatures, aFeatureCount, "stackwalk");
mProfileJS = hasFeature(aFeatures, aFeatureCount, "js");
mProfileGPU = hasFeature(aFeatures, aFeatureCount, "gpu");
// Users sometimes ask to filter by a list of threads but forget to request
// profiling non main threads. Let's make it implificit if we have a filter
mProfileThreads = hasFeature(aFeatures, aFeatureCount, "threads") || aFilterCount > 0;
mAddLeafAddresses = hasFeature(aFeatures, aFeatureCount, "leaf");
mPrivacyMode = hasFeature(aFeatures, aFeatureCount, "privacy");
mAddMainThreadIO = hasFeature(aFeatures, aFeatureCount, "mainthreadio");
mProfileMemory = hasFeature(aFeatures, aFeatureCount, "memory");
mTaskTracer = hasFeature(aFeatures, aFeatureCount, "tasktracer");
mLayersDump = hasFeature(aFeatures, aFeatureCount, "layersdump");
mDisplayListDump = hasFeature(aFeatures, aFeatureCount, "displaylistdump");
mProfileRestyle = hasFeature(aFeatures, aFeatureCount, "restyle");
#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
mProfileJava = mozilla::jni::IsFennec() &&
hasFeature(aFeatures, aFeatureCount, "java");
#else
mProfileJava = false;
#endif
bool ignore;
sStartTime = mozilla::TimeStamp::ProcessCreation(ignore);
@ -319,9 +286,11 @@ Sampler::StreamTaskTracer(SpliceableJSONWriter& aWriter)
void
Sampler::StreamMetaJSCustomObject(SpliceableJSONWriter& aWriter)
{
MOZ_RELEASE_ASSERT(NS_IsMainThread());
aWriter.IntProperty("version", 3);
aWriter.DoubleProperty("interval", gInterval);
aWriter.IntProperty("stackwalk", mUseStackWalk);
aWriter.IntProperty("stackwalk", gUseStackWalk);
#ifdef DEBUG
aWriter.IntProperty("debug", 1);
@ -495,7 +464,7 @@ Sampler::StreamJSON(SpliceableJSONWriter& aWriter, double aSinceTime)
aWriter.EndObject();
// Data of TaskTracer doesn't belong in the circular buffer.
if (TaskTracer()) {
if (gTaskTracer) {
aWriter.StartObjectProperty("tasktracer");
StreamTaskTracer(aWriter);
aWriter.EndObject();
@ -537,7 +506,7 @@ Sampler::StreamJSON(SpliceableJSONWriter& aWriter, double aSinceTime)
}
#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
if (ProfileJava()) {
if (gProfileJava) {
java::GeckoJavaSampler::Pause();
aWriter.Start();
@ -1162,13 +1131,13 @@ Sampler::InplaceTick(TickSample* sample)
#if defined(USE_NS_STACKWALK) || defined(USE_EHABI_STACKWALK) || \
defined(USE_LUL_STACKWALK)
if (mUseStackWalk) {
if (gUseStackWalk) {
doNativeBacktrace(currThreadInfo, sample);
} else {
doSampleStackTrace(currThreadInfo, sample, mAddLeafAddresses);
doSampleStackTrace(currThreadInfo, sample, gAddLeafAddresses);
}
#else
doSampleStackTrace(currThreadInfo, sample, mAddLeafAddresses);
doSampleStackTrace(currThreadInfo, sample, gAddLeafAddresses);
#endif
// Don't process the PeudoStack's markers if we're
@ -1274,7 +1243,7 @@ ThreadSelected(const char* aThreadName)
void
Sampler::RegisterThread(ThreadInfo* aInfo)
{
if (!aInfo->IsMainThread() && !mProfileThreads) {
if (!aInfo->IsMainThread() && !gProfileThreads) {
return;
}

Просмотреть файл

@ -239,8 +239,7 @@ void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
static void
ProfilerSignalThread(ThreadInfo* aInfo, bool aIsFirstProfiledThread)
{
// XXX: this is an off-main-thread(?) use of gSampler
if (aIsFirstProfiledThread && gSampler->ProfileMemory()) {
if (aIsFirstProfiledThread && gProfileMemory) {
aInfo->mRssMemory = nsMemoryReporterManager::ResidentFast();
aInfo->mUssMemory = nsMemoryReporterManager::ResidentUnique();
} else {

Просмотреть файл

@ -205,8 +205,7 @@ public:
sample->ussMemory = 0;
sample->rssMemory = 0;
// XXX: this is an off-main-thread use of gSampler
if (isFirstProfiledThread && gSampler->ProfileMemory()) {
if (isFirstProfiledThread && gProfileMemory) {
sample->rssMemory = nsMemoryReporterManager::ResidentFast();
}

Просмотреть файл

@ -217,8 +217,7 @@ class SamplerThread
sample->timestamp = mozilla::TimeStamp::Now();
sample->threadInfo = aThreadInfo;
// XXX: this is an off-main-thread use of gSampler
if (isFirstProfiledThread && gSampler->ProfileMemory()) {
if (isFirstProfiledThread && gProfileMemory) {
sample->rssMemory = nsMemoryReporterManager::ResidentFast();
} else {
sample->rssMemory = 0;

Просмотреть файл

@ -127,10 +127,22 @@ static int gLastFrameNumber = 0;
int sInitCount = 0; // Each init must have a matched shutdown.
static bool sIsProfiling = false; // is raced on
static bool sIsGPUProfiling = false; // is raced on
static bool sIsLayersDump = false; // is raced on
static bool sIsDisplayListDump = false; // is raced on
static bool sIsRestyleProfiling = false; // is raced on
// All accesses to these are on the main thread, so no locking is needed.
static bool gProfileJava = false;
static bool gProfileJS = false;
static bool gTaskTracer = false;
// XXX: These are all accessed by multiple threads and might require more
// inter-thread synchronization than they currently have.
static Atomic<bool> gAddLeafAddresses(false);
static Atomic<bool> gDisplayListDump(false);
static Atomic<bool> gLayersDump(false);
static Atomic<bool> gProfileGPU(false);
static Atomic<bool> gProfileMemory(false);
static Atomic<bool> gProfileRestyle(false);
static Atomic<bool> gProfileThreads(false);
static Atomic<bool> gUseStackWalk(false);
// Environment variables to control the profiler
const char* PROFILER_HELP = "MOZ_PROFILER_HELP";
@ -839,6 +851,17 @@ profiler_get_buffer_info_helper(uint32_t *aCurrentPosition,
*aGeneration = gBuffer->mGeneration;
}
static bool
hasFeature(const char** aFeatures, uint32_t aFeatureCount, const char* aFeature)
{
for (size_t i = 0; i < aFeatureCount; i++) {
if (strcmp(aFeatures[i], aFeature) == 0) {
return true;
}
}
return false;
}
// Values are only honored on the first start
void
profiler_start(int aProfileEntries, double aInterval,
@ -885,14 +908,38 @@ profiler_start(int aProfileEntries, double aInterval,
gEntrySize = aProfileEntries ? aProfileEntries : PROFILE_DEFAULT_ENTRY;
gInterval = aInterval ? aInterval : PROFILE_DEFAULT_INTERVAL;
gBuffer = new ProfileBuffer(gEntrySize);
gSampler = new Sampler(aFeatures, aFeatureCount, aFilterCount);
gSampler = new Sampler();
gGatherer = new mozilla::ProfileGatherer(gSampler);
bool mainThreadIO = hasFeature(aFeatures, aFeatureCount, "mainthreadio");
bool privacyMode = hasFeature(aFeatures, aFeatureCount, "privacy");
#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
gProfileJava = mozilla::jni::IsFennec() &&
hasFeature(aFeatures, aFeatureCount, "java");
#else
gProfileJava = false;
#endif
gProfileJS = hasFeature(aFeatures, aFeatureCount, "js");
gTaskTracer = hasFeature(aFeatures, aFeatureCount, "tasktracer");
gAddLeafAddresses = hasFeature(aFeatures, aFeatureCount, "leaf");
gDisplayListDump = hasFeature(aFeatures, aFeatureCount, "displaylistdump");
gLayersDump = hasFeature(aFeatures, aFeatureCount, "layersdump");
gProfileGPU = hasFeature(aFeatures, aFeatureCount, "gpu");
gProfileMemory = hasFeature(aFeatures, aFeatureCount, "memory");
gProfileRestyle = hasFeature(aFeatures, aFeatureCount, "restyle");
// Profile non-main threads if we have a filter, because users sometimes ask
// to filter by a list of threads but forget to explicitly request.
gProfileThreads = hasFeature(aFeatures, aFeatureCount, "threads") ||
aFilterCount > 0;
gUseStackWalk = hasFeature(aFeatures, aFeatureCount, "stackwalk");
MOZ_ASSERT(!gIsActive && !gIsPaused);
gSampler->Start();
MOZ_ASSERT(gIsActive && !gIsPaused); // Start() sets gIsActive.
if (gSampler->ProfileJS() || gSampler->InPrivacyMode()) {
if (gProfileJS || privacyMode) {
mozilla::StaticMutexAutoLock lock(sRegisteredThreadsMutex);
for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) {
@ -901,17 +948,17 @@ profiler_start(int aProfileEntries, double aInterval,
continue;
}
info->Stack()->reinitializeOnResume();
if (gSampler->ProfileJS()) {
if (gProfileJS) {
info->Stack()->enableJSSampling();
}
if (gSampler->InPrivacyMode()) {
if (privacyMode) {
info->Stack()->mPrivacyMode = true;
}
}
}
#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
if (gSampler->ProfileJava()) {
if (gProfileJava) {
int javaInterval = aInterval;
// Java sampling doesn't accuratly keep up with 1ms sampling
if (javaInterval < 10) {
@ -921,7 +968,7 @@ profiler_start(int aProfileEntries, double aInterval,
}
#endif
if (gSampler->AddMainThreadIO()) {
if (mainThreadIO) {
if (!sInterposeObserver) {
// Lazily create IO interposer observer
sInterposeObserver = new mozilla::ProfilerIOInterposeObserver();
@ -931,10 +978,6 @@ profiler_start(int aProfileEntries, double aInterval,
}
sIsProfiling = true;
sIsGPUProfiling = gSampler->ProfileGPU();
sIsLayersDump = gSampler->LayersDump();
sIsDisplayListDump = gSampler->DisplayListDump();
sIsRestyleProfiling = gSampler->ProfileRestyle();
if (Sampler::CanNotifyObservers()) {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
@ -976,7 +1019,7 @@ profiler_stop()
return;
}
bool disableJS = gSampler->ProfileJS();
bool disableJS = gProfileJS;
{
StaticMutexAutoLock lock(gThreadNameFiltersMutex);
@ -986,6 +1029,20 @@ profiler_stop()
gSampler->Stop();
MOZ_ASSERT(!gIsActive && !gIsPaused); // Stop() clears these.
gProfileJava = false;
gProfileJS = false;
gTaskTracer = false;
gAddLeafAddresses = false;
gDisplayListDump = false;
gLayersDump = false;
gProfileGPU = false;
gProfileMemory = false;
gProfileRestyle = false;
gProfileThreads = false;
gUseStackWalk = false;
delete gSampler;
gSampler = nullptr;
gBuffer = nullptr;
@ -1007,10 +1064,6 @@ profiler_stop()
sInterposeObserver = nullptr;
sIsProfiling = false;
sIsGPUProfiling = false;
sIsLayersDump = false;
sIsDisplayListDump = false;
sIsRestyleProfiling = false;
if (Sampler::CanNotifyObservers()) {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
@ -1074,24 +1127,24 @@ profiler_feature_active(const char* aName)
{
// This function runs both on and off the main thread.
if (!profiler_is_active()) {
if (!sIsProfiling) {
return false;
}
if (strcmp(aName, "gpu") == 0) {
return sIsGPUProfiling;
return gProfileGPU;
}
if (strcmp(aName, "layersdump") == 0) {
return sIsLayersDump;
return gLayersDump;
}
if (strcmp(aName, "displaylistdump") == 0) {
return sIsDisplayListDump;
return gDisplayListDump;
}
if (strcmp(aName, "restyle") == 0) {
return sIsRestyleProfiling;
return gProfileRestyle;
}
return false;

Просмотреть файл

@ -238,8 +238,7 @@ class Promise;
class Sampler {
public:
// Initialize sampler.
Sampler(const char** aFeatures, uint32_t aFeatureCount,
uint32_t aFilterCount);
Sampler();
~Sampler();
// This method is called for each sampling period with the current
@ -286,18 +285,6 @@ public:
void RegisterThread(ThreadInfo* aInfo);
bool ProfileJS() const { return mProfileJS; }
bool ProfileJava() const { return mProfileJava; }
bool ProfileGPU() const { return mProfileGPU; }
bool ProfileThreads() const { return mProfileThreads; }
bool InPrivacyMode() const { return mPrivacyMode; }
bool AddMainThreadIO() const { return mAddMainThreadIO; }
bool ProfileMemory() const { return mProfileMemory; }
bool TaskTracer() const { return mTaskTracer; }
bool LayersDump() const { return mLayersDump; }
bool DisplayListDump() const { return mDisplayListDump; }
bool ProfileRestyle() const { return mProfileRestyle; }
void ToStreamAsJSON(std::ostream& stream, double aSinceTime = 0);
JSObject *ToJSObject(JSContext *aCx, double aSinceTime = 0);
mozilla::UniquePtr<char[]> ToJSON(double aSinceTime = 0);
@ -315,20 +302,6 @@ private:
// Called within a signal. This function must be reentrant
void InplaceTick(TickSample* sample);
bool mAddLeafAddresses;
bool mUseStackWalk;
bool mProfileJS;
bool mProfileGPU;
bool mProfileThreads;
bool mProfileJava;
bool mLayersDump;
bool mDisplayListDump;
bool mProfileRestyle;
bool mPrivacyMode;
bool mAddMainThreadIO;
bool mProfileMemory;
bool mTaskTracer;
};
#endif /* ndef TOOLS_PLATFORM_H_ */