2013-08-19 23:45:26 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
|
|
|
* 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 js_ProfilingStack_h
|
|
|
|
#define js_ProfilingStack_h
|
|
|
|
|
2013-09-19 12:24:53 -07:00
|
|
|
#include "mozilla/NullPtr.h"
|
2014-05-30 18:41:11 -07:00
|
|
|
#include "mozilla/TypedEnum.h"
|
2014-05-28 15:44:41 -07:00
|
|
|
|
2013-08-19 23:45:26 -07:00
|
|
|
#include "jsbytecode.h"
|
|
|
|
#include "jstypes.h"
|
|
|
|
|
|
|
|
#include "js/Utility.h"
|
|
|
|
|
|
|
|
struct JSRuntime;
|
|
|
|
|
|
|
|
namespace js {
|
|
|
|
|
|
|
|
// A call stack can be specified to the JS engine such that all JS entry/exits
|
|
|
|
// to functions push/pop an entry to/from the specified stack.
|
|
|
|
//
|
|
|
|
// For more detailed information, see vm/SPSProfiler.h.
|
|
|
|
//
|
|
|
|
class ProfileEntry
|
|
|
|
{
|
|
|
|
// All fields are marked volatile to prevent the compiler from re-ordering
|
|
|
|
// instructions. Namely this sequence:
|
|
|
|
//
|
|
|
|
// entry[size] = ...;
|
|
|
|
// size++;
|
|
|
|
//
|
|
|
|
// If the size modification were somehow reordered before the stores, then
|
|
|
|
// if a sample were taken it would be examining bogus information.
|
|
|
|
//
|
2014-05-28 15:44:41 -07:00
|
|
|
// A ProfileEntry represents both a C++ profile entry and a JS one.
|
|
|
|
|
|
|
|
// Descriptive string of this entry.
|
|
|
|
const char * volatile string;
|
|
|
|
|
|
|
|
// Stack pointer for non-JS entries, the script pointer otherwise.
|
|
|
|
void * volatile spOrScript;
|
|
|
|
|
|
|
|
// Line number for non-JS entries, the bytecode offset otherwise.
|
|
|
|
int32_t volatile lineOrPc;
|
|
|
|
|
|
|
|
// General purpose storage describing this frame.
|
2014-06-04 11:37:49 -07:00
|
|
|
uint32_t volatile flags_;
|
2013-08-19 23:45:26 -07:00
|
|
|
|
|
|
|
public:
|
2014-05-28 15:44:41 -07:00
|
|
|
// These traits are bit masks. Make sure they're powers of 2.
|
|
|
|
enum Flags {
|
|
|
|
// Indicate whether a profile entry represents a CPP frame. If not set,
|
|
|
|
// a JS frame is assumed by default. You're not allowed to publicly
|
|
|
|
// change the frame type. Instead, call `setJsFrame` or `setCppFrame`.
|
|
|
|
IS_CPP_ENTRY = 0x01,
|
|
|
|
|
|
|
|
// Indicate that copying the frame label is not necessary when taking a
|
|
|
|
// sample of the pseudostack.
|
2014-06-04 11:37:49 -07:00
|
|
|
FRAME_LABEL_COPY = 0x02,
|
|
|
|
|
2014-07-29 07:56:22 -07:00
|
|
|
// This ProfileEntry was pushed immediately before calling into asm.js.
|
|
|
|
ASMJS = 0x04,
|
|
|
|
|
2014-06-04 11:37:49 -07:00
|
|
|
// Mask for removing all flags except the category information.
|
2014-07-29 07:56:22 -07:00
|
|
|
CATEGORY_MASK = ~IS_CPP_ENTRY & ~FRAME_LABEL_COPY & ~ASMJS
|
2014-05-28 15:44:41 -07:00
|
|
|
};
|
2014-04-11 08:58:55 -07:00
|
|
|
|
2014-05-30 18:41:11 -07:00
|
|
|
MOZ_BEGIN_NESTED_ENUM_CLASS(Category, uint32_t)
|
2014-07-29 07:56:22 -07:00
|
|
|
OTHER = 0x08,
|
|
|
|
CSS = 0x10,
|
|
|
|
JS = 0x20,
|
|
|
|
GC = 0x40,
|
|
|
|
CC = 0x80,
|
|
|
|
NETWORK = 0x100,
|
|
|
|
GRAPHICS = 0x200,
|
|
|
|
STORAGE = 0x400,
|
|
|
|
EVENTS = 0x800,
|
2014-05-30 18:41:11 -07:00
|
|
|
|
|
|
|
FIRST = OTHER,
|
|
|
|
LAST = EVENTS
|
|
|
|
MOZ_END_NESTED_ENUM_CLASS(Category)
|
2014-05-23 14:12:29 -07:00
|
|
|
|
2013-08-19 23:45:26 -07:00
|
|
|
// All of these methods are marked with the 'volatile' keyword because SPS's
|
|
|
|
// representation of the stack is stored such that all ProfileEntry
|
|
|
|
// instances are volatile. These methods would not be available unless they
|
|
|
|
// were marked as volatile as well.
|
|
|
|
|
2014-05-28 15:44:41 -07:00
|
|
|
bool isCpp() const volatile { return hasFlag(IS_CPP_ENTRY); }
|
|
|
|
bool isJs() const volatile { return !isCpp(); }
|
|
|
|
|
|
|
|
bool isCopyLabel() const volatile { return hasFlag(FRAME_LABEL_COPY); };
|
|
|
|
|
|
|
|
void setLabel(const char *aString) volatile { string = aString; }
|
|
|
|
const char *label() const volatile { return string; }
|
|
|
|
|
|
|
|
void setJsFrame(JSScript *aScript, jsbytecode *aPc) volatile {
|
2014-06-04 11:37:49 -07:00
|
|
|
flags_ = 0;
|
2014-05-28 15:44:41 -07:00
|
|
|
spOrScript = aScript;
|
|
|
|
setPC(aPc);
|
|
|
|
}
|
|
|
|
void setCppFrame(void *aSp, uint32_t aLine) volatile {
|
2014-06-04 11:37:49 -07:00
|
|
|
flags_ = IS_CPP_ENTRY;
|
2014-05-28 15:44:41 -07:00
|
|
|
spOrScript = aSp;
|
2014-05-29 20:54:49 -07:00
|
|
|
lineOrPc = static_cast<int32_t>(aLine);
|
2013-08-19 23:45:26 -07:00
|
|
|
}
|
|
|
|
|
2014-05-30 18:41:11 -07:00
|
|
|
void setFlag(uint32_t flag) volatile {
|
2014-05-28 15:44:41 -07:00
|
|
|
MOZ_ASSERT(flag != IS_CPP_ENTRY);
|
2014-06-04 11:37:49 -07:00
|
|
|
flags_ |= flag;
|
2014-05-20 12:25:25 -07:00
|
|
|
}
|
2014-05-30 18:41:11 -07:00
|
|
|
void unsetFlag(uint32_t flag) volatile {
|
2014-05-28 15:44:41 -07:00
|
|
|
MOZ_ASSERT(flag != IS_CPP_ENTRY);
|
2014-06-04 11:37:49 -07:00
|
|
|
flags_ &= ~flag;
|
2014-05-28 15:44:41 -07:00
|
|
|
}
|
2014-05-30 18:41:11 -07:00
|
|
|
bool hasFlag(uint32_t flag) const volatile {
|
2014-06-04 11:37:49 -07:00
|
|
|
return bool(flags_ & flag);
|
|
|
|
}
|
2014-06-04 11:37:49 -07:00
|
|
|
|
2014-06-04 11:37:49 -07:00
|
|
|
uint32_t flags() const volatile {
|
|
|
|
return flags_;
|
2014-05-20 12:25:25 -07:00
|
|
|
}
|
2014-06-04 11:37:49 -07:00
|
|
|
uint32_t category() const volatile {
|
|
|
|
return flags_ & CATEGORY_MASK;
|
|
|
|
}
|
2014-05-26 18:51:50 -07:00
|
|
|
|
2014-05-28 15:44:41 -07:00
|
|
|
void *stackAddress() const volatile {
|
|
|
|
MOZ_ASSERT(!isJs());
|
|
|
|
return spOrScript;
|
|
|
|
}
|
|
|
|
JSScript *script() const volatile {
|
|
|
|
MOZ_ASSERT(isJs());
|
|
|
|
return (JSScript *)spOrScript;
|
|
|
|
}
|
|
|
|
uint32_t line() const volatile {
|
|
|
|
MOZ_ASSERT(!isJs());
|
2014-05-29 20:54:49 -07:00
|
|
|
return static_cast<uint32_t>(lineOrPc);
|
2014-05-28 15:44:41 -07:00
|
|
|
}
|
2013-08-19 23:45:26 -07:00
|
|
|
|
|
|
|
// We can't know the layout of JSScript, so look in vm/SPSProfiler.cpp.
|
2013-11-22 11:17:30 -08:00
|
|
|
JS_FRIEND_API(jsbytecode *) pc() const volatile;
|
2013-08-19 23:45:26 -07:00
|
|
|
JS_FRIEND_API(void) setPC(jsbytecode *pc) volatile;
|
|
|
|
|
2014-05-28 15:44:41 -07:00
|
|
|
// The offset of a pc into a script's code can actually be 0, so to
|
|
|
|
// signify a nullptr pc, use a -1 index. This is checked against in
|
|
|
|
// pc() and setPC() to set/get the right pc.
|
|
|
|
static const int32_t NullPCOffset = -1;
|
2014-02-24 09:27:58 -08:00
|
|
|
|
2014-05-28 15:44:41 -07:00
|
|
|
static size_t offsetOfLabel() { return offsetof(ProfileEntry, string); }
|
|
|
|
static size_t offsetOfSpOrScript() { return offsetof(ProfileEntry, spOrScript); }
|
|
|
|
static size_t offsetOfLineOrPc() { return offsetof(ProfileEntry, lineOrPc); }
|
2014-06-04 11:37:49 -07:00
|
|
|
static size_t offsetOfFlags() { return offsetof(ProfileEntry, flags_); }
|
2013-08-19 23:45:26 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
SetRuntimeProfilingStack(JSRuntime *rt, ProfileEntry *stack, uint32_t *size,
|
|
|
|
uint32_t max);
|
|
|
|
|
|
|
|
JS_FRIEND_API(void)
|
|
|
|
EnableRuntimeProfilingStack(JSRuntime *rt, bool enabled);
|
|
|
|
|
2014-03-03 11:36:08 -08:00
|
|
|
JS_FRIEND_API(void)
|
|
|
|
RegisterRuntimeProfilingEventMarker(JSRuntime *rt, void (*fn)(const char *));
|
|
|
|
|
2013-08-19 23:45:26 -07:00
|
|
|
JS_FRIEND_API(jsbytecode*)
|
|
|
|
ProfilingGetPC(JSRuntime *rt, JSScript *script, void *ip);
|
|
|
|
|
|
|
|
} // namespace js
|
|
|
|
|
|
|
|
#endif /* js_ProfilingStack_h */
|