2013-03-15 17:48:56 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef PROFILER_PSEUDO_STACK_H_
|
|
|
|
#define PROFILER_PSEUDO_STACK_H_
|
|
|
|
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2013-03-15 17:48:56 -07:00
|
|
|
#include "mozilla/NullPtr.h"
|
2013-07-30 07:25:31 -07:00
|
|
|
#include <stdint.h>
|
2013-08-19 23:45:26 -07:00
|
|
|
#include "js/ProfilingStack.h"
|
2013-03-15 17:48:56 -07:00
|
|
|
#include <stdlib.h>
|
2014-03-28 13:08:22 -07:00
|
|
|
#include "mozilla/Atomics.h"
|
2013-03-15 17:48:56 -07:00
|
|
|
|
|
|
|
/* we duplicate this code here to avoid header dependencies
|
|
|
|
* which make it more difficult to include in other places */
|
|
|
|
#if defined(_M_X64) || defined(__x86_64__)
|
|
|
|
#define V8_HOST_ARCH_X64 1
|
|
|
|
#elif defined(_M_IX86) || defined(__i386__) || defined(__i386)
|
|
|
|
#define V8_HOST_ARCH_IA32 1
|
|
|
|
#elif defined(__ARMEL__)
|
|
|
|
#define V8_HOST_ARCH_ARM 1
|
|
|
|
#else
|
|
|
|
#warning Please add support for your architecture in chromium_types.h
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// STORE_SEQUENCER: Because signals can interrupt our profile modification
|
|
|
|
// we need to make stores are not re-ordered by the compiler
|
|
|
|
// or hardware to make sure the profile is consistent at
|
|
|
|
// every point the signal can fire.
|
|
|
|
#ifdef V8_HOST_ARCH_ARM
|
|
|
|
// TODO Is there something cheaper that will prevent
|
|
|
|
// memory stores from being reordered
|
|
|
|
|
|
|
|
typedef void (*LinuxKernelMemoryBarrierFunc)(void);
|
|
|
|
LinuxKernelMemoryBarrierFunc pLinuxKernelMemoryBarrier __attribute__((weak)) =
|
|
|
|
(LinuxKernelMemoryBarrierFunc) 0xffff0fa0;
|
|
|
|
|
|
|
|
# define STORE_SEQUENCER() pLinuxKernelMemoryBarrier()
|
|
|
|
#elif defined(V8_HOST_ARCH_IA32) || defined(V8_HOST_ARCH_X64)
|
|
|
|
# if defined(_MSC_VER)
|
|
|
|
#if _MSC_VER > 1400
|
|
|
|
# include <intrin.h>
|
|
|
|
#else // _MSC_VER > 1400
|
|
|
|
// MSVC2005 has a name collision bug caused when both <intrin.h> and <winnt.h> are included together.
|
|
|
|
#ifdef _WINNT_
|
|
|
|
# define _interlockedbittestandreset _interlockedbittestandreset_NAME_CHANGED_TO_AVOID_MSVS2005_ERROR
|
|
|
|
# define _interlockedbittestandset _interlockedbittestandset_NAME_CHANGED_TO_AVOID_MSVS2005_ERROR
|
|
|
|
# include <intrin.h>
|
|
|
|
#else
|
|
|
|
# include <intrin.h>
|
|
|
|
# define _interlockedbittestandreset _interlockedbittestandreset_NAME_CHANGED_TO_AVOID_MSVS2005_ERROR
|
|
|
|
# define _interlockedbittestandset _interlockedbittestandset_NAME_CHANGED_TO_AVOID_MSVS2005_ERROR
|
|
|
|
#endif
|
|
|
|
// Even though MSVC2005 has the intrinsic _ReadWriteBarrier, it fails to link to it when it's
|
|
|
|
// not explicitly declared.
|
|
|
|
# pragma intrinsic(_ReadWriteBarrier)
|
|
|
|
#endif // _MSC_VER > 1400
|
|
|
|
# define STORE_SEQUENCER() _ReadWriteBarrier();
|
|
|
|
# elif defined(__INTEL_COMPILER)
|
|
|
|
# define STORE_SEQUENCER() __memory_barrier();
|
|
|
|
# elif __GNUC__
|
|
|
|
# define STORE_SEQUENCER() asm volatile("" ::: "memory");
|
|
|
|
# else
|
|
|
|
# error "Memory clobber not supported for your compiler."
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# error "Memory clobber not supported for your platform."
|
|
|
|
#endif
|
|
|
|
|
2014-03-28 13:08:22 -07:00
|
|
|
// We can't include <algorithm> because it causes issues on OS X, so we use
|
|
|
|
// our own min function.
|
|
|
|
static inline uint32_t sMin(uint32_t l, uint32_t r) {
|
|
|
|
return l < r ? l : r;
|
|
|
|
}
|
|
|
|
|
2013-03-15 17:48:56 -07:00
|
|
|
// A stack entry exists to allow the JS engine to inform SPS of the current
|
|
|
|
// backtrace, but also to instrument particular points in C++ in case stack
|
|
|
|
// walking is not available on the platform we are running on.
|
|
|
|
//
|
|
|
|
// Each entry has a descriptive string, a relevant stack address, and some extra
|
|
|
|
// information the JS engine might want to inform SPS of. This class inherits
|
|
|
|
// from the JS engine's version of the entry to ensure that the size and layout
|
|
|
|
// of the two representations are consistent.
|
|
|
|
class StackEntry : public js::ProfileEntry
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2013-07-10 21:27:04 -07:00
|
|
|
class ProfilerMarkerPayload;
|
2013-09-25 08:28:34 -07:00
|
|
|
template<typename T>
|
|
|
|
class ProfilerLinkedList;
|
2014-04-21 13:48:47 -07:00
|
|
|
class JSStreamWriter;
|
2013-07-10 21:27:04 -07:00
|
|
|
class JSCustomArray;
|
|
|
|
class ThreadProfile;
|
|
|
|
class ProfilerMarker {
|
2013-09-25 08:28:34 -07:00
|
|
|
friend class ProfilerLinkedList<ProfilerMarker>;
|
2013-07-10 21:27:04 -07:00
|
|
|
public:
|
2014-07-28 10:11:26 -07:00
|
|
|
explicit ProfilerMarker(const char* aMarkerName,
|
2014-02-25 07:40:45 -08:00
|
|
|
ProfilerMarkerPayload* aPayload = nullptr,
|
|
|
|
float aTime = 0);
|
2013-07-10 21:27:04 -07:00
|
|
|
|
|
|
|
~ProfilerMarker();
|
|
|
|
|
|
|
|
const char* GetMarkerName() const {
|
|
|
|
return mMarkerName;
|
|
|
|
}
|
|
|
|
|
2014-04-21 13:48:47 -07:00
|
|
|
void
|
|
|
|
StreamJSObject(JSStreamWriter& b) const;
|
2013-07-10 21:27:04 -07:00
|
|
|
|
|
|
|
void SetGeneration(int aGenID);
|
|
|
|
|
|
|
|
bool HasExpired(int aGenID) const {
|
|
|
|
return mGenID + 2 <= aGenID;
|
|
|
|
}
|
|
|
|
|
2014-02-25 07:40:45 -08:00
|
|
|
float GetTime();
|
|
|
|
|
2013-07-10 21:27:04 -07:00
|
|
|
private:
|
|
|
|
char* mMarkerName;
|
|
|
|
ProfilerMarkerPayload* mPayload;
|
|
|
|
ProfilerMarker* mNext;
|
2014-02-25 07:40:45 -08:00
|
|
|
float mTime;
|
2013-07-10 21:27:04 -07:00
|
|
|
int mGenID;
|
|
|
|
};
|
|
|
|
|
2013-09-25 08:28:34 -07:00
|
|
|
// Foward declaration
|
|
|
|
typedef struct _UnwinderThreadBuffer UnwinderThreadBuffer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This struct is used to add a mNext field to UnwinderThreadBuffer objects for
|
|
|
|
* use with ProfilerLinkedList. It is done this way so that UnwinderThreadBuffer
|
|
|
|
* may continue to be opaque with respect to code outside of UnwinderThread2.cpp
|
|
|
|
*/
|
|
|
|
struct LinkedUWTBuffer
|
|
|
|
{
|
|
|
|
LinkedUWTBuffer()
|
|
|
|
:mNext(nullptr)
|
|
|
|
{}
|
|
|
|
virtual ~LinkedUWTBuffer() {}
|
|
|
|
virtual UnwinderThreadBuffer* GetBuffer() = 0;
|
|
|
|
LinkedUWTBuffer* mNext;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class ProfilerLinkedList {
|
2013-07-10 21:27:04 -07:00
|
|
|
public:
|
2013-09-25 08:28:34 -07:00
|
|
|
ProfilerLinkedList()
|
2013-07-10 21:27:04 -07:00
|
|
|
: mHead(nullptr)
|
|
|
|
, mTail(nullptr)
|
|
|
|
{}
|
|
|
|
|
2013-09-25 08:28:34 -07:00
|
|
|
void insert(T* elem)
|
|
|
|
{
|
|
|
|
if (!mTail) {
|
|
|
|
mHead = elem;
|
|
|
|
mTail = elem;
|
|
|
|
} else {
|
|
|
|
mTail->mNext = elem;
|
|
|
|
mTail = elem;
|
|
|
|
}
|
|
|
|
elem->mNext = nullptr;
|
|
|
|
}
|
2013-07-10 21:27:04 -07:00
|
|
|
|
2013-09-25 08:28:34 -07:00
|
|
|
T* popHead()
|
|
|
|
{
|
|
|
|
if (!mHead) {
|
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* head = mHead;
|
|
|
|
|
|
|
|
mHead = head->mNext;
|
|
|
|
if (!mHead) {
|
|
|
|
mTail = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
|
|
|
const T* peek() {
|
2013-07-10 21:27:04 -07:00
|
|
|
return mHead;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-09-25 08:28:34 -07:00
|
|
|
T* mHead;
|
|
|
|
T* mTail;
|
2013-07-10 21:27:04 -07:00
|
|
|
};
|
|
|
|
|
2013-09-25 08:28:34 -07:00
|
|
|
typedef ProfilerLinkedList<ProfilerMarker> ProfilerMarkerLinkedList;
|
|
|
|
typedef ProfilerLinkedList<LinkedUWTBuffer> UWTBufferLinkedList;
|
|
|
|
|
2013-07-10 21:27:04 -07:00
|
|
|
class PendingMarkers {
|
|
|
|
public:
|
|
|
|
PendingMarkers()
|
|
|
|
: mSignalLock(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
~PendingMarkers();
|
|
|
|
|
|
|
|
void addMarker(ProfilerMarker *aMarker);
|
|
|
|
|
|
|
|
void updateGeneration(int aGenID);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Track a marker which has been inserted into the ThreadProfile.
|
|
|
|
* This marker can safely be deleted once the generation has
|
|
|
|
* expired.
|
|
|
|
*/
|
|
|
|
void addStoredMarker(ProfilerMarker *aStoredMarker);
|
|
|
|
|
|
|
|
// called within signal. Function must be reentrant
|
|
|
|
ProfilerMarkerLinkedList* getPendingMarkers()
|
|
|
|
{
|
|
|
|
// if mSignalLock then the stack is inconsistent because it's being
|
|
|
|
// modified by the profiled thread. Post pone these markers
|
|
|
|
// for the next sample. The odds of a livelock are nearly impossible
|
|
|
|
// and would show up in a profile as many sample in 'addMarker' thus
|
|
|
|
// we ignore this scenario.
|
|
|
|
if (mSignalLock) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return &mPendingMarkers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clearMarkers()
|
|
|
|
{
|
|
|
|
while (mPendingMarkers.peek()) {
|
|
|
|
delete mPendingMarkers.popHead();
|
|
|
|
}
|
|
|
|
while (mStoredMarkers.peek()) {
|
|
|
|
delete mStoredMarkers.popHead();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Keep a list of active markers to be applied to the next sample taken
|
|
|
|
ProfilerMarkerLinkedList mPendingMarkers;
|
|
|
|
ProfilerMarkerLinkedList mStoredMarkers;
|
|
|
|
// If this is set then it's not safe to read mStackPointer from the signal handler
|
|
|
|
volatile bool mSignalLock;
|
|
|
|
// We don't want to modify _markers from within the signal so we allow
|
|
|
|
// it to queue a clear operation.
|
|
|
|
volatile mozilla::sig_safe_t mGenID;
|
|
|
|
};
|
|
|
|
|
2013-09-25 08:28:34 -07:00
|
|
|
class PendingUWTBuffers
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PendingUWTBuffers()
|
|
|
|
: mSignalLock(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void addLinkedUWTBuffer(LinkedUWTBuffer* aBuff)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aBuff);
|
|
|
|
mSignalLock = true;
|
|
|
|
STORE_SEQUENCER();
|
|
|
|
mPendingUWTBuffers.insert(aBuff);
|
|
|
|
STORE_SEQUENCER();
|
|
|
|
mSignalLock = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// called within signal. Function must be reentrant
|
|
|
|
UWTBufferLinkedList* getLinkedUWTBuffers()
|
|
|
|
{
|
|
|
|
if (mSignalLock) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return &mPendingUWTBuffers;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
UWTBufferLinkedList mPendingUWTBuffers;
|
|
|
|
volatile bool mSignalLock;
|
|
|
|
};
|
|
|
|
|
2014-03-03 11:36:08 -08:00
|
|
|
// Stub eventMarker function for js-engine event generation.
|
|
|
|
void ProfilerJSEventMarker(const char *event);
|
|
|
|
|
2013-03-15 17:48:56 -07:00
|
|
|
// the PseudoStack members are read by signal
|
|
|
|
// handlers, so the mutation of them needs to be signal-safe.
|
|
|
|
struct PseudoStack
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PseudoStack()
|
|
|
|
: mStackPointer(0)
|
2014-03-28 13:08:22 -07:00
|
|
|
, mSleepId(0)
|
|
|
|
, mSleepIdObserved(0)
|
|
|
|
, mSleeping(false)
|
2013-03-15 17:48:56 -07:00
|
|
|
, mRuntime(nullptr)
|
|
|
|
, mStartJSSampling(false)
|
2013-06-14 09:42:10 -07:00
|
|
|
, mPrivacyMode(false)
|
2013-03-15 17:48:56 -07:00
|
|
|
{ }
|
|
|
|
|
2013-05-16 08:38:23 -07:00
|
|
|
~PseudoStack() {
|
2013-07-10 21:27:04 -07:00
|
|
|
if (mStackPointer != 0) {
|
2013-05-16 08:38:23 -07:00
|
|
|
// We're releasing the pseudostack while it's still in use.
|
|
|
|
// The label macros keep a non ref counted reference to the
|
|
|
|
// stack to avoid a TLS. If these are not all cleared we will
|
|
|
|
// get a use-after-free so better to crash now.
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-28 13:08:22 -07:00
|
|
|
// This is called on every profiler restart. Put things that should happen at that time here.
|
|
|
|
void reinitializeOnResume() {
|
|
|
|
// This is needed to cause an initial sample to be taken from sleeping threads. Otherwise sleeping
|
|
|
|
// threads would not have any samples to copy forward while sleeping.
|
|
|
|
mSleepId++;
|
|
|
|
}
|
|
|
|
|
2013-09-25 08:28:34 -07:00
|
|
|
void addLinkedUWTBuffer(LinkedUWTBuffer* aBuff)
|
|
|
|
{
|
|
|
|
mPendingUWTBuffers.addLinkedUWTBuffer(aBuff);
|
|
|
|
}
|
|
|
|
|
|
|
|
UWTBufferLinkedList* getLinkedUWTBuffers()
|
|
|
|
{
|
|
|
|
return mPendingUWTBuffers.getLinkedUWTBuffers();
|
|
|
|
}
|
|
|
|
|
2014-02-25 07:40:45 -08:00
|
|
|
void addMarker(const char *aMarkerStr, ProfilerMarkerPayload *aPayload, float aTime)
|
2013-03-15 17:48:56 -07:00
|
|
|
{
|
2014-02-25 07:40:45 -08:00
|
|
|
ProfilerMarker* marker = new ProfilerMarker(aMarkerStr, aPayload, aTime);
|
2013-07-10 21:27:04 -07:00
|
|
|
mPendingMarkers.addMarker(marker);
|
|
|
|
}
|
2013-03-15 17:48:56 -07:00
|
|
|
|
2013-07-10 21:27:04 -07:00
|
|
|
void addStoredMarker(ProfilerMarker *aStoredMarker) {
|
|
|
|
mPendingMarkers.addStoredMarker(aStoredMarker);
|
2013-03-15 17:48:56 -07:00
|
|
|
}
|
|
|
|
|
2013-07-10 21:27:04 -07:00
|
|
|
void updateGeneration(int aGenID) {
|
|
|
|
mPendingMarkers.updateGeneration(aGenID);
|
2013-03-15 17:48:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// called within signal. Function must be reentrant
|
2013-07-10 21:27:04 -07:00
|
|
|
ProfilerMarkerLinkedList* getPendingMarkers()
|
2013-03-15 17:48:56 -07:00
|
|
|
{
|
2013-07-10 21:27:04 -07:00
|
|
|
return mPendingMarkers.getPendingMarkers();
|
2013-03-15 17:48:56 -07:00
|
|
|
}
|
|
|
|
|
2014-05-30 18:41:11 -07:00
|
|
|
void push(const char *aName, js::ProfileEntry::Category aCategory, uint32_t line)
|
2014-05-26 18:51:50 -07:00
|
|
|
{
|
2014-05-30 18:41:11 -07:00
|
|
|
push(aName, aCategory, nullptr, false, line);
|
2014-05-26 18:51:50 -07:00
|
|
|
}
|
|
|
|
|
2014-05-30 18:41:11 -07:00
|
|
|
void push(const char *aName, js::ProfileEntry::Category aCategory,
|
|
|
|
void *aStackAddress, bool aCopy, uint32_t line)
|
2013-03-15 17:48:56 -07:00
|
|
|
{
|
|
|
|
if (size_t(mStackPointer) >= mozilla::ArrayLength(mStack)) {
|
|
|
|
mStackPointer++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-28 15:44:41 -07:00
|
|
|
volatile StackEntry &entry = mStack[mStackPointer];
|
|
|
|
|
2013-03-15 17:48:56 -07:00
|
|
|
// Make sure we increment the pointer after the name has
|
|
|
|
// been written such that mStack is always consistent.
|
2014-05-28 15:44:41 -07:00
|
|
|
entry.setLabel(aName);
|
|
|
|
entry.setCppFrame(aStackAddress, line);
|
2014-06-04 11:37:49 -07:00
|
|
|
MOZ_ASSERT(entry.flags() == js::ProfileEntry::IS_CPP_ENTRY);
|
2014-05-28 15:44:41 -07:00
|
|
|
|
2014-05-30 18:41:11 -07:00
|
|
|
uint32_t uint_category = static_cast<uint32_t>(aCategory);
|
|
|
|
MOZ_ASSERT(
|
|
|
|
uint_category >= static_cast<uint32_t>(js::ProfileEntry::Category::FIRST) &&
|
|
|
|
uint_category <= static_cast<uint32_t>(js::ProfileEntry::Category::LAST));
|
|
|
|
|
|
|
|
entry.setFlag(uint_category);
|
|
|
|
|
2014-05-28 15:44:41 -07:00
|
|
|
// Track if mLabel needs a copy.
|
|
|
|
if (aCopy)
|
|
|
|
entry.setFlag(js::ProfileEntry::FRAME_LABEL_COPY);
|
|
|
|
else
|
|
|
|
entry.unsetFlag(js::ProfileEntry::FRAME_LABEL_COPY);
|
2013-03-15 17:48:56 -07:00
|
|
|
|
|
|
|
// Prevent the optimizer from re-ordering these instructions
|
|
|
|
STORE_SEQUENCER();
|
|
|
|
mStackPointer++;
|
|
|
|
}
|
|
|
|
void pop()
|
|
|
|
{
|
|
|
|
mStackPointer--;
|
|
|
|
}
|
|
|
|
bool isEmpty()
|
|
|
|
{
|
|
|
|
return mStackPointer == 0;
|
|
|
|
}
|
|
|
|
uint32_t stackSize() const
|
|
|
|
{
|
2014-03-28 13:08:22 -07:00
|
|
|
return sMin(mStackPointer, mozilla::sig_safe_t(mozilla::ArrayLength(mStack)));
|
2013-03-15 17:48:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void sampleRuntime(JSRuntime *runtime) {
|
|
|
|
mRuntime = runtime;
|
|
|
|
if (!runtime) {
|
|
|
|
// JS shut down
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-17 22:10:50 -08:00
|
|
|
static_assert(sizeof(mStack[0]) == sizeof(js::ProfileEntry),
|
|
|
|
"mStack must be binary compatible with js::ProfileEntry.");
|
2013-03-15 17:48:56 -07:00
|
|
|
js::SetRuntimeProfilingStack(runtime,
|
|
|
|
(js::ProfileEntry*) mStack,
|
|
|
|
(uint32_t*) &mStackPointer,
|
2013-03-26 10:32:09 -07:00
|
|
|
uint32_t(mozilla::ArrayLength(mStack)));
|
2013-03-15 17:48:56 -07:00
|
|
|
if (mStartJSSampling)
|
|
|
|
enableJSSampling();
|
|
|
|
}
|
|
|
|
void enableJSSampling() {
|
|
|
|
if (mRuntime) {
|
|
|
|
js::EnableRuntimeProfilingStack(mRuntime, true);
|
2014-03-03 11:36:08 -08:00
|
|
|
js::RegisterRuntimeProfilingEventMarker(mRuntime, &ProfilerJSEventMarker);
|
2013-03-15 17:48:56 -07:00
|
|
|
mStartJSSampling = false;
|
|
|
|
} else {
|
|
|
|
mStartJSSampling = true;
|
|
|
|
}
|
|
|
|
}
|
2013-04-03 15:59:17 -07:00
|
|
|
void jsOperationCallback() {
|
|
|
|
if (mStartJSSampling)
|
|
|
|
enableJSSampling();
|
|
|
|
}
|
2013-03-15 17:48:56 -07:00
|
|
|
void disableJSSampling() {
|
|
|
|
mStartJSSampling = false;
|
|
|
|
if (mRuntime)
|
|
|
|
js::EnableRuntimeProfilingStack(mRuntime, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep a list of active checkpoints
|
|
|
|
StackEntry volatile mStack[1024];
|
|
|
|
private:
|
2013-07-10 21:27:04 -07:00
|
|
|
// Keep a list of pending markers that must be moved
|
|
|
|
// to the circular buffer
|
|
|
|
PendingMarkers mPendingMarkers;
|
2013-09-25 08:28:34 -07:00
|
|
|
// List of LinkedUWTBuffers that must be processed on the next tick
|
|
|
|
PendingUWTBuffers mPendingUWTBuffers;
|
2013-03-15 17:48:56 -07:00
|
|
|
// This may exceed the length of mStack, so instead use the stackSize() method
|
|
|
|
// to determine the number of valid samples in mStack
|
|
|
|
mozilla::sig_safe_t mStackPointer;
|
2014-03-28 13:08:22 -07:00
|
|
|
// Incremented at every sleep/wake up of the thread
|
|
|
|
int mSleepId;
|
|
|
|
// Previous id observed. If this is not the same as mSleepId, this thread is not sleeping in the same place any more
|
|
|
|
mozilla::Atomic<int> mSleepIdObserved;
|
|
|
|
// Keeps tack of whether the thread is sleeping or not (1 when sleeping 0 when awake)
|
|
|
|
mozilla::Atomic<int> mSleeping;
|
2013-03-15 17:48:56 -07:00
|
|
|
public:
|
|
|
|
// The runtime which is being sampled
|
|
|
|
JSRuntime *mRuntime;
|
|
|
|
// Start JS Profiling when possible
|
|
|
|
bool mStartJSSampling;
|
2013-06-14 09:42:10 -07:00
|
|
|
bool mPrivacyMode;
|
2014-03-28 13:08:22 -07:00
|
|
|
|
|
|
|
enum SleepState {NOT_SLEEPING, SLEEPING_FIRST, SLEEPING_AGAIN};
|
|
|
|
|
|
|
|
// The first time this is called per sleep cycle we return SLEEPING_FIRST
|
|
|
|
// and any other subsequent call within the same sleep cycle we return SLEEPING_AGAIN
|
|
|
|
SleepState observeSleeping() {
|
|
|
|
if (mSleeping != 0) {
|
|
|
|
if (mSleepIdObserved == mSleepId) {
|
|
|
|
return SLEEPING_AGAIN;
|
|
|
|
} else {
|
|
|
|
mSleepIdObserved = mSleepId;
|
|
|
|
return SLEEPING_FIRST;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return NOT_SLEEPING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Call this whenever the current thread sleeps or wakes up
|
|
|
|
// Calling setSleeping with the same value twice in a row is an error
|
|
|
|
void setSleeping(int sleeping) {
|
|
|
|
MOZ_ASSERT(mSleeping != sleeping);
|
|
|
|
mSleepId++;
|
|
|
|
mSleeping = sleeping;
|
|
|
|
}
|
2013-03-15 17:48:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|