diff --git a/tools/profiler/core/Sampler.cpp b/tools/profiler/core/Sampler.cpp index afe15da6f5d6..adb35661c9d6 100644 --- a/tools/profiler/core/Sampler.cpp +++ b/tools/profiler/core/Sampler.cpp @@ -170,7 +170,7 @@ Sampler::Sampler() for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) { ThreadInfo* info = sRegisteredThreads->at(i); - RegisterThread(info); + MaybeSetProfile(info); } } @@ -530,42 +530,3 @@ void PseudoStack::flushSamplerOnJSShutdown() // END SaveProfileTask et al //////////////////////////////////////////////////////////////////////// -static bool -ThreadSelected(const char* aThreadName) -{ - StaticMutexAutoLock lock(gThreadNameFiltersMutex); - - if (gThreadNameFilters.empty()) { - return true; - } - - std::string name = aThreadName; - std::transform(name.begin(), name.end(), name.begin(), ::tolower); - - for (uint32_t i = 0; i < gThreadNameFilters.length(); ++i) { - std::string filter = gThreadNameFilters[i]; - std::transform(filter.begin(), filter.end(), filter.begin(), ::tolower); - - // Crude, non UTF-8 compatible, case insensitive substring search - if (name.find(filter) != std::string::npos) { - return true; - } - } - - return false; -} - -void -Sampler::RegisterThread(ThreadInfo* aInfo) -{ - if (!aInfo->IsMainThread() && !gProfileThreads) { - return; - } - - if (!ThreadSelected(aInfo->Name())) { - return; - } - - aInfo->SetProfile(gBuffer); -} - diff --git a/tools/profiler/core/platform.cpp b/tools/profiler/core/platform.cpp index 753c2e2f96ce..a255051bd35b 100644 --- a/tools/profiler/core/platform.cpp +++ b/tools/profiler/core/platform.cpp @@ -1167,6 +1167,40 @@ GeckoProfilerReporter::CollectReports(nsIHandleReportCallback* aHandleReport, NS_IMPL_ISUPPORTS(GeckoProfilerReporter, nsIMemoryReporter) +static bool +ThreadSelected(const char* aThreadName) +{ + StaticMutexAutoLock lock(gThreadNameFiltersMutex); + + if (gThreadNameFilters.empty()) { + return true; + } + + std::string name = aThreadName; + std::transform(name.begin(), name.end(), name.begin(), ::tolower); + + for (uint32_t i = 0; i < gThreadNameFilters.length(); ++i) { + std::string filter = gThreadNameFilters[i]; + std::transform(filter.begin(), filter.end(), filter.begin(), ::tolower); + + // Crude, non UTF-8 compatible, case insensitive substring search + if (name.find(filter) != std::string::npos) { + return true; + } + } + + return false; +} + +static void +MaybeSetProfile(ThreadInfo* aInfo) +{ + if ((aInfo->IsMainThread() || gProfileThreads) && + ThreadSelected(aInfo->Name())) { + aInfo->SetProfile(gBuffer); + } +} + static void RegisterCurrentThread(const char* aName, PseudoStack* aPseudoStack, bool aIsMainThread, void* stackTop) @@ -1192,10 +1226,7 @@ RegisterCurrentThread(const char* aName, PseudoStack* aPseudoStack, ThreadInfo* info = new ThreadInfo(aName, id, aIsMainThread, aPseudoStack, stackTop); - // XXX: this is an off-main-thread use of gSampler - if (gSampler) { - gSampler->RegisterThread(info); - } + MaybeSetProfile(info); sRegisteredThreads->push_back(info); } @@ -1586,7 +1617,7 @@ profiler_start(int aProfileEntries, double aInterval, profiler_stop(); // Deep copy aThreadNameFilters. Must happen before Sampler's constructor - // calls RegisterThread(). + // calls MaybeSetProfile(). { StaticMutexAutoLock lock(gThreadNameFiltersMutex); diff --git a/tools/profiler/core/platform.h b/tools/profiler/core/platform.h index c4488b68b284..410e1c35b60b 100644 --- a/tools/profiler/core/platform.h +++ b/tools/profiler/core/platform.h @@ -221,8 +221,6 @@ public: Sampler(); ~Sampler(); - void RegisterThread(ThreadInfo* aInfo); - void ToStreamAsJSON(std::ostream& stream, double aSinceTime = 0); JSObject *ToJSObject(JSContext *aCx, double aSinceTime = 0); mozilla::UniquePtr ToJSON(double aSinceTime = 0);