From 61019f45d124c181c48fe314f3b7bb7518425cc1 Mon Sep 17 00:00:00 2001 From: Benoit Girard Date: Wed, 10 Apr 2013 19:43:20 -0400 Subject: [PATCH] Backout cb37a2ae805f on a CLOSED TREE --- dom/workers/RuntimeService.cpp | 5 -- ipc/chromium/src/base/thread.cc | 5 -- tools/profiler/BreakpadSampler.cpp | 15 ++--- tools/profiler/GeckoProfiler.h | 3 - tools/profiler/GeckoProfilerFunc.h | 4 -- tools/profiler/GeckoProfilerImpl.h | 13 ---- tools/profiler/ProfileEntry.cpp | 10 +-- tools/profiler/ProfileEntry.h | 11 +--- tools/profiler/TableTicker.cpp | 54 ++++++---------- tools/profiler/TableTicker.h | 62 ++---------------- tools/profiler/platform-linux.cc | 100 ++++++----------------------- tools/profiler/platform-macos.cc | 39 ++--------- tools/profiler/platform-win32.cc | 40 ++---------- tools/profiler/platform.cpp | 31 +-------- tools/profiler/platform.h | 66 +------------------ 15 files changed, 63 insertions(+), 395 deletions(-) diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index fdfd21a2f0f2..070f739dce2d 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -42,8 +42,6 @@ #include "OSFileConstants.h" #include -#include "GeckoProfiler.h" - using namespace mozilla; using namespace mozilla::dom; @@ -517,8 +515,6 @@ public: return NS_ERROR_FAILURE; } - profiler_register_thread("WebWorker"); - { JSAutoRequest ar(cx); workerPrivate->DoRunLoop(cx); @@ -547,7 +543,6 @@ public: JS_DestroyRuntime(rt); workerPrivate->ScheduleDeletion(false); - profiler_unregister_thread(); return NS_OK; } }; diff --git a/ipc/chromium/src/base/thread.cc b/ipc/chromium/src/base/thread.cc index 31ec62832ec3..f447fbb201eb 100644 --- a/ipc/chromium/src/base/thread.cc +++ b/ipc/chromium/src/base/thread.cc @@ -8,7 +8,6 @@ #include "base/string_util.h" #include "base/thread_local.h" #include "base/waitable_event.h" -#include "GeckoProfiler.h" namespace base { @@ -137,8 +136,6 @@ void Thread::StopSoon() { } void Thread::ThreadMain() { - profiler_register_thread(name_.c_str()); - // The message loop for this thread. MessageLoop message_loop(startup_data_->options.message_loop_type); @@ -164,8 +161,6 @@ void Thread::ThreadMain() { // Assert that MessageLoop::Quit was called by ThreadQuitTask. DCHECK(GetThreadWasQuitProperly()); - profiler_unregister_thread(); - // We can't receive messages anymore. message_loop_ = NULL; thread_id_ = 0; diff --git a/tools/profiler/BreakpadSampler.cpp b/tools/profiler/BreakpadSampler.cpp index d30a55b6ea2f..bc804e3627f5 100644 --- a/tools/profiler/BreakpadSampler.cpp +++ b/tools/profiler/BreakpadSampler.cpp @@ -158,13 +158,6 @@ void genPseudoBacktraceEntries(/*MODIFIED*/UnwinderThreadBuffer* utb, // RUNS IN SIGHANDLER CONTEXT void BreakpadSampler::Tick(TickSample* sample) { - if (!sample->threadProfile) { - // Platform doesn't support multithread, so use the main thread profile we created - sample->threadProfile = GetPrimaryThreadProfile(); - } - - ThreadProfile& currThreadProfile = *sample->threadProfile; - /* Get hold of an empty inter-thread buffer into which to park the ProfileEntries for this sample. */ UnwinderThreadBuffer* utb = uwt__acquire_empty_buffer(); @@ -179,7 +172,7 @@ void BreakpadSampler::Tick(TickSample* sample) thread, and park them in |utb|. */ // Marker(s) come before the sample - PseudoStack* stack = currThreadProfile.GetPseudoStack(); + PseudoStack* stack = mPrimaryThreadProfile.GetPseudoStack(); for (int i = 0; stack->getMarker(i) != NULL; i++) { utb__addEntry( utb, ProfileEntry('m', stack->getMarker(i)) ); } @@ -193,7 +186,7 @@ void BreakpadSampler::Tick(TickSample* sample) // XXX: we also probably want to add an entry to the profile to help // distinguish which samples are part of the same event. That, or record // the event generation in each sample - currThreadProfile.erase(); + mPrimaryThreadProfile.erase(); } sLastSampledEventGeneration = sCurrentEventGeneration; @@ -300,9 +293,9 @@ void BreakpadSampler::Tick(TickSample* sample) # else # error "Unsupported platform" # endif - uwt__release_full_buffer(&currThreadProfile, utb, ucV); + uwt__release_full_buffer(&mPrimaryThreadProfile, utb, ucV); } else { - uwt__release_full_buffer(&currThreadProfile, utb, NULL); + uwt__release_full_buffer(&mPrimaryThreadProfile, utb, NULL); } } diff --git a/tools/profiler/GeckoProfiler.h b/tools/profiler/GeckoProfiler.h index 9105f0470ecb..4c8e2b5452c8 100644 --- a/tools/profiler/GeckoProfiler.h +++ b/tools/profiler/GeckoProfiler.h @@ -135,9 +135,6 @@ static inline void profiler_lock() {} // Re-enable the profiler and notify 'profiler-unlocked'. static inline void profiler_unlock() {} -static inline void profiler_register_thread(const char* name) {} -static inline void profiler_unregister_thread() {} - #else #include "GeckoProfilerImpl.h" diff --git a/tools/profiler/GeckoProfilerFunc.h b/tools/profiler/GeckoProfilerFunc.h index 41134bfb5ce7..2c26d8eb8a92 100644 --- a/tools/profiler/GeckoProfilerFunc.h +++ b/tools/profiler/GeckoProfilerFunc.h @@ -57,10 +57,6 @@ void mozilla_sampler_lock(); // Unlock the profiler, leaving it stopped and fires profiler-unlocked. void mozilla_sampler_unlock(); -// Register/unregister threads with the profiler -bool mozilla_sampler_register_thread(const char* name); -void mozilla_sampler_unregister_thread(); - /* Returns true if env var SPS_NEW is set to anything, else false. */ extern bool sps_version2(); diff --git a/tools/profiler/GeckoProfilerImpl.h b/tools/profiler/GeckoProfilerImpl.h index 3a23e7cb694b..ff38d8a26b5d 100644 --- a/tools/profiler/GeckoProfilerImpl.h +++ b/tools/profiler/GeckoProfilerImpl.h @@ -140,18 +140,6 @@ void profiler_unlock() return mozilla_sampler_unlock(); } -static inline -void profiler_register_thread(const char* name) -{ - mozilla_sampler_register_thread(name); -} - -static inline -void profiler_unregister_thread() -{ - mozilla_sampler_unregister_thread(); -} - // we want the class and function name but can't easily get that using preprocessor macros // __func__ doesn't have the class name and __PRETTY_FUNCTION__ has the parameters @@ -166,7 +154,6 @@ void profiler_unregister_thread() #define PROFILER_MAIN_THREAD_LABEL_PRINTF(name_space, info, ...) MOZ_ASSERT(NS_IsMainThread(), "This can only be called on the main thread"); mozilla::SamplerStackFramePrintfRAII SAMPLER_APPEND_LINE_NUMBER(sampler_raii)(name_space "::" info, __LINE__, __VA_ARGS__) #define PROFILER_MAIN_THREAD_MARKER(info) MOZ_ASSERT(NS_IsMainThread(), "This can only be called on the main thread"); mozilla_sampler_add_marker(info) - /* FIXME/bug 789667: memory constraints wouldn't much of a problem for * this small a sample buffer size, except that serializing the * profile data is extremely, unnecessarily memory intensive. */ diff --git a/tools/profiler/ProfileEntry.cpp b/tools/profiler/ProfileEntry.cpp index 4435ebf4e9a2..d8c74b748217 100644 --- a/tools/profiler/ProfileEntry.cpp +++ b/tools/profiler/ProfileEntry.cpp @@ -134,23 +134,19 @@ std::ostream& operator<<(std::ostream& stream, const ProfileEntry& entry) #define DYNAMIC_MAX_STRING 512 -ThreadProfile::ThreadProfile(const char* aName, int aEntrySize, PseudoStack *aStack, int aThreadId, bool aIsMainThread) +ThreadProfile::ThreadProfile(int aEntrySize, PseudoStack *aStack) : mWritePos(0) , mLastFlushPos(0) , mReadPos(0) , mEntrySize(aEntrySize) , mPseudoStack(aStack) , mMutex("ThreadProfile::mMutex") - , mName(strdup(aName)) - , mThreadId(aThreadId) - , mIsMainThread(aIsMainThread) { mEntries = new ProfileEntry[mEntrySize]; } ThreadProfile::~ThreadProfile() { - free(mName); delete[] mEntries; } @@ -303,10 +299,6 @@ JSCustomObject* ThreadProfile::ToJSObject(JSContext *aCx) } void ThreadProfile::BuildJSObject(JSAObjectBuilder& b, JSCustomObject* profile) { - // Thread meta data - b.DefineProperty(profile, "name", mName); - b.DefineProperty(profile, "tid", mThreadId); - JSCustomArray *samples = b.CreateArray(); b.DefineProperty(profile, "samples", samples); diff --git a/tools/profiler/ProfileEntry.h b/tools/profiler/ProfileEntry.h index a5483b59f887..897abb23c6ea 100644 --- a/tools/profiler/ProfileEntry.h +++ b/tools/profiler/ProfileEntry.h @@ -6,7 +6,6 @@ #ifndef MOZ_PROFILE_ENTRY_H #define MOZ_PROFILE_ENTRY_H -#include #include "GeckoProfilerImpl.h" #include "JSAObjectBuilder.h" #include "platform.h" @@ -57,7 +56,7 @@ typedef void (*IterateTagsCallback)(const ProfileEntry& entry, const char* tagSt class ThreadProfile { public: - ThreadProfile(const char* aName, int aEntrySize, PseudoStack *aStack, int aThreadId, bool aIsMainThread); + ThreadProfile(int aEntrySize, PseudoStack *aStack); ~ThreadProfile(); void addTag(ProfileEntry aTag); void flush(); @@ -71,11 +70,6 @@ public: PseudoStack* GetPseudoStack(); mozilla::Mutex* GetMutex(); void BuildJSObject(JSAObjectBuilder& b, JSCustomObject* profile); - - bool IsMainThread() const { return mIsMainThread; } - const char* Name() const { return mName; } - int ThreadId() const { return mThreadId; } - private: // Circular buffer 'Keep One Slot Open' implementation // for simplicity @@ -86,9 +80,6 @@ private: int mEntrySize; PseudoStack* mPseudoStack; mozilla::Mutex mMutex; - char* mName; - int mThreadId; - bool mIsMainThread; }; std::ostream& operator<<(std::ostream& stream, const ThreadProfile& profile); diff --git a/tools/profiler/TableTicker.cpp b/tools/profiler/TableTicker.cpp index 14a3350b1318..c31d9d94e4fa 100644 --- a/tools/profiler/TableTicker.cpp +++ b/tools/profiler/TableTicker.cpp @@ -173,22 +173,16 @@ void TableTicker::BuildJSObject(JSAObjectBuilder& b, JSCustomObject* profile) JSCustomArray *threads = b.CreateArray(); b.DefineProperty(profile, "threads", threads); + // For now we only have one thread SetPaused(true); - - { - mozilla::MutexAutoLock lock(*sRegisteredThreadsMutex); - - for (size_t i = 0; i < sRegisteredThreads->size(); i++) { - MutexAutoLock lock(*sRegisteredThreads->at(i)->Profile()->GetMutex()); - - JSCustomObject* threadSamples = b.CreateObject(); - sRegisteredThreads->at(i)->Profile()->BuildJSObject(b, threadSamples); - b.ArrayPush(threads, threadSamples); - } - } - + ThreadProfile* prof = GetPrimaryThreadProfile(); + prof->GetMutex()->Lock(); + JSCustomObject* threadSamples = b.CreateObject(); + prof->BuildJSObject(b, threadSamples); + b.ArrayPush(threads, threadSamples); + prof->GetMutex()->Unlock(); SetPaused(false); -} +} // END SaveProfileTask et al //////////////////////////////////////////////////////////////////////// @@ -389,17 +383,10 @@ void doSampleStackTrace(PseudoStack *aStack, ThreadProfile &aProfile, TickSample void TableTicker::Tick(TickSample* sample) { - if (!sample->threadProfile) { - // Platform doesn't support multithread, so use the main thread profile we created - sample->threadProfile = GetPrimaryThreadProfile(); - } - - ThreadProfile& currThreadProfile = *sample->threadProfile; - // Marker(s) come before the sample - PseudoStack* stack = currThreadProfile.GetPseudoStack(); + PseudoStack* stack = mPrimaryThreadProfile.GetPseudoStack(); for (int i = 0; stack->getMarker(i) != NULL; i++) { - addDynamicTag(currThreadProfile, 'm', stack->getMarker(i)); + addDynamicTag(mPrimaryThreadProfile, 'm', stack->getMarker(i)); } stack->mQueueClearMarker = true; @@ -411,7 +398,7 @@ void TableTicker::Tick(TickSample* sample) // XXX: we also probably want to add an entry to the profile to help // distinguish which samples are part of the same event. That, or record // the event generation in each sample - currThreadProfile.erase(); + mPrimaryThreadProfile.erase(); } sLastSampledEventGeneration = sCurrentEventGeneration; @@ -427,29 +414,29 @@ void TableTicker::Tick(TickSample* sample) #if defined(USE_BACKTRACE) || defined(USE_NS_STACKWALK) if (mUseStackWalk) { - doNativeBacktrace(currThreadProfile, sample); + doNativeBacktrace(mPrimaryThreadProfile, sample); } else { - doSampleStackTrace(stack, currThreadProfile, mAddLeafAddresses ? sample : nullptr); + doSampleStackTrace(stack, mPrimaryThreadProfile, mAddLeafAddresses ? sample : nullptr); } #else - doSampleStackTrace(stack, currThreadProfile, mAddLeafAddresses ? sample : nullptr); + doSampleStackTrace(stack, mPrimaryThreadProfile, mAddLeafAddresses ? sample : nullptr); #endif if (recordSample) - currThreadProfile.flush(); + mPrimaryThreadProfile.flush(); - if (!sLastTracerEvent.IsNull() && sample && currThreadProfile.IsMainThread()) { + if (!sLastTracerEvent.IsNull() && sample) { TimeDuration delta = sample->timestamp - sLastTracerEvent; - currThreadProfile.addTag(ProfileEntry('r', delta.ToMilliseconds())); + mPrimaryThreadProfile.addTag(ProfileEntry('r', delta.ToMilliseconds())); } if (sample) { TimeDuration delta = sample->timestamp - mStartTime; - currThreadProfile.addTag(ProfileEntry('t', delta.ToMilliseconds())); + mPrimaryThreadProfile.addTag(ProfileEntry('t', delta.ToMilliseconds())); } if (sLastFrameNumber != sFrameNumber) { - currThreadProfile.addTag(ProfileEntry('f', sFrameNumber)); + mPrimaryThreadProfile.addTag(ProfileEntry('f', sFrameNumber)); sLastFrameNumber = sFrameNumber; } } @@ -473,8 +460,7 @@ void mozilla_sampler_print_location1() return; } - ThreadProfile threadProfile("Temp", PROFILE_DEFAULT_ENTRY, stack, - 0, false); + ThreadProfile threadProfile(1000, stack); doSampleStackTrace(stack, threadProfile, NULL); threadProfile.flush(); diff --git a/tools/profiler/TableTicker.h b/tools/profiler/TableTicker.h index edb91195430d..6b00d1e1c6d5 100644 --- a/tools/profiler/TableTicker.h +++ b/tools/profiler/TableTicker.h @@ -5,7 +5,6 @@ #include "platform.h" #include "ProfileEntry.h" -#include "mozilla/Mutex.h" static bool hasFeature(const char** aFeatures, uint32_t aFeatureCount, const char* aFeature) { @@ -28,8 +27,8 @@ class TableTicker: public Sampler { public: TableTicker(int aInterval, int aEntrySize, PseudoStack *aStack, const char** aFeatures, uint32_t aFeatureCount) - : Sampler(aInterval, true, aEntrySize) - , mPrimaryThreadProfile(nullptr) + : Sampler(aInterval, true) + , mPrimaryThreadProfile(aEntrySize, aStack) , mStartTime(TimeStamp::Now()) , mSaveRequested(false) { @@ -39,47 +38,10 @@ class TableTicker: public Sampler { mJankOnly = hasFeature(aFeatures, aFeatureCount, "jank"); mProfileJS = hasFeature(aFeatures, aFeatureCount, "js"); mAddLeafAddresses = hasFeature(aFeatures, aFeatureCount, "leaf"); - - { - mozilla::MutexAutoLock lock(*sRegisteredThreadsMutex); - - // Create ThreadProfile for each registered thread - for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) { - ThreadInfo* info = sRegisteredThreads->at(i); - ThreadProfile* profile = new ThreadProfile(info->Name(), - aEntrySize, - info->Stack(), - info->ThreadId(), - info->IsMainThread()); - profile->addTag(ProfileEntry('m', "Start")); - - info->SetProfile(profile); - } - - SetActiveSampler(this); - } + mPrimaryThreadProfile.addTag(ProfileEntry('m', "Start")); } - ~TableTicker() { - if (IsActive()) - Stop(); - - SetActiveSampler(nullptr); - - // Destroy ThreadProfile for all threads - { - mozilla::MutexAutoLock lock(*sRegisteredThreadsMutex); - - for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) { - ThreadInfo* info = sRegisteredThreads->at(i); - ThreadProfile* profile = info->Profile(); - if (profile) { - delete profile; - info->SetProfile(nullptr); - } - } - } - } + ~TableTicker() { if (IsActive()) Stop(); } virtual void SampleStack(TickSample* sample) {} @@ -96,19 +58,7 @@ class TableTicker: public Sampler { ThreadProfile* GetPrimaryThreadProfile() { - if (!mPrimaryThreadProfile) { - mozilla::MutexAutoLock lock(*sRegisteredThreadsMutex); - - for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) { - ThreadInfo* info = sRegisteredThreads->at(i); - if (info->IsMainThread()) { - mPrimaryThreadProfile = info->Profile(); - break; - } - } - } - - return mPrimaryThreadProfile; + return &mPrimaryThreadProfile; } void ToStreamAsJSON(std::ostream& stream); @@ -126,7 +76,7 @@ protected: void BuildJSObject(JSAObjectBuilder& b, JSCustomObject* profile); // This represent the application's main thread (SAMPLER_INIT) - ThreadProfile* mPrimaryThreadProfile; + ThreadProfile mPrimaryThreadProfile; TimeStamp mStartTime; bool mSaveRequested; bool mAddLeafAddresses; diff --git a/tools/profiler/platform-linux.cc b/tools/profiler/platform-linux.cc index 0b5915e88327..0cc1c058156a 100644 --- a/tools/profiler/platform-linux.cc +++ b/tools/profiler/platform-linux.cc @@ -39,7 +39,6 @@ #include #include #include -#include #ifdef ANDROID #include #else @@ -61,13 +60,9 @@ #include #include "platform.h" #include "GeckoProfilerImpl.h" -#include "mozilla/Mutex.h" -#include "ProfileEntry.h" -#include "nsThreadUtils.h" #include #include -#include #define SIGNAL_SAVE_PROFILE SIGUSR2 @@ -80,14 +75,15 @@ pid_t gettid() } #endif +static Sampler* sActiveSampler = NULL; + + #ifdef ANDROID #include "android-signal-defs.h" #endif -static ThreadProfile* sCurrentThreadProfile = NULL; - static void ProfilerSaveSignalHandler(int signal, siginfo_t* info, void* context) { - Sampler::GetActiveSampler()->RequestSave(); + sActiveSampler->RequestSave(); } #ifdef ANDROID @@ -98,7 +94,7 @@ static void ProfilerSaveSignalHandler(int signal, siginfo_t* info, void* context #define V8_HOST_ARCH_X64 1 #endif static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { - if (!Sampler::GetActiveSampler()) + if (!sActiveSampler) return; TickSample sample_obj; @@ -107,7 +103,7 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { #ifdef ENABLE_SPS_LEAF_DATA // If profiling, we extract the current pc and sp. - if (Sampler::GetActiveSampler()->IsProfiling()) { + if (sActiveSampler->IsProfiling()) { // Extracting the sample from the context is extremely machine dependent. ucontext_t* ucontext = reinterpret_cast(context); mcontext_t& mcontext = ucontext->uc_mcontext; @@ -142,17 +138,14 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { #endif } #endif - sample->threadProfile = sCurrentThreadProfile; sample->timestamp = mozilla::TimeStamp::Now(); - Sampler::GetActiveSampler()->Tick(sample); - - sCurrentThreadProfile = NULL; + sActiveSampler->Tick(sample); } #ifndef XP_MACOSX -int tgkill(pid_t tgid, pid_t tid, int signalno) { - return syscall(SYS_tgkill, tgid, tid, signalno); +void tgkill(pid_t tgid, pid_t tid, int signalno) { + syscall(SYS_tgkill, tgid, tid, signalno); } #endif @@ -180,33 +173,8 @@ class Sampler::PlatformData : public Malloced { #ifdef XP_MACOSX pthread_kill(signal_receiver_, SIGPROF); #else - - std::vector threads = GetRegisteredThreads(); - - for (uint32_t i = 0; i < threads.size(); i++) { - ThreadInfo* info = threads[i]; - - // We use sCurrentThreadProfile the ThreadProfile for the - // thread we're profiling to the signal handler - sCurrentThreadProfile = info->Profile(); - - int threadId = info->ThreadId(); - if (threadId == 0) { - threadId = vm_tid_; - } - - if (tgkill(vm_tgid_, threadId, SIGPROF) != 0) { - printf_stderr("profiler failed to signal tid=%d\n", threadId); -#ifdef DEBUG - abort(); -#endif - continue; - } - - // Wait for the signal handler to run before moving on to the next one - while (sCurrentThreadProfile) - sched_yield(); - } + // Glibc doesn't provide a wrapper for tgkill(2). + tgkill(vm_tgid_, vm_tid_, SIGPROF); #endif } @@ -241,12 +209,11 @@ static void* SenderEntry(void* arg) { } -Sampler::Sampler(int interval, bool profiling, int entrySize) +Sampler::Sampler(int interval, bool profiling) : interval_(interval), profiling_(profiling), paused_(false), - active_(false), - entrySize_(entrySize) { + active_(false) { data_ = new PlatformData(this); } @@ -258,6 +225,7 @@ Sampler::~Sampler() { void Sampler::Start() { LOG("Sampler started"); + if (sActiveSampler != NULL) return; // Request profiling signals. LOG("Request signal"); @@ -291,6 +259,9 @@ void Sampler::Start() { data_->signal_sender_launched_ = true; } LOG("Profiler thread started"); + + // Set this sampler as the active sampler. + sActiveSampler = this; } @@ -310,41 +281,9 @@ void Sampler::Stop() { sigaction(SIGPROF, &data_->old_sigprof_signal_handler_, 0); data_->signal_handler_installed_ = false; } -} -bool Sampler::RegisterCurrentThread(const char* aName, PseudoStack* aPseudoStack, bool aIsMainThread) -{ - mozilla::MutexAutoLock lock(*sRegisteredThreadsMutex); - - ThreadInfo* info = new ThreadInfo(aName, gettid(), aIsMainThread, aPseudoStack); - - if (sActiveSampler) { - // We need to create the ThreadProfile now - info->SetProfile(new ThreadProfile(info->Name(), - sActiveSampler->EntrySize(), - info->Stack(), - info->ThreadId(), - aIsMainThread)); - } - - sRegisteredThreads->push_back(info); - return true; -} - -void Sampler::UnregisterCurrentThread() -{ - mozilla::MutexAutoLock lock(*sRegisteredThreadsMutex); - - int id = gettid(); - - for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) { - ThreadInfo* info = sRegisteredThreads->at(i); - if (info->ThreadId() == id) { - delete info; - sRegisteredThreads->erase(sRegisteredThreads->begin() + i); - break; - } - } + // This sampler is no longer the active sampler. + sActiveSampler = NULL; } #ifdef ANDROID @@ -368,4 +307,3 @@ void OS::RegisterStartHandler() } } #endif - diff --git a/tools/profiler/platform-macos.cc b/tools/profiler/platform-macos.cc index 50945dc34fcd..99392cc7ed61 100644 --- a/tools/profiler/platform-macos.cc +++ b/tools/profiler/platform-macos.cc @@ -28,8 +28,6 @@ #include #include -#include "nsThreadUtils.h" - #include "platform.h" #include "UnwinderThread2.h" /* uwt__register_thread_for_profiling */ @@ -201,8 +199,8 @@ class Sampler::PlatformData : public Malloced { class SamplerThread : public Thread { public: explicit SamplerThread(int interval) - : Thread("SamplerThread") - , interval_(interval) {} + : Thread("SamplerThread"), + interval_(interval) {} static void AddActiveSampler(Sampler* sampler) { ScopedLock lock(mutex_); @@ -281,7 +279,6 @@ class SamplerThread : public Thread { sample->sp = reinterpret_cast
(state.REGISTER_FIELD(sp)); sample->fp = reinterpret_cast
(state.REGISTER_FIELD(bp)); sample->timestamp = mozilla::TimeStamp::Now(); - sample->threadProfile = NULL; sampler->SampleStack(sample); sampler->Tick(sample); } @@ -305,13 +302,12 @@ Mutex* SamplerThread::mutex_ = OS::CreateMutex(); SamplerThread* SamplerThread::instance_ = NULL; -Sampler::Sampler(int interval, bool profiling, int entrySize) +Sampler::Sampler(int interval, bool profiling) : // isolate_(isolate), interval_(interval), profiling_(profiling), paused_(false), - active_(false), - entrySize_(entrySize) /*, + active_(false) /*, samples_taken_(0)*/ { data_ = new PlatformData; } @@ -341,30 +337,3 @@ Sampler::GetProfiledThread(Sampler::PlatformData* aData) { return aData->profiled_pthread(); } - -bool Sampler::RegisterCurrentThread(const char* aName, PseudoStack* aPseudoStack, bool aIsMainThread) -{ - mozilla::MutexAutoLock lock(*sRegisteredThreadsMutex); - - if (!aIsMainThread) - return false; - - ThreadInfo* info = new ThreadInfo(aName, 0, true, aPseudoStack); - - if (sActiveSampler) { - // We need to create the ThreadProfile now - info->SetProfile(new ThreadProfile(info->Name(), - sActiveSampler->EntrySize(), - info->Stack(), - info->ThreadId(), - true)); - } - - sRegisteredThreads->push_back(info); - return true; -} - -void Sampler::UnregisterCurrentThread() -{ - // We only have the main thread currently and that will never be unregistered -} \ No newline at end of file diff --git a/tools/profiler/platform-win32.cc b/tools/profiler/platform-win32.cc index 818b536b68f3..af68f4c52354 100644 --- a/tools/profiler/platform-win32.cc +++ b/tools/profiler/platform-win32.cc @@ -28,10 +28,9 @@ #include #include -#include #include "platform.h" +#include -#include "ProfileEntry.h" class Sampler::PlatformData : public Malloced { public: @@ -68,9 +67,9 @@ Sampler::GetThreadHandle(Sampler::PlatformData* aData) class SamplerThread : public Thread { public: SamplerThread(int interval, Sampler* sampler) - : Thread("SamplerThread") - , interval_(interval) - , sampler_(sampler) {} + : Thread("SamplerThread"), + interval_(interval), + sampler_(sampler) {} static void StartSampler(Sampler* sampler) { if (instance_ == NULL) { @@ -121,7 +120,6 @@ class SamplerThread : public Thread { // Grab the timestamp before pausing the thread, to avoid deadlocks. sample->timestamp = mozilla::TimeStamp::Now(); - sample->threadProfile = NULL; static const DWORD kSuspendFailed = static_cast(-1); if (SuspendThread(profiled_thread) == kSuspendFailed) @@ -157,12 +155,11 @@ class SamplerThread : public Thread { SamplerThread* SamplerThread::instance_ = NULL; -Sampler::Sampler(int interval, bool profiling, int entrySize) +Sampler::Sampler(int interval, bool profiling) : interval_(interval), profiling_(profiling), paused_(false), active_(false), - entrySize_(entrySize), data_(new PlatformData) { } @@ -241,30 +238,3 @@ void Thread::Join() { void OS::Sleep(int milliseconds) { ::Sleep(milliseconds); } - -bool Sampler::RegisterCurrentThread(const char* aName, PseudoStack* aPseudoStack, bool aIsMainThread) -{ - mozilla::MutexAutoLock lock(*sRegisteredThreadsMutex); - - if (!aIsMainThread) - return false; - - ThreadInfo* info = new ThreadInfo(aName, 0, true, aPseudoStack); - - if (sActiveSampler) { - // We need to create the ThreadProfile now - info->SetProfile(new ThreadProfile(info->Name(), - sActiveSampler->EntrySize(), - info->Stack(), - info->ThreadId(), - true)); - } - - sRegisteredThreads->push_back(info); - return true; -} - -void Sampler::UnregisterCurrentThread() -{ - // We only have the main thread currently and that will never be unregistered -} \ No newline at end of file diff --git a/tools/profiler/platform.cpp b/tools/profiler/platform.cpp index 27bbeb6df5b0..653b681dd17c 100644 --- a/tools/profiler/platform.cpp +++ b/tools/profiler/platform.cpp @@ -18,7 +18,6 @@ #include "nsDirectoryServiceUtils.h" #include "nsDirectoryServiceDefs.h" #include "mozilla/Services.h" -#include "nsThreadUtils.h" mozilla::ThreadLocal tlsPseudoStack; mozilla::ThreadLocal tlsTicker; @@ -36,7 +35,7 @@ int sLastFrameNumber = 0; unsigned int sLastSampledEventGeneration = 0; /* a counter that's incremented everytime we get responsiveness event - * note: it might also be worth trackplaing everytime we go around + * note: it might also be worth tracking everytime we go around * the event loop */ unsigned int sCurrentEventGeneration = 0; /* we don't need to worry about overflow because we only treat the @@ -44,18 +43,6 @@ unsigned int sCurrentEventGeneration = 0; * a problem if 2^32 events happen between samples that we need * to know are associated with different events */ -std::vector* Sampler::sRegisteredThreads = new std::vector(); -mozilla::Mutex* Sampler::sRegisteredThreadsMutex = new mozilla::Mutex("sRegisteredThreads mutex"); - -Sampler* Sampler::sActiveSampler; - -ThreadInfo::~ThreadInfo() { - free(mName); - - if (mProfile) - delete mProfile; -} - bool sps_version2() { static int version = 0; // Raced on, potentially @@ -306,8 +293,6 @@ void mozilla_sampler_shutdown() uwt__deinit(); } - Sampler::FreeRegisteredThreads(); - profiler_stop(); // We can't delete the Stack because we can be between a // sampler call_enter/call_exit point. @@ -502,20 +487,6 @@ void mozilla_sampler_unlock() os->NotifyObservers(nullptr, "profiler-unlocked", nullptr); } -bool mozilla_sampler_register_thread(const char* aName) -{ - PseudoStack* stack = new PseudoStack(); - tlsPseudoStack.set(stack); - - return Sampler::RegisterCurrentThread(aName, stack, false); -} - -void mozilla_sampler_unregister_thread() -{ - Sampler::UnregisterCurrentThread(); -} - // END externally visible functions //////////////////////////////////////////////////////////////////////// - diff --git a/tools/profiler/platform.h b/tools/profiler/platform.h index 8371927aa9d2..22bc75afbe87 100644 --- a/tools/profiler/platform.h +++ b/tools/profiler/platform.h @@ -232,9 +232,6 @@ extern int sUnwindStackScan; /* max # of dubious frames allowed */ // (if used for profiling) the program counter and stack pointer for // the thread that created it. -class PseudoStack; -class ThreadProfile; - // TickSample captures the information collected for each sample. class TickSample { public: @@ -258,44 +255,16 @@ class TickSample { Address function; // The last called JS function. void* context; // The context from the signal handler, if available. On // Win32 this may contain the windows thread context. - ThreadProfile* threadProfile; static const int kMaxFramesCount = 64; + Address stack[kMaxFramesCount]; // Call stack. int frames_count; // Number of captured frames. mozilla::TimeStamp timestamp; }; -class ThreadInfo { - public: - ThreadInfo(const char* aName, int aThreadId, bool aIsMainThread, PseudoStack* aPseudoStack) - : mName(strdup(aName)) - , mThreadId(aThreadId) - , mIsMainThread(aIsMainThread) - , mPseudoStack(aPseudoStack) - , mProfile(NULL) {} - - virtual ~ThreadInfo(); - - const char* Name() const { return mName; } - int ThreadId() const { return mThreadId; } - - bool IsMainThread() const { return mIsMainThread; } - PseudoStack* Stack() const { return mPseudoStack; } - - void SetProfile(ThreadProfile* aProfile) { mProfile = aProfile; } - ThreadProfile* Profile() const { return mProfile; } - - private: - char* mName; - int mThreadId; - const bool mIsMainThread; - PseudoStack* mPseudoStack; - ThreadProfile* mProfile; -}; - class Sampler { public: // Initialize sampler. - explicit Sampler(int interval, bool profiling, int entrySize); + explicit Sampler(int interval, bool profiling); virtual ~Sampler(); int interval() const { return interval_; } @@ -326,8 +295,6 @@ class Sampler { bool IsPaused() const { return paused_; } void SetPaused(bool value) { NoBarrier_Store(&paused_, value); } - int EntrySize() { return entrySize_; } - class PlatformData; PlatformData* platform_data() { return data_; } @@ -341,34 +308,6 @@ class Sampler { #ifdef XP_MACOSX static pthread_t GetProfiledThread(PlatformData*); #endif - - static std::vector GetRegisteredThreads() { - mozilla::MutexAutoLock lock(*sRegisteredThreadsMutex); - - return *sRegisteredThreads; - } - - static bool RegisterCurrentThread(const char* aName, PseudoStack* aPseudoStack, bool aIsMainThread); - static void UnregisterCurrentThread(); - - // Should only be called on shutdown - static void FreeRegisteredThreads() { - while (sRegisteredThreads->size() > 0) { - sRegisteredThreads->pop_back(); - } - - delete sRegisteredThreadsMutex; - delete sRegisteredThreads; - } - - static Sampler* GetActiveSampler() { return sActiveSampler; } - static void SetActiveSampler(Sampler* sampler) { sActiveSampler = sampler; } - - protected: - static std::vector* sRegisteredThreads; - static mozilla::Mutex* sRegisteredThreadsMutex; - static Sampler* sActiveSampler; - private: void SetActive(bool value) { NoBarrier_Store(&active_, value); } @@ -376,7 +315,6 @@ class Sampler { const bool profiling_; Atomic32 paused_; Atomic32 active_; - const int entrySize_; PlatformData* data_; // Platform specific data. };