mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
7adb8133f5
- missing bit of 989499 and some other files (23b0597ba6) - Bug 1233666 - Remove hacks for getting frame pointer for x86/x64 gcc. r=glandium (bfe8f59916) - Bug 1176266: In TimeStamp_posix.cpp, check for XP_LINUX instead of LINUX, and add missing #include, to allow strrchr usage. r=BenWa (56c725cffa) - Bug 1167230 - Don't pack ProfileEntry on ARM. r=shu (89f880e0cb) - Bug 1209779 - Ensure that all null elements are written when streaming profiler JSON; r=shu (2bae5addc6) - missing bit of Bug 1141712 - Make LUL (55f1276545) - Bug 1061800 - Add breakpad ids to profiler in Linux. r=BenWa (994fd1a941) - Bug 829621 - Compute the breakpad-id for OS X. r=BenWa. (e129580174) - missing of Bug 938157 - Lightweight CFI/EXIDX (b355dc3140) - Bug 1193838 - Allow ProfileGatherer to gather profiles from exiting processes. r=BenWa (5ab1a6a3c9) - align some missing stuff (5ebecd2364) - align some missing stuff (b8ff7aa361) - Bug 1164315 - Update key fingerprint for bitbucket.org; r=me (c1a3fbd930) - Bug 1178955 - Refactor config path selection; r=smacleod (89552bb0ac) - Bug 1195445 - Update host key fingerprint for bugzilla.mozilla.org (3783541088) - Bug 1218903 - Update bmo fingerprint. r=fubar, a=Tomcat (5b836fc585) - Bug 1178955 - Print config path on failure; r=smacleod (f5499f3771) - Bug 1185113 - Support setting more secure file permissions; r=smacleod (7dbf6b22fd) - Bug 1184229 - Detect multiple version-control-tools repos in Mercurial config; r=smacleod (16c24072a9) - Bug 978514 - mach mercurial-setup: Use mqext from the version-control-tools repo (1fa5765e8a) - Bug 1178955 - Don't pass config paths to updater; r=smacleod (80fcb05121) - Bug 1197527 - Don't unnecessarily attempt to create extensions directory in MercurialUpdater; r=gps (9b049c3ff8) - Bug 1164812 - mach mercurial-setup: Always mark the v-c-t repo as needing update (bd631208bd) - Bug 1197527 - Always clone version-control-tools in MercurialSetupWizard; r=gps (6990e8f589) - Bug 1197527 - Consolidate obtaining hg path into mozversioncontrol.get_hg_path; r=gps (e0b029a8e9) - Bug 1200458 - Skip permission check for .hgrc on Windows in hgsetup wizard. r=gps DONTBUILD (cc5b0d6daf) - Bug 1168466 - Bump minimum Mercurial version; r=smacleod (7fde47cfbe) - Bug 1185113 - Clarify language around Bugzilla credentials; r=smacleod (9166fdfbf9) - Bug 1185112 - Don't prompt for Bugzilla username/password if cookies defined; r=smacleod (cd87c96823) - Bug 1188931 - Fix hgsetup wizard. r=gps (68a6b46be4) - Bug 1200461 - Prompt for Bugzilla API Key instead of password; r=smacleod (780fb5d85d) - Bug 1228580 - ./mach mercurial-setup should use ~ to set up extension paths, not my literal home directory. r=gps (7a0c839880) - Bug 1231192 - Mark Mercurial 3.5.2 as oldest non-legacy version; r=smacleod (8f69483333) - Bug 1231192 - Bump some minimum Mercurial version; r=smacleod (916c56a852) - Bug 1162093 - Add "push-to-try" from version-control-tools to the mercurial setup wizard prompt.;r=gps (d29c7cf63a) - Bug 1168466 - Prompt to install bundleclone extension; r=smacleod (780ce90a08) - Bug 1185557 - Print relevant config options; r=smacleod (2f3f7e0161) - Bug 1231192 - Support clonebundles feature; r=smacleod (dcba1ccd34) - Bug 1231192 - Offer to install hg wip; r=smacleod (c42ebce5c8) - Bug 1231192 - Only install host fingerprints if not running secure Python+hg; r=smacleod (3154a2497b) - Bug 1178955 - Error when semicolon comments are seen; r=smacleod (e1f7081bb6) - Bug 1231989 - Prompt to install hgwatchman extension; r=ahal (0eddf0c1c8) - Bug 1178955 - Print line number for parse errors; r=smacleod (5369468cf1) - Bug 1185557 - Only prompt to install progress on Mercurial <3.5; r=smacleod (401f362265) - Bug 1232747 - Check for ssl.SSLContext existence; r=dminor (d505b07c5c) - Bug 1144629 - UnicodeDecodeError in ./mach mercurial-setup. r=gps, r=glandium (611d3ec83e) - Bug 1216970 - Make the copying more obvious in ProfilerImpl::GetStacktrace. r=froydnj (085625e113) - Bug 1190466 - tools/rb/find-leakers.pl re-written in Python r=mccr8 (4bfdcad13e) - Bug 1116478 - Open web content handlers in the proper tab in e10s. r=billm (ff8e11f45e) - Bug 1213437 - Less data copying when handling structured clones in MessageManager, r=baku (c4e2a13253) - const-var (69d17f312d) - Bug 1203090 - Ensure we always use '/' as the starting path separator for the DOM path of the Directorys initially returned by HTMLInputElement.getFilesAndDirectories. r=baku (1325bbc40c) - Bug 1209975 - Stop using dom::Promise::MaybeRejectBrokenly() in GetDirectoryListingTask. r=baku (2106790950) - Bug 1209924 - Implement a general filtering mechanism for Directory::GetFilesAndDirectories, and add filtering of sensitive files/directories. r=baku (27b4a26262) - Force a repaint after DXGI device resets. (bug 1188019, r=bas) (09c999e6e5) - Bug 1163911 - Make responsive images block the document load event while the load task is queued. r=jst (0ee0e3db79) - Bug 1166138 - Make img srcset react to resize/viewport changes, r=jdm (91674519e6) - Bug 1194893 - Pref for default file upload directory. r=smaug (ec6d33d983) - bug 1116409: switch update server to sha2 cert; update in-tree pinning. r=rstrong,snorp,mfinkle,dkeeler (7c8f631f27) - bug 1116409: fix cert pinning on backup cert for aus5.mozilla.org. r=typofix (3c690cbc6d) - Bug 1167048 - Change default font for Thai script from serif to sans-serif. r=smontagu (15dc86c389) - Bug 1205570 - fix up font prefs for x-math lang group. r=heycam (03f1820752) - Bug 1071769: Use DrawTargetTiled on B2G. r=Bas (b80ce768f1) - fix misspatch of 1149343 (541dd7aac8) - Bug 1199766 - Disable ICE TCP SO gathering via user pref. r=bwc (80cdc9c662) - Bug 1187472 - only log UDP and TCP candidate gathering failures. r=bwc (bc3dcb02d0) - Bug 1190615 - Skip non-UDP STUN servers for UDP sockets. r=bwc (a2d1d914b5) - Bug 1187775 - skip host and reflexive ICE candidates if relay-only. r=bwc (7e2cba1685) - Bug 1185198 - use port 9 for TCP active candidates. r=bwc (0a89cb199d) - Bug 1177921 - Fix typo in STUN server name. r=drno (1ad43ced6b) - Bug 1178349 - Enable ice_unittests on desktop linux on CI. r=bwc (ce5ece8264) - Bug 1189041 - Add option to only gather addresses for default route. r=bwc (3651f2ff06) - Bug 1189040: add a whitelist for network interfaces to use with ICE/webrtc r=ekr (6f693af72c) - Bug 1189198 - don't start STUN transactions with a protocol mis-match. r=mtseng (a3b410e2a8) - Bug 1208096 - Handle various failure cases for TURN gathering better. r=drno (1d8e173448) - Bug 1211389 - Make absolutely sure the relay->srflx pointer doesn't dangle. r=drno (d59b0bf08d) - Bug 1215616: use base address for server rflx ICE candidates r=bwc (89d07331ac) - Bug 1207451 - removed framing from multi_tcp API. r=bwc (317f40f490) - Bug 1186590 - Part 1 - Enable interface prioritizer on all platforms. r=drno (036a69fdb3) - Bug 1194019 - New defaults for gather tests. r=bwc (8343ceab56) - Bug 1144933: Only check that remote candidate is loopback in TestLoopbackOnlySortOf. r=drno (1f53d824e4) - Bug 1186590 - Part 2 - Move hard-coded interface priority list into nrinterfaceprioritizer, and simplify some functions. r=drno (9f20fad21b) - Bug 1152137 - Part 1: Test case. r=ekr (6b50f06d90) - Bug 1152137 - Part 2: Remove attributes that could not be initted properly instead of just freeing them. r=ekr (ccdf81294a) - Bug 1200763 - Remove hard-coded STUN IP address from ice_unittest, and do a DNS lookup instead. r=drno (ae54a83363) - Bug 1208176 - Part 1: Add a couple of interface names. r=drno (b7ead0b476) - Bug 1208176 - Part 2: Add a one-sided trickle test case to ice_unittest. r=drno (ad6afedb1c) - Bug 1037618 - Relax candidate verification for TCP. r=bwc (0cad14c89e) - Bug 1208176 - Part 3: Be forgiving when we see prflx instead of host candidates in ice_unittest. r=drno (50bdec2ba3) - Bug 1035428: Re-register writeable callback after partially servicing the send queue. r=drno (2fdb7880fa) - Bug 1135753 - Mark some overridden virtual functions in WebRTC as MOZ_OVERRIDE; r=mt (97f451c97d) - Bug 950660: Part 4: Bridge TCPSocketChild to nr_socket r=bwc,jdm (654587b321) - Bug 971357: Log STUN responses at INFO instead of DEBUG. r=ekr (81b500df17) - Bug 1006809 - update triggered check behavior to RFC 5245. r+bwc r=mjf (31b718b5e5) - Bug 1208278 - improved STUN request timeout handling. r=bwc (cf470fb12f) - Bug 1142964 - Fix ICE tiebreaker on Windows. r=bwc (0d2fd78252) - Bug 1219557 - don't pair candidates from different reserved networks. r=mt r=bwc (24d3e5106c) - Bug 1220441 - Improve gather trickle ice unit tests. r=bwc r=mjf (96f76c6c8c) - Bug 1205421 - fix DNS resolution of STUN server in ice_unittest. r=bwc (5d5b153358) - Bug 1206465 - removed ice_ctx from TestStunTcpServer. r=bwc (9a0df03894) - ug 1008792 - Check for valid pointer before using. r=bwc (7660fd0a71) - Bug 1233101 - Use MOZ_LIKELY in js_new etc to help branch prediction; r=terrence (31fb244734) - Bug 1225565 - Fix module import cycle detection r=shu (370dc26ee8) - Bug 1225558 - Improve module error messages r=shu (83b6038bb3) - Bug 1225561 - Don't allow a module to export non-existent local bindings r=shu (41f065891a) - Bug 1233124 - Remove mis-named duplicate typedefs for rooted import and export entries r=terrence (17a60bdb39) - Bug 1208464 - Implement proposed ES7 functions Object.values and Object.entries. r=evilpie (615193d0fb) - Bug 1226549 - added assert check for matches pointer in for prevent null dereference. r=hv1989 (d321ad0385) - Bug 1232113 - "Make the format specifiers in JS_snprintf() invocations more portable". r=jcoppeard (7c58b79a53) - Bug 1232446 - Re-enable method calls in SelfHosted code using new anti-content checks. (r=till) (ba7dc22ff8) - Bug 1232159 - Stop using pseudo-Uint32Array in SelfHosted code. (r=till) (c325f8ff58) - Bug 1226235 - Print file and line info for failing assert in self-hosted code. r=efaust (4a8d54d38b) - fix misspatch (fca2efc1f1) - Bug 1186003 - Switch automated builds to Gtk+3. r=mshal (658ad843b7) - Bug 1181342 - tooltool manifests and build-clang config for clang 3.6 r=rail (6264b4df68) - Bug 1181342 - Follow up to use the unpack feature of tooltool instead of setup.sh r=glandium (96bb3b2062) - Bug 1181255 - Mozconfigs for tsan builds. r=glandium (19250f4cc1) - Bug 1181255 - Get tsan builds on gtk3. r=glandium (e5ffd1c02f) - Bug 1187664 - Create a fontconfig cache so that Firefox doesn't have to do it itself when run on build automation. r=mshal (8ce567bd4c) - Bug 1188780 - Include debug symbols in gtk3 tooltool package. r=mshal (a5b573aa58) - Bug 1188780: remove setup.sh invocations, as they fail outside the mock environment; r=glandium a=RyanVM (058e306cac) - Bug 1178513 - Fix non-unified bustage. r=wchen (543d1e5497) - Bug 1162789 - Add a comment explaining why mForm is not set to null during unlink (eaa2a82048) - Bug 1189655 - Define MOZ_HAVE_CXX11_CONSTEXPR on VS2015 or later. r=Waldo (2d134e3b41) - Bug 1231758 - Fix bogus assertion in BCE for Annex B function assignment. (r=jorendorff) (701b2530b9) - Bug 1233100 - Ensure that derived constructor bad return value errors are thrown before leaving the containing block. (r=shu) (52f5bcf0a5) - Bug 1232022, 1232449 - Address forgotten review nits and fix bogus error message. (rs=Waldo) (dfd9d5e388) - Bug 1233121 - Refactor ObjectBox tracing r=terrence (876a140535) - Bug 1231647 - Check for duplicate exported let and const in modules r=shu (99f53ad443)
734 lines
22 KiB
C++
734 lines
22 KiB
C++
// Copyright (c) 2006-2011 The Chromium Authors. All rights reserved.
|
|
//
|
|
// 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.
|
|
|
|
/*
|
|
# vim: sw=2
|
|
*/
|
|
#include <stdio.h>
|
|
#include <math.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 <sys/prctl.h> // set name
|
|
#include <stdlib.h>
|
|
#include <sched.h>
|
|
#ifdef ANDROID
|
|
#include <android/log.h>
|
|
#else
|
|
#define __android_log_print(a, ...)
|
|
#endif
|
|
#include <ucontext.h>
|
|
// 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
|
|
#include <semaphore.h>
|
|
#ifdef __GLIBC__
|
|
#include <execinfo.h> // backtrace, backtrace_symbols
|
|
#endif // def __GLIBC__
|
|
#include <strings.h> // index
|
|
#include <errno.h>
|
|
#include <stdarg.h>
|
|
#include "prenv.h"
|
|
#include "platform.h"
|
|
#include "GeckoProfiler.h"
|
|
#include "mozilla/Mutex.h"
|
|
#include "mozilla/Atomics.h"
|
|
#include "mozilla/LinuxSignal.h"
|
|
#include "mozilla/TimeStamp.h"
|
|
#include "mozilla/DebugOnly.h"
|
|
#include "ProfileEntry.h"
|
|
#include "nsThreadUtils.h"
|
|
#include "GeckoSampler.h"
|
|
#include "ThreadResponsiveness.h"
|
|
|
|
#if defined(__ARM_EABI__) && defined(MOZ_WIDGET_GONK)
|
|
// Should also work on other Android and ARM Linux, but not tested there yet.
|
|
# define USE_EHABI_STACKWALK
|
|
# include "EHABIStackWalk.h"
|
|
#elif defined(SPS_PLAT_amd64_linux) || defined(SPS_PLAT_x86_linux)
|
|
# define USE_LUL_STACKWALK
|
|
# include "lul/LulMain.h"
|
|
# include "lul/platform-linux-lul.h"
|
|
#endif
|
|
|
|
// Memory profile
|
|
#include "nsMemoryReporterManager.h"
|
|
|
|
#include <string.h>
|
|
#include <list>
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
#include "ipc/Nuwa.h"
|
|
#endif
|
|
|
|
#define SIGNAL_SAVE_PROFILE SIGUSR2
|
|
|
|
using namespace mozilla;
|
|
|
|
#if defined(USE_LUL_STACKWALK)
|
|
// A singleton instance of the library. It is initialised at first
|
|
// use. Currently only the main thread can call Sampler::Start, so
|
|
// there is no need for a mechanism to ensure that it is only
|
|
// created once in a multi-thread-use situation.
|
|
lul::LUL* sLUL = nullptr;
|
|
|
|
// This is the sLUL initialization routine.
|
|
static void sLUL_initialization_routine(void)
|
|
{
|
|
MOZ_ASSERT(!sLUL);
|
|
MOZ_ASSERT(gettid() == getpid()); /* "this is the main thread" */
|
|
sLUL = new lul::LUL(logging_sink_for_LUL);
|
|
// Read all the unwind info currently available.
|
|
read_procmaps(sLUL);
|
|
}
|
|
#endif
|
|
|
|
/* static */ Thread::tid_t
|
|
Thread::GetCurrentId()
|
|
{
|
|
return gettid();
|
|
}
|
|
|
|
#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) {
|
|
if (Sampler::GetActiveSampler()) {
|
|
was_paused = Sampler::GetActiveSampler()->IsPaused();
|
|
Sampler::GetActiveSampler()->SetPaused(true);
|
|
} else {
|
|
was_paused = false;
|
|
}
|
|
}
|
|
|
|
// In the parent, just after the fork, return pausedness to the
|
|
// pre-fork state.
|
|
static void paf_parent(void) {
|
|
if (Sampler::GetActiveSampler())
|
|
Sampler::GetActiveSampler()->SetPaused(was_paused);
|
|
}
|
|
|
|
// Set up the fork handlers.
|
|
static void* setup_atfork() {
|
|
pthread_atfork(paf_prepare, paf_parent, NULL);
|
|
return NULL;
|
|
}
|
|
#endif /* !defined(ANDROID) */
|
|
|
|
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;
|
|
|
|
static mozilla::Atomic<ThreadProfile*> sCurrentThreadProfile;
|
|
static sem_t sSignalHandlingDone;
|
|
|
|
static void ProfilerSaveSignalHandler(int signal, siginfo_t* info, void* context) {
|
|
Sampler::GetActiveSampler()->RequestSave();
|
|
}
|
|
|
|
static void SetSampleContext(TickSample* sample, void* context)
|
|
{
|
|
// 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.
|
|
#if !defined(ANDROID) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3))
|
|
sample->pc = reinterpret_cast<Address>(mcontext.gregs[R15]);
|
|
sample->sp = reinterpret_cast<Address>(mcontext.gregs[R13]);
|
|
sample->fp = reinterpret_cast<Address>(mcontext.gregs[R11]);
|
|
#ifdef ENABLE_ARM_LR_SAVING
|
|
sample->lr = reinterpret_cast<Address>(mcontext.gregs[R14]);
|
|
#endif
|
|
#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);
|
|
#ifdef ENABLE_ARM_LR_SAVING
|
|
sample->lr = reinterpret_cast<Address>(mcontext.arm_lr);
|
|
#endif
|
|
#endif
|
|
#elif V8_HOST_ARCH_MIPS
|
|
// Implement this on MIPS.
|
|
UNIMPLEMENTED();
|
|
#endif
|
|
}
|
|
|
|
#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
|
|
|
|
namespace {
|
|
|
|
void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
|
|
if (!Sampler::GetActiveSampler()) {
|
|
sem_post(&sSignalHandlingDone);
|
|
return;
|
|
}
|
|
|
|
TickSample sample_obj;
|
|
TickSample* sample = &sample_obj;
|
|
sample->context = context;
|
|
|
|
// If profiling, we extract the current pc and sp.
|
|
if (Sampler::GetActiveSampler()->IsProfiling()) {
|
|
SetSampleContext(sample, context);
|
|
}
|
|
sample->threadProfile = sCurrentThreadProfile;
|
|
sample->timestamp = mozilla::TimeStamp::Now();
|
|
sample->rssMemory = sample->threadProfile->mRssMemory;
|
|
sample->ussMemory = sample->threadProfile->mUssMemory;
|
|
|
|
Sampler::GetActiveSampler()->Tick(sample);
|
|
|
|
sCurrentThreadProfile = NULL;
|
|
sem_post(&sSignalHandlingDone);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
static void ProfilerSignalThread(ThreadProfile *profile,
|
|
bool isFirstProfiledThread)
|
|
{
|
|
if (isFirstProfiledThread && Sampler::GetActiveSampler()->ProfileMemory()) {
|
|
profile->mRssMemory = nsMemoryReporterManager::ResidentFast();
|
|
profile->mUssMemory = nsMemoryReporterManager::ResidentUnique();
|
|
} else {
|
|
profile->mRssMemory = 0;
|
|
profile->mUssMemory = 0;
|
|
}
|
|
}
|
|
|
|
int tgkill(pid_t tgid, pid_t tid, int signalno) {
|
|
return syscall(SYS_tgkill, tgid, tid, signalno);
|
|
}
|
|
|
|
class PlatformData {
|
|
public:
|
|
PlatformData()
|
|
{}
|
|
};
|
|
|
|
/* static */ PlatformData*
|
|
Sampler::AllocPlatformData(int aThreadId)
|
|
{
|
|
return new PlatformData;
|
|
}
|
|
|
|
/* static */ void
|
|
Sampler::FreePlatformData(PlatformData* aData)
|
|
{
|
|
delete aData;
|
|
}
|
|
|
|
static void* SignalSender(void* arg) {
|
|
// Taken from platform_thread_posix.cc
|
|
prctl(PR_SET_NAME, "SamplerThread", 0, 0, 0);
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
// If the Nuwa process is enabled, we need to mark and freeze the sampler
|
|
// thread in the Nuwa process and have this thread recreated in the spawned
|
|
// child.
|
|
if(IsNuwaProcess()) {
|
|
NuwaMarkCurrentThread(nullptr, nullptr);
|
|
// Freeze the thread here so the spawned child will get the correct tgid
|
|
// from the getpid() call below.
|
|
NuwaFreezeCurrentThread();
|
|
}
|
|
#endif
|
|
|
|
int vm_tgid_ = getpid();
|
|
DebugOnly<int> my_tid = gettid();
|
|
|
|
unsigned int nSignalsSent = 0;
|
|
|
|
TimeDuration lastSleepOverhead = 0;
|
|
TimeStamp sampleStart = TimeStamp::Now();
|
|
while (SamplerRegistry::sampler->IsActive()) {
|
|
|
|
SamplerRegistry::sampler->HandleSaveRequest();
|
|
SamplerRegistry::sampler->DeleteExpiredMarkers();
|
|
|
|
if (!SamplerRegistry::sampler->IsPaused()) {
|
|
::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
|
|
std::vector<ThreadInfo*> threads =
|
|
SamplerRegistry::sampler->GetRegisteredThreads();
|
|
|
|
bool isFirstProfiledThread = true;
|
|
for (uint32_t i = 0; i < threads.size(); i++) {
|
|
ThreadInfo* info = threads[i];
|
|
|
|
// This will be null if we're not interested in profiling this thread.
|
|
if (!info->Profile() || info->IsPendingDelete())
|
|
continue;
|
|
|
|
PseudoStack::SleepState sleeping = info->Stack()->observeSleeping();
|
|
if (sleeping == PseudoStack::SLEEPING_AGAIN) {
|
|
info->Profile()->DuplicateLastSample();
|
|
continue;
|
|
}
|
|
|
|
info->Profile()->GetThreadResponsiveness()->Update();
|
|
|
|
// We use sCurrentThreadProfile the ThreadProfile for the
|
|
// thread we're profiling to the signal handler
|
|
sCurrentThreadProfile = info->Profile();
|
|
|
|
int threadId = info->ThreadId();
|
|
MOZ_ASSERT(threadId != my_tid);
|
|
|
|
// Profile from the signal sender for information which is not signal
|
|
// safe, and will have low variation between the emission of the signal
|
|
// and the signal handler catch.
|
|
ProfilerSignalThread(sCurrentThreadProfile, isFirstProfiledThread);
|
|
|
|
// Profile from the signal handler for information which is signal safe
|
|
// and needs to be precise too, such as the stack of the interrupted
|
|
// thread.
|
|
if (tgkill(vm_tgid_, threadId, SIGPROF) != 0) {
|
|
printf_stderr("profiler failed to signal tid=%d\n", threadId);
|
|
#ifdef DEBUG
|
|
abort();
|
|
#else
|
|
continue;
|
|
#endif
|
|
}
|
|
|
|
// Wait for the signal handler to run before moving on to the next one
|
|
sem_wait(&sSignalHandlingDone);
|
|
isFirstProfiledThread = false;
|
|
|
|
// The LUL unwind object accumulates frame statistics.
|
|
// Periodically we should poke it to give it a chance to print
|
|
// those statistics. This involves doing I/O (fprintf,
|
|
// __android_log_print, etc) and so can't safely be done from
|
|
// the unwinder threads, which is why it is done here.
|
|
if ((++nSignalsSent & 0xF) == 0) {
|
|
# if defined(USE_LUL_STACKWALK)
|
|
sLUL->MaybeShowStats();
|
|
# endif
|
|
}
|
|
}
|
|
}
|
|
|
|
TimeStamp targetSleepEndTime = sampleStart + TimeDuration::FromMicroseconds(SamplerRegistry::sampler->interval() * 1000);
|
|
TimeStamp beforeSleep = TimeStamp::Now();
|
|
TimeDuration targetSleepDuration = targetSleepEndTime - beforeSleep;
|
|
double sleepTime = std::max(0.0, (targetSleepDuration - lastSleepOverhead).ToMicroseconds());
|
|
OS::SleepMicro(sleepTime);
|
|
sampleStart = TimeStamp::Now();
|
|
lastSleepOverhead = sampleStart - (beforeSleep + TimeDuration::FromMicroseconds(sleepTime));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
Sampler::Sampler(double interval, bool profiling, int entrySize)
|
|
: interval_(interval),
|
|
profiling_(profiling),
|
|
paused_(false),
|
|
active_(false),
|
|
entrySize_(entrySize) {
|
|
}
|
|
|
|
Sampler::~Sampler() {
|
|
ASSERT(!signal_sender_launched_);
|
|
}
|
|
|
|
|
|
void Sampler::Start() {
|
|
LOG("Sampler started");
|
|
|
|
#if defined(USE_EHABI_STACKWALK)
|
|
mozilla::EHABIStackWalkInit();
|
|
#elif defined(USE_LUL_STACKWALK)
|
|
// NOTE: this isn't thread-safe. But we expect Sampler::Start to be
|
|
// called only from the main thread, so this is OK in general.
|
|
if (!sLUL) {
|
|
sLUL_initialization_routine();
|
|
}
|
|
#endif
|
|
|
|
SamplerRegistry::AddActiveSampler(this);
|
|
|
|
// Initialize signal handler communication
|
|
sCurrentThreadProfile = NULL;
|
|
if (sem_init(&sSignalHandlingDone, /* pshared: */ 0, /* value: */ 0) != 0) {
|
|
LOG("Error initializing semaphore");
|
|
return;
|
|
}
|
|
|
|
// Request profiling signals.
|
|
LOG("Request signal");
|
|
struct sigaction sa;
|
|
sa.sa_sigaction = MOZ_SIGNAL_TRAMPOLINE(ProfilerSignalHandler);
|
|
sigemptyset(&sa.sa_mask);
|
|
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
|
if (sigaction(SIGPROF, &sa, &old_sigprof_signal_handler_) != 0) {
|
|
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;
|
|
if (sigaction(SIGNAL_SAVE_PROFILE, &sa2, &old_sigsave_signal_handler_) != 0) {
|
|
LOG("Error installing start signal");
|
|
return;
|
|
}
|
|
LOG("Signal installed");
|
|
signal_handler_installed_ = true;
|
|
|
|
#if defined(USE_LUL_STACKWALK)
|
|
// Switch into unwind mode. After this point, we can't add or
|
|
// remove any unwind info to/from this LUL instance. The only thing
|
|
// we can do with it is Unwind() calls.
|
|
sLUL->EnableUnwinding();
|
|
|
|
// Has a test been requested?
|
|
if (PR_GetEnv("MOZ_PROFILER_LUL_TEST")) {
|
|
int nTests = 0, nTestsPassed = 0;
|
|
RunLulUnitTests(&nTests, &nTestsPassed, sLUL);
|
|
}
|
|
#endif
|
|
|
|
// Start a thread that sends SIGPROF signal to VM thread.
|
|
// Sending the signal ourselves instead of relying on itimer provides
|
|
// much better accuracy.
|
|
SetActive(true);
|
|
if (pthread_create(
|
|
&signal_sender_thread_, NULL, SignalSender, NULL) == 0) {
|
|
signal_sender_launched_ = true;
|
|
}
|
|
LOG("Profiler thread started");
|
|
}
|
|
|
|
|
|
void Sampler::Stop() {
|
|
SetActive(false);
|
|
|
|
// Wait for signal sender termination (it will exit after setting
|
|
// active_ to false).
|
|
if (signal_sender_launched_) {
|
|
pthread_join(signal_sender_thread_, NULL);
|
|
signal_sender_launched_ = false;
|
|
}
|
|
|
|
SamplerRegistry::RemoveActiveSampler(this);
|
|
|
|
// Restore old signal handler
|
|
if (signal_handler_installed_) {
|
|
sigaction(SIGNAL_SAVE_PROFILE, &old_sigsave_signal_handler_, 0);
|
|
sigaction(SIGPROF, &old_sigprof_signal_handler_, 0);
|
|
signal_handler_installed_ = false;
|
|
}
|
|
}
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
static void
|
|
UpdateThreadId(void* aThreadInfo) {
|
|
ThreadInfo* info = static_cast<ThreadInfo*>(aThreadInfo);
|
|
// Note that this function is called during thread recreation. Only the thread
|
|
// calling this method is running. We can't try to acquire
|
|
// Sampler::sRegisteredThreadsMutex because it could be held by another
|
|
// thread.
|
|
info->SetThreadId(gettid());
|
|
}
|
|
#endif
|
|
|
|
bool Sampler::RegisterCurrentThread(const char* aName,
|
|
PseudoStack* aPseudoStack,
|
|
bool aIsMainThread, void* stackTop)
|
|
{
|
|
if (!Sampler::sRegisteredThreadsMutex)
|
|
return false;
|
|
|
|
::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
|
|
|
|
int id = gettid();
|
|
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;
|
|
}
|
|
}
|
|
|
|
set_tls_stack_top(stackTop);
|
|
|
|
ThreadInfo* info = new StackOwningThreadInfo(aName, id,
|
|
aIsMainThread, aPseudoStack, stackTop);
|
|
|
|
if (sActiveSampler) {
|
|
sActiveSampler->RegisterThread(info);
|
|
}
|
|
|
|
sRegisteredThreads->push_back(info);
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
if (IsNuwaProcess()) {
|
|
if (info->IsMainThread()) {
|
|
// Main thread isn't a marked thread. Register UpdateThreadId() to
|
|
// NuwaAddConstructor(), which runs before all other threads are
|
|
// recreated.
|
|
NuwaAddConstructor(UpdateThreadId, info);
|
|
} else {
|
|
// Register UpdateThreadInfo() to be run when the thread is recreated.
|
|
NuwaAddThreadConstructor(UpdateThreadId, info);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
return true;
|
|
}
|
|
|
|
void Sampler::UnregisterCurrentThread()
|
|
{
|
|
if (!Sampler::sRegisteredThreadsMutex)
|
|
return;
|
|
|
|
tlsStackTop.set(nullptr);
|
|
|
|
::MutexAutoLock lock(*Sampler::sRegisteredThreadsMutex);
|
|
|
|
int id = gettid();
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#ifdef ANDROID
|
|
static struct sigaction old_sigstart_signal_handler;
|
|
const int SIGSTART = SIGUSR2;
|
|
|
|
static void freeArray(const char** array, int size) {
|
|
for (int i = 0; i < size; i++) {
|
|
free((void*) array[i]);
|
|
}
|
|
}
|
|
|
|
static uint32_t readCSVArray(char* csvList, const char** buffer) {
|
|
uint32_t count;
|
|
char* savePtr;
|
|
int newlinePos = strlen(csvList) - 1;
|
|
if (csvList[newlinePos] == '\n') {
|
|
csvList[newlinePos] = '\0';
|
|
}
|
|
|
|
char* item = strtok_r(csvList, ",", &savePtr);
|
|
for (count = 0; item; item = strtok_r(NULL, ",", &savePtr)) {
|
|
int length = strlen(item) + 1; // Include \0
|
|
char* newBuf = (char*) malloc(sizeof(char) * length);
|
|
buffer[count] = newBuf;
|
|
strncpy(newBuf, item, length);
|
|
count++;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
// Currently support only the env variables
|
|
// reported in read_profiler_env
|
|
static void ReadProfilerVars(const char* fileName, const char** features,
|
|
uint32_t* featureCount, const char** threadNames, uint32_t* threadCount) {
|
|
FILE* file = fopen(fileName, "r");
|
|
const int bufferSize = 1024;
|
|
char line[bufferSize];
|
|
char* feature;
|
|
char* value;
|
|
char* savePtr;
|
|
|
|
if (file) {
|
|
while (fgets(line, bufferSize, file) != NULL) {
|
|
feature = strtok_r(line, "=", &savePtr);
|
|
value = strtok_r(NULL, "", &savePtr);
|
|
|
|
if (strncmp(feature, PROFILER_INTERVAL, bufferSize) == 0) {
|
|
set_profiler_interval(value);
|
|
} else if (strncmp(feature, PROFILER_ENTRIES, bufferSize) == 0) {
|
|
set_profiler_entries(value);
|
|
} else if (strncmp(feature, PROFILER_STACK, bufferSize) == 0) {
|
|
set_profiler_scan(value);
|
|
} else if (strncmp(feature, PROFILER_FEATURES, bufferSize) == 0) {
|
|
*featureCount = readCSVArray(value, features);
|
|
} else if (strncmp(feature, "threads", bufferSize) == 0) {
|
|
*threadCount = readCSVArray(value, threadNames);
|
|
}
|
|
}
|
|
|
|
fclose(file);
|
|
}
|
|
}
|
|
|
|
|
|
static void StartSignalHandler(int signal, siginfo_t* info, void* context) {
|
|
// XXX: Everything we do here is NOT async signal safe. We risk nasty things
|
|
// like deadlocks but we typically only do this once so it tends to be ok.
|
|
// See bug 909403
|
|
uint32_t featureCount = 0;
|
|
uint32_t threadCount = 0;
|
|
|
|
// Just allocate 10 features for now
|
|
// FIXME: these don't really point to const chars*
|
|
// So we free them later, but we don't want to change the const char**
|
|
// declaration in profiler_start. Annoying but ok for now.
|
|
const char* threadNames[10];
|
|
const char* features[10];
|
|
const char* profilerConfigFile = "/data/local/tmp/profiler.options";
|
|
|
|
ReadProfilerVars(profilerConfigFile, features, &featureCount, threadNames, &threadCount);
|
|
MOZ_ASSERT(featureCount < 10);
|
|
MOZ_ASSERT(threadCount < 10);
|
|
|
|
profiler_start(PROFILE_DEFAULT_ENTRY, 1,
|
|
features, featureCount,
|
|
threadNames, threadCount);
|
|
|
|
freeArray(threadNames, threadCount);
|
|
freeArray(features, featureCount);
|
|
}
|
|
|
|
void OS::Startup()
|
|
{
|
|
LOG("Registering start signal");
|
|
struct sigaction sa;
|
|
sa.sa_sigaction = StartSignalHandler;
|
|
sigemptyset(&sa.sa_mask);
|
|
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
|
if (sigaction(SIGSTART, &sa, &old_sigstart_signal_handler) != 0) {
|
|
LOG("Error installing signal");
|
|
}
|
|
}
|
|
|
|
#else
|
|
|
|
void OS::Startup() {
|
|
// Set up the fork handlers.
|
|
setup_atfork();
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void TickSample::PopulateContext(void* aContext)
|
|
{
|
|
MOZ_ASSERT(aContext);
|
|
ucontext_t* pContext = reinterpret_cast<ucontext_t*>(aContext);
|
|
if (!getcontext(pContext)) {
|
|
context = pContext;
|
|
SetSampleContext(this, aContext);
|
|
}
|
|
}
|
|
|
|
void OS::SleepMicro(int microseconds)
|
|
{
|
|
if (MOZ_UNLIKELY(microseconds >= 1000000)) {
|
|
// Use usleep for larger intervals, because the nanosleep
|
|
// code below only supports intervals < 1 second.
|
|
MOZ_ALWAYS_TRUE(!::usleep(microseconds));
|
|
return;
|
|
}
|
|
|
|
struct timespec ts;
|
|
ts.tv_sec = 0;
|
|
ts.tv_nsec = microseconds * 1000UL;
|
|
|
|
int rv = ::nanosleep(&ts, &ts);
|
|
|
|
while (rv != 0 && errno == EINTR) {
|
|
// Keep waiting in case of interrupt.
|
|
// nanosleep puts the remaining time back into ts.
|
|
rv = ::nanosleep(&ts, &ts);
|
|
}
|
|
|
|
MOZ_ASSERT(!rv, "nanosleep call failed");
|
|
}
|