Bug 1334466 (part 3) - Rename GeckoSampler.cpp as Sampler.cpp. r=mstange.

The patch also moves some Sampler methods from platform.cpp to Sampler.cpp. Now
all Sampler methods are in Sampler.cpp except for a small number of
platform-specific ones, which are in platform-*.cpp.

--HG--
rename : tools/profiler/core/GeckoSampler.cpp => tools/profiler/core/Sampler.cpp
extra : rebase_source : a13862dccfcb1c78567cc9eb22e92b8410d2e544
This commit is contained in:
Nicholas Nethercote 2017-01-28 00:57:52 +11:00
parent b33fc679ac
commit 9c6ed67ad7
3 changed files with 108 additions and 102 deletions

View File

@ -165,6 +165,9 @@ hasFeature(const char** aFeatures, uint32_t aFeatureCount, const char* aFeature)
return false;
}
std::vector<ThreadInfo*>* Sampler::sRegisteredThreads = nullptr;
mozilla::UniquePtr<mozilla::Mutex> Sampler::sRegisteredThreadsMutex;
Sampler::Sampler(double aInterval, int aEntrySize,
const char** aFeatures, uint32_t aFeatureCount,
const char** aThreadNameFilters, uint32_t aFilterCount)
@ -270,6 +273,110 @@ Sampler::~Sampler()
#endif
}
void
Sampler::Startup()
{
sRegisteredThreads = new std::vector<ThreadInfo*>();
sRegisteredThreadsMutex = MakeUnique<Mutex>("sRegisteredThreadsMutex");
// We could create the sLUL object and read unwind info into it at
// this point. That would match the lifetime implied by destruction
// of it in Sampler::Shutdown just below. However, that gives a big
// delay on startup, even if no profiling is actually to be done.
// So, instead, sLUL is created on demand at the first call to
// Sampler::Start.
}
void
Sampler::Shutdown()
{
while (sRegisteredThreads->size() > 0) {
delete sRegisteredThreads->back();
sRegisteredThreads->pop_back();
}
sRegisteredThreadsMutex = nullptr;
delete sRegisteredThreads;
// UnregisterThread can be called after shutdown in XPCShell. Thus
// we need to point to null to ignore such a call after shutdown.
sRegisteredThreadsMutex = nullptr;
sRegisteredThreads = nullptr;
#if defined(USE_LUL_STACKWALK)
// Delete the sLUL object, if it actually got created.
if (sLUL) {
delete sLUL;
sLUL = nullptr;
}
#endif
}
bool
Sampler::RegisterCurrentThread(const char* aName,
PseudoStack* aPseudoStack,
bool aIsMainThread, void* stackTop)
{
if (!sRegisteredThreadsMutex) {
return false;
}
MutexAutoLock lock(*sRegisteredThreadsMutex);
Thread::tid_t id = Thread::GetCurrentId();
for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) {
ThreadInfo* info = sRegisteredThreads->at(i);
if (info->ThreadId() == id && !info->IsPendingDelete()) {
// Thread already registered. This means the first unregister will be
// too early.
ASSERT(false);
return false;
}
}
ThreadInfo* info = new StackOwningThreadInfo(aName, id,
aIsMainThread, aPseudoStack, stackTop);
// XXX: this is an off-main-thread use of gSampler
if (gSampler) {
gSampler->RegisterThread(info);
}
sRegisteredThreads->push_back(info);
return true;
}
void
Sampler::UnregisterCurrentThread()
{
if (!sRegisteredThreadsMutex) {
return;
}
MutexAutoLock lock(*sRegisteredThreadsMutex);
Thread::tid_t id = Thread::GetCurrentId();
for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) {
ThreadInfo* info = sRegisteredThreads->at(i);
if (info->ThreadId() == id && !info->IsPendingDelete()) {
if (profiler_is_active()) {
// We still want to show the results of this thread if you
// save the profile shortly after a thread is terminated.
// For now we will defer the delete to profile stop.
info->SetPendingDelete();
break;
} else {
delete info;
sRegisteredThreads->erase(sRegisteredThreads->begin() + i);
break;
}
}
}
}
void
Sampler::HandleSaveRequest()
{

View File

@ -100,9 +100,6 @@ static int sUnwindInterval; /* in milliseconds */
static int sUnwindStackScan; /* max # of dubious frames allowed */
static int sProfileEntries; /* how many entries do we store? */
std::vector<ThreadInfo*>* Sampler::sRegisteredThreads = nullptr;
mozilla::UniquePtr< ::Mutex> Sampler::sRegisteredThreadsMutex;
static mozilla::StaticAutoPtr<mozilla::ProfilerIOInterposeObserver>
sInterposeObserver;
@ -110,104 +107,6 @@ static mozilla::StaticAutoPtr<mozilla::ProfilerIOInterposeObserver>
// profiler_register_thread.
static const char * gGeckoThreadName = "GeckoMain";
void Sampler::Startup() {
sRegisteredThreads = new std::vector<ThreadInfo*>();
sRegisteredThreadsMutex = MakeUnique<Mutex>("sRegisteredThreadsMutex");
// We could create the sLUL object and read unwind info into it at
// this point. That would match the lifetime implied by destruction
// of it in Sampler::Shutdown just below. However, that gives a big
// delay on startup, even if no profiling is actually to be done.
// So, instead, sLUL is created on demand at the first call to
// Sampler::Start.
}
void Sampler::Shutdown() {
while (sRegisteredThreads->size() > 0) {
delete sRegisteredThreads->back();
sRegisteredThreads->pop_back();
}
sRegisteredThreadsMutex = nullptr;
delete sRegisteredThreads;
// UnregisterThread can be called after shutdown in XPCShell. Thus
// we need to point to null to ignore such a call after shutdown.
sRegisteredThreadsMutex = nullptr;
sRegisteredThreads = nullptr;
#if defined(USE_LUL_STACKWALK)
// Delete the sLUL object, if it actually got created.
if (sLUL) {
delete sLUL;
sLUL = nullptr;
}
#endif
}
bool
Sampler::RegisterCurrentThread(const char* aName,
PseudoStack* aPseudoStack,
bool aIsMainThread, void* stackTop)
{
if (!sRegisteredThreadsMutex)
return false;
MutexAutoLock lock(*sRegisteredThreadsMutex);
Thread::tid_t id = Thread::GetCurrentId();
for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) {
ThreadInfo* info = sRegisteredThreads->at(i);
if (info->ThreadId() == id && !info->IsPendingDelete()) {
// Thread already registered. This means the first unregister will be
// too early.
ASSERT(false);
return false;
}
}
ThreadInfo* info = new StackOwningThreadInfo(aName, id,
aIsMainThread, aPseudoStack, stackTop);
// XXX: this is an off-main-thread use of gSampler
if (gSampler) {
gSampler->RegisterThread(info);
}
sRegisteredThreads->push_back(info);
return true;
}
void
Sampler::UnregisterCurrentThread()
{
if (!sRegisteredThreadsMutex)
return;
MutexAutoLock lock(*sRegisteredThreadsMutex);
Thread::tid_t id = Thread::GetCurrentId();
for (uint32_t i = 0; i < sRegisteredThreads->size(); i++) {
ThreadInfo* info = sRegisteredThreads->at(i);
if (info->ThreadId() == id && !info->IsPendingDelete()) {
if (profiler_is_active()) {
// We still want to show the results of this thread if you
// save the profile shortly after a thread is terminated.
// For now we will defer the delete to profile stop.
info->SetPendingDelete();
break;
} else {
delete info;
sRegisteredThreads->erase(sRegisteredThreads->begin() + i);
break;
}
}
}
}
StackOwningThreadInfo::StackOwningThreadInfo(const char* aName, int aThreadId,
bool aIsMainThread,
PseudoStack* aPseudoStack,

View File

@ -23,13 +23,13 @@ if CONFIG['MOZ_GECKO_PROFILER']:
'gecko/Profiler.jsm',
]
UNIFIED_SOURCES += [
'core/GeckoSampler.cpp',
'core/platform.cpp',
'core/ProfileBuffer.cpp',
'core/ProfileEntry.cpp',
'core/ProfileJSONWriter.cpp',
'core/ProfilerBacktrace.cpp',
'core/ProfilerMarkers.cpp',
'core/Sampler.cpp',
'core/StackTop.cpp',
'core/SyncProfile.cpp',
'core/ThreadInfo.cpp',