Backout cb37a2ae805f on a CLOSED TREE

This commit is contained in:
Benoit Girard 2013-04-10 19:43:20 -04:00
Родитель 5d50089575
Коммит 61019f45d1
15 изменённых файлов: 63 добавлений и 395 удалений

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

@ -42,8 +42,6 @@
#include "OSFileConstants.h"
#include <algorithm>
#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;
}
};

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

@ -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;

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

@ -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);
}
}

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

@ -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"

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

@ -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();

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

@ -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. */

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

@ -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);

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

@ -6,7 +6,6 @@
#ifndef MOZ_PROFILE_ENTRY_H
#define MOZ_PROFILE_ENTRY_H
#include <ostream>
#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);

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

@ -173,20 +173,14 @@ 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);
}
@ -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();

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

@ -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;

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

@ -39,7 +39,6 @@
#include <sys/syscall.h>
#include <sys/types.h>
#include <stdlib.h>
#include <sched.h>
#ifdef ANDROID
#include <android/log.h>
#else
@ -61,13 +60,9 @@
#include <stdarg.h>
#include "platform.h"
#include "GeckoProfilerImpl.h"
#include "mozilla/Mutex.h"
#include "ProfileEntry.h"
#include "nsThreadUtils.h"
#include <string.h>
#include <stdio.h>
#include <list>
#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<ucontext_t*>(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<ThreadInfo*> 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

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

@ -28,8 +28,6 @@
#include <string.h>
#include <errno.h>
#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<Address>(state.REGISTER_FIELD(sp));
sample->fp = reinterpret_cast<Address>(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
}

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

@ -28,10 +28,9 @@
#include <windows.h>
#include <mmsystem.h>
#include <process.h>
#include "platform.h"
#include <process.h>
#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<DWORD>(-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
}

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

@ -18,7 +18,6 @@
#include "nsDirectoryServiceUtils.h"
#include "nsDirectoryServiceDefs.h"
#include "mozilla/Services.h"
#include "nsThreadUtils.h"
mozilla::ThreadLocal<PseudoStack *> tlsPseudoStack;
mozilla::ThreadLocal<TableTicker *> 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<ThreadInfo*>* Sampler::sRegisteredThreads = new std::vector<ThreadInfo*>();
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
////////////////////////////////////////////////////////////////////////

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

@ -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<ThreadInfo*> 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<ThreadInfo*>* 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.
};