2011-08-27 04:05:37 +04:00
|
|
|
// Copyright (c) 2006-2011 The Chromium Authors. All rights reserved.
|
2012-11-19 23:02:32 +04:00
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions
|
|
|
|
// are met:
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer in
|
|
|
|
// the documentation and/or other materials provided with the
|
|
|
|
// distribution.
|
|
|
|
// * Neither the name of Google, Inc. nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this
|
|
|
|
// software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
|
|
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
// SUCH DAMAGE.
|
2011-08-27 04:05:37 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
# vim: sw=2
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <semaphore.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdlib.h>
|
2013-03-29 23:34:49 +04:00
|
|
|
#include <sched.h>
|
2011-08-27 04:05:37 +04:00
|
|
|
#ifdef ANDROID
|
|
|
|
#include <android/log.h>
|
|
|
|
#else
|
|
|
|
#define __android_log_print(a, ...)
|
|
|
|
#endif
|
|
|
|
// Ubuntu Dapper requires memory pages to be marked as
|
|
|
|
// executable. Otherwise, OS raises an exception when executing code
|
|
|
|
// in that page.
|
|
|
|
#include <sys/types.h> // mmap & munmap
|
|
|
|
#include <sys/mman.h> // mmap & munmap
|
|
|
|
#include <sys/stat.h> // open
|
|
|
|
#include <fcntl.h> // open
|
|
|
|
#include <unistd.h> // sysconf
|
|
|
|
#ifdef __GLIBC__
|
|
|
|
#include <execinfo.h> // backtrace, backtrace_symbols
|
|
|
|
#endif // def __GLIBC__
|
|
|
|
#include <strings.h> // index
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "platform.h"
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfilerImpl.h"
|
2013-03-29 23:34:49 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
|
|
|
#include "ProfileEntry.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2013-04-04 02:59:17 +04:00
|
|
|
#include "TableTicker.h"
|
2011-08-27 04:05:37 +04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2013-03-29 23:34:49 +04:00
|
|
|
#include <list>
|
2011-08-27 04:05:37 +04:00
|
|
|
|
2011-12-09 02:35:36 +04:00
|
|
|
#define SIGNAL_SAVE_PROFILE SIGUSR2
|
2011-08-27 04:05:37 +04:00
|
|
|
|
2011-12-16 00:44:13 +04:00
|
|
|
#if defined(__GLIBC__)
|
|
|
|
// glibc doesn't implement gettid(2).
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
pid_t gettid()
|
|
|
|
{
|
|
|
|
return (pid_t) syscall(SYS_gettid);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-16 22:53:03 +04:00
|
|
|
#if !defined(ANDROID)
|
|
|
|
// Keep track of when any of our threads calls fork(), so we can
|
|
|
|
// temporarily disable signal delivery during the fork() call. Not
|
|
|
|
// doing so appears to cause a kind of race, in which signals keep
|
|
|
|
// getting delivered to the thread doing fork(), which keeps causing
|
|
|
|
// it to fail and be restarted; hence forward progress is delayed a
|
|
|
|
// great deal. A side effect of this is to permanently disable
|
|
|
|
// sampling in the child process. See bug 837390.
|
|
|
|
|
|
|
|
// Unfortunately this is only doable on non-Android, since Bionic
|
|
|
|
// doesn't have pthread_atfork.
|
|
|
|
|
|
|
|
// This records the current state at the time we paused it.
|
|
|
|
static bool was_paused = false;
|
|
|
|
|
|
|
|
// In the parent, just before the fork, record the pausedness state,
|
|
|
|
// and then pause.
|
|
|
|
static void paf_prepare(void) {
|
2013-03-29 23:34:49 +04:00
|
|
|
if (Sampler::GetActiveSampler()) {
|
|
|
|
was_paused = Sampler::GetActiveSampler()->IsPaused();
|
|
|
|
Sampler::GetActiveSampler()->SetPaused(true);
|
2013-04-16 22:53:03 +04:00
|
|
|
} else {
|
|
|
|
was_paused = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// In the parent, just after the fork, return pausedness to the
|
|
|
|
// pre-fork state.
|
|
|
|
static void paf_parent(void) {
|
2013-03-29 23:34:49 +04:00
|
|
|
if (Sampler::GetActiveSampler())
|
|
|
|
Sampler::GetActiveSampler()->SetPaused(was_paused);
|
2013-04-16 22:53:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the fork handlers. This is called just once, at the first
|
|
|
|
// call to SenderEntry.
|
|
|
|
static void* setup_atfork() {
|
|
|
|
pthread_atfork(paf_prepare, paf_parent, NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif /* !defined(ANDROID) */
|
|
|
|
|
2012-11-08 20:45:17 +04:00
|
|
|
#ifdef ANDROID
|
2012-03-02 23:11:47 +04:00
|
|
|
#include "android-signal-defs.h"
|
2011-08-27 04:05:37 +04:00
|
|
|
#endif
|
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
struct SamplerRegistry {
|
|
|
|
static void AddActiveSampler(Sampler *sampler) {
|
|
|
|
ASSERT(!SamplerRegistry::sampler);
|
|
|
|
SamplerRegistry::sampler = sampler;
|
|
|
|
}
|
|
|
|
static void RemoveActiveSampler(Sampler *sampler) {
|
|
|
|
SamplerRegistry::sampler = NULL;
|
|
|
|
}
|
|
|
|
static Sampler *sampler;
|
|
|
|
};
|
|
|
|
|
|
|
|
Sampler *SamplerRegistry::sampler = NULL;
|
|
|
|
|
2013-03-29 23:34:49 +04:00
|
|
|
static ThreadProfile* sCurrentThreadProfile = NULL;
|
|
|
|
|
2011-08-27 04:05:37 +04:00
|
|
|
static void ProfilerSaveSignalHandler(int signal, siginfo_t* info, void* context) {
|
2013-03-29 23:34:49 +04:00
|
|
|
Sampler::GetActiveSampler()->RequestSave();
|
2011-08-27 04:05:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ANDROID
|
|
|
|
#define V8_HOST_ARCH_ARM 1
|
|
|
|
#define SYS_gettid __NR_gettid
|
|
|
|
#define SYS_tgkill __NR_tgkill
|
|
|
|
#else
|
|
|
|
#define V8_HOST_ARCH_X64 1
|
|
|
|
#endif
|
|
|
|
static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
|
2013-03-29 23:34:49 +04:00
|
|
|
if (!Sampler::GetActiveSampler())
|
2011-08-27 04:05:37 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
TickSample sample_obj;
|
|
|
|
TickSample* sample = &sample_obj;
|
2012-03-02 23:11:47 +04:00
|
|
|
sample->context = context;
|
2011-08-27 04:05:37 +04:00
|
|
|
|
2012-01-11 03:02:00 +04:00
|
|
|
#ifdef ENABLE_SPS_LEAF_DATA
|
2011-08-27 04:05:37 +04:00
|
|
|
// If profiling, we extract the current pc and sp.
|
2013-03-29 23:34:49 +04:00
|
|
|
if (Sampler::GetActiveSampler()->IsProfiling()) {
|
2011-08-27 04:05:37 +04:00
|
|
|
// Extracting the sample from the context is extremely machine dependent.
|
|
|
|
ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
|
|
|
|
mcontext_t& mcontext = ucontext->uc_mcontext;
|
|
|
|
#if V8_HOST_ARCH_IA32
|
|
|
|
sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_EIP]);
|
|
|
|
sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_ESP]);
|
|
|
|
sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_EBP]);
|
|
|
|
#elif V8_HOST_ARCH_X64
|
|
|
|
sample->pc = reinterpret_cast<Address>(mcontext.gregs[REG_RIP]);
|
|
|
|
sample->sp = reinterpret_cast<Address>(mcontext.gregs[REG_RSP]);
|
|
|
|
sample->fp = reinterpret_cast<Address>(mcontext.gregs[REG_RBP]);
|
|
|
|
#elif V8_HOST_ARCH_ARM
|
|
|
|
// An undefined macro evaluates to 0, so this applies to Android's Bionic also.
|
2012-11-08 20:45:17 +04:00
|
|
|
#if !defined(ANDROID) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3))
|
2011-08-27 04:05:37 +04:00
|
|
|
sample->pc = reinterpret_cast<Address>(mcontext.gregs[R15]);
|
|
|
|
sample->sp = reinterpret_cast<Address>(mcontext.gregs[R13]);
|
|
|
|
sample->fp = reinterpret_cast<Address>(mcontext.gregs[R11]);
|
2012-07-04 19:25:15 +04:00
|
|
|
#ifdef ENABLE_ARM_LR_SAVING
|
|
|
|
sample->lr = reinterpret_cast<Address>(mcontext.gregs[R14]);
|
|
|
|
#endif
|
2011-08-27 04:05:37 +04:00
|
|
|
#else
|
|
|
|
sample->pc = reinterpret_cast<Address>(mcontext.arm_pc);
|
|
|
|
sample->sp = reinterpret_cast<Address>(mcontext.arm_sp);
|
|
|
|
sample->fp = reinterpret_cast<Address>(mcontext.arm_fp);
|
2012-07-04 19:25:15 +04:00
|
|
|
#ifdef ENABLE_ARM_LR_SAVING
|
|
|
|
sample->lr = reinterpret_cast<Address>(mcontext.arm_lr);
|
|
|
|
#endif
|
2011-08-27 04:05:37 +04:00
|
|
|
#endif
|
|
|
|
#elif V8_HOST_ARCH_MIPS
|
|
|
|
// Implement this on MIPS.
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
2013-03-29 23:34:49 +04:00
|
|
|
sample->threadProfile = sCurrentThreadProfile;
|
2012-01-11 03:02:00 +04:00
|
|
|
sample->timestamp = mozilla::TimeStamp::Now();
|
|
|
|
|
2013-03-29 23:34:49 +04:00
|
|
|
Sampler::GetActiveSampler()->Tick(sample);
|
|
|
|
|
|
|
|
sCurrentThreadProfile = NULL;
|
2011-08-27 04:05:37 +04:00
|
|
|
}
|
|
|
|
|
2013-03-29 23:34:49 +04:00
|
|
|
int tgkill(pid_t tgid, pid_t tid, int signalno) {
|
|
|
|
return syscall(SYS_tgkill, tgid, tid, signalno);
|
2011-08-27 04:05:37 +04:00
|
|
|
}
|
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
class PlatformData : public Malloced {
|
2011-08-27 04:05:37 +04:00
|
|
|
public:
|
2013-04-04 02:59:17 +04:00
|
|
|
PlatformData()
|
|
|
|
{}
|
|
|
|
};
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
/* static */ PlatformData*
|
|
|
|
Sampler::AllocPlatformData(int aThreadId)
|
|
|
|
{
|
|
|
|
return new PlatformData;
|
|
|
|
}
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
/* static */ void
|
|
|
|
Sampler::FreePlatformData(PlatformData* aData)
|
|
|
|
{
|
|
|
|
delete aData;
|
|
|
|
}
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
static void* SignalSender(void* arg) {
|
|
|
|
# if defined(ANDROID)
|
|
|
|
// pthread_atfork isn't available on Android.
|
|
|
|
void* initialize_atfork = NULL;
|
|
|
|
# else
|
|
|
|
// This call is done just once, at the first call to SenderEntry.
|
|
|
|
// It returns NULL.
|
|
|
|
static void* initialize_atfork = setup_atfork();
|
|
|
|
# endif
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
int vm_tgid_ = getpid();
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
while (SamplerRegistry::sampler->IsActive()) {
|
|
|
|
SamplerRegistry::sampler->HandleSaveRequest();
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
if (!SamplerRegistry::sampler->IsPaused()) {
|
|
|
|
mozilla::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
|
|
|
|
std::vector<ThreadInfo*> threads =
|
|
|
|
SamplerRegistry::sampler->GetRegisteredThreads();
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
for (uint32_t i = 0; i < threads.size(); i++) {
|
|
|
|
ThreadInfo* info = threads[i];
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
// This will be null if we're not interested in profiling this thread.
|
|
|
|
if (!info->Profile())
|
|
|
|
continue;
|
2013-04-18 16:15:09 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
// We use sCurrentThreadProfile the ThreadProfile for the
|
|
|
|
// thread we're profiling to the signal handler
|
|
|
|
sCurrentThreadProfile = info->Profile();
|
|
|
|
|
|
|
|
int threadId = info->ThreadId();
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
if (tgkill(vm_tgid_, threadId, SIGPROF) != 0) {
|
|
|
|
printf_stderr("profiler failed to signal tid=%d\n", threadId);
|
|
|
|
#ifdef DEBUG
|
|
|
|
abort();
|
2013-04-18 16:15:09 +04:00
|
|
|
#endif
|
2013-04-04 02:59:17 +04:00
|
|
|
continue;
|
|
|
|
}
|
2013-04-18 16:15:09 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
// Wait for the signal handler to run before moving on to the next one
|
|
|
|
while (sCurrentThreadProfile)
|
|
|
|
sched_yield();
|
|
|
|
}
|
|
|
|
}
|
2013-04-18 16:15:09 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
// Convert ms to us and subtract 100 us to compensate delays
|
|
|
|
// occuring during signal delivery.
|
|
|
|
// TODO measure and confirm this.
|
|
|
|
const useconds_t interval =
|
|
|
|
SamplerRegistry::sampler->interval() * 1000 - 100;
|
|
|
|
//int result = usleep(interval);
|
|
|
|
usleep(interval);
|
|
|
|
}
|
2013-04-16 22:53:03 +04:00
|
|
|
return initialize_atfork; // which is guaranteed to be NULL
|
2011-08-27 04:05:37 +04:00
|
|
|
}
|
|
|
|
|
2013-03-29 23:34:49 +04:00
|
|
|
Sampler::Sampler(int interval, bool profiling, int entrySize)
|
2011-08-27 04:05:37 +04:00
|
|
|
: interval_(interval),
|
|
|
|
profiling_(profiling),
|
2012-06-14 03:24:48 +04:00
|
|
|
paused_(false),
|
2013-03-29 23:34:49 +04:00
|
|
|
active_(false),
|
|
|
|
entrySize_(entrySize) {
|
2011-08-27 04:05:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Sampler::~Sampler() {
|
2013-04-04 02:59:17 +04:00
|
|
|
ASSERT(!signal_sender_launched_);
|
2011-08-27 04:05:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Sampler::Start() {
|
2013-03-11 02:00:23 +04:00
|
|
|
LOG("Sampler started");
|
2013-04-04 02:59:17 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
SamplerRegistry::AddActiveSampler(this);
|
|
|
|
|
2011-08-27 04:05:37 +04:00
|
|
|
// Request profiling signals.
|
|
|
|
LOG("Request signal");
|
|
|
|
struct sigaction sa;
|
|
|
|
sa.sa_sigaction = ProfilerSignalHandler;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
2013-04-04 02:59:17 +04:00
|
|
|
if (sigaction(SIGPROF, &sa, &old_sigprof_signal_handler_) != 0) {
|
2011-08-27 04:05:37 +04:00
|
|
|
LOG("Error installing signal");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Request save profile signals
|
|
|
|
struct sigaction sa2;
|
|
|
|
sa2.sa_sigaction = ProfilerSaveSignalHandler;
|
|
|
|
sigemptyset(&sa2.sa_mask);
|
|
|
|
sa2.sa_flags = SA_RESTART | SA_SIGINFO;
|
2013-04-04 02:59:17 +04:00
|
|
|
if (sigaction(SIGNAL_SAVE_PROFILE, &sa2, &old_sigsave_signal_handler_) != 0) {
|
2011-08-27 04:05:37 +04:00
|
|
|
LOG("Error installing start signal");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LOG("Signal installed");
|
2013-04-04 02:59:17 +04:00
|
|
|
signal_handler_installed_ = true;
|
2011-08-27 04:05:37 +04:00
|
|
|
|
|
|
|
// Start a thread that sends SIGPROF signal to VM thread.
|
|
|
|
// Sending the signal ourselves instead of relying on itimer provides
|
|
|
|
// much better accuracy.
|
2011-10-31 21:25:04 +04:00
|
|
|
SetActive(true);
|
2011-08-27 04:05:37 +04:00
|
|
|
if (pthread_create(
|
2013-04-04 02:59:17 +04:00
|
|
|
&signal_sender_thread_, NULL, SignalSender, NULL) == 0) {
|
|
|
|
signal_sender_launched_ = true;
|
2011-08-27 04:05:37 +04:00
|
|
|
}
|
|
|
|
LOG("Profiler thread started");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Sampler::Stop() {
|
2011-10-31 21:25:04 +04:00
|
|
|
SetActive(false);
|
2011-08-27 04:05:37 +04:00
|
|
|
|
|
|
|
// Wait for signal sender termination (it will exit after setting
|
|
|
|
// active_ to false).
|
2013-04-04 02:59:17 +04:00
|
|
|
if (signal_sender_launched_) {
|
|
|
|
pthread_join(signal_sender_thread_, NULL);
|
|
|
|
signal_sender_launched_ = false;
|
2011-08-27 04:05:37 +04:00
|
|
|
}
|
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
SamplerRegistry::RemoveActiveSampler(this);
|
|
|
|
|
2011-08-27 04:05:37 +04:00
|
|
|
// Restore old signal handler
|
2013-04-04 02:59:17 +04:00
|
|
|
if (signal_handler_installed_) {
|
|
|
|
sigaction(SIGNAL_SAVE_PROFILE, &old_sigsave_signal_handler_, 0);
|
|
|
|
sigaction(SIGPROF, &old_sigprof_signal_handler_, 0);
|
|
|
|
signal_handler_installed_ = false;
|
2013-03-29 23:34:49 +04:00
|
|
|
}
|
2013-03-29 23:34:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Sampler::RegisterCurrentThread(const char* aName, PseudoStack* aPseudoStack, bool aIsMainThread)
|
|
|
|
{
|
2013-04-04 02:59:17 +04:00
|
|
|
mozilla::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
|
|
|
|
|
|
|
|
ThreadInfo* info = new ThreadInfo(aName, gettid(),
|
|
|
|
aIsMainThread, aPseudoStack);
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
bool profileThread = sActiveSampler &&
|
|
|
|
(aIsMainThread || sActiveSampler->ProfileThreads());
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
if (profileThread) {
|
2013-03-29 23:34:49 +04:00
|
|
|
// We need to create the ThreadProfile now
|
|
|
|
info->SetProfile(new ThreadProfile(info->Name(),
|
|
|
|
sActiveSampler->EntrySize(),
|
|
|
|
info->Stack(),
|
|
|
|
info->ThreadId(),
|
2013-04-04 02:59:17 +04:00
|
|
|
info->GetPlatformData(),
|
2013-03-29 23:34:49 +04:00
|
|
|
aIsMainThread));
|
2013-04-04 02:59:17 +04:00
|
|
|
if (sActiveSampler->ProfileJS()) {
|
|
|
|
info->Profile()->GetPseudoStack()->enableJSSampling();
|
|
|
|
}
|
2013-03-29 23:34:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sRegisteredThreads->push_back(info);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sampler::UnregisterCurrentThread()
|
|
|
|
{
|
2013-04-04 02:59:17 +04:00
|
|
|
mozilla::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
|
2013-03-29 23:34:49 +04:00
|
|
|
|
|
|
|
int id = gettid();
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-03-29 23:34:49 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2011-08-27 04:05:37 +04:00
|
|
|
}
|
|
|
|
|
2012-07-11 19:28:04 +04:00
|
|
|
#ifdef ANDROID
|
2012-07-11 18:55:22 +04:00
|
|
|
static struct sigaction old_sigstart_signal_handler;
|
|
|
|
const int SIGSTART = SIGUSR1;
|
2012-03-02 23:11:47 +04:00
|
|
|
|
2012-07-11 18:55:22 +04:00
|
|
|
static void StartSignalHandler(int signal, siginfo_t* info, void* context) {
|
2013-03-16 08:47:02 +04:00
|
|
|
profiler_start(PROFILE_DEFAULT_ENTRY, PROFILE_DEFAULT_INTERVAL,
|
|
|
|
PROFILE_DEFAULT_FEATURES, PROFILE_DEFAULT_FEATURE_COUNT);
|
2012-03-02 23:11:47 +04:00
|
|
|
}
|
|
|
|
|
2012-07-11 18:55:22 +04:00
|
|
|
void OS::RegisterStartHandler()
|
2012-03-02 23:11:47 +04:00
|
|
|
{
|
2012-07-11 18:55:22 +04:00
|
|
|
LOG("Registering start signal");
|
2012-03-02 23:11:47 +04:00
|
|
|
struct sigaction sa;
|
2012-07-11 18:55:22 +04:00
|
|
|
sa.sa_sigaction = StartSignalHandler;
|
2012-03-02 23:11:47 +04:00
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
2012-07-11 18:55:22 +04:00
|
|
|
if (sigaction(SIGSTART, &sa, &old_sigstart_signal_handler) != 0) {
|
2012-03-02 23:11:47 +04:00
|
|
|
LOG("Error installing signal");
|
|
|
|
}
|
|
|
|
}
|
2012-07-11 19:28:04 +04:00
|
|
|
#endif
|
2013-03-29 23:34:49 +04:00
|
|
|
|