2013-03-11 02:00:23 +04: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/. */
|
|
|
|
|
2013-05-27 16:29:24 +04:00
|
|
|
#include <ostream>
|
2013-03-11 02:00:23 +04:00
|
|
|
#include "platform.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2013-03-21 13:17:23 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2013-03-11 02:00:23 +04:00
|
|
|
|
|
|
|
// JSON
|
|
|
|
#include "JSObjectBuilder.h"
|
2013-03-26 01:57:28 +04:00
|
|
|
#include "JSCustomObjectBuilder.h"
|
2013-03-11 02:00:23 +04:00
|
|
|
|
|
|
|
// Self
|
2013-03-26 01:57:28 +04:00
|
|
|
#include "ProfileEntry.h"
|
2013-03-11 02:00:23 +04:00
|
|
|
|
|
|
|
#if _MSC_VER
|
|
|
|
#define snprintf _snprintf
|
|
|
|
#endif
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2013-03-26 01:57:28 +04:00
|
|
|
// BEGIN ProfileEntry
|
2013-03-11 02:00:23 +04:00
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
ProfileEntry::ProfileEntry()
|
2013-11-11 23:16:31 +04:00
|
|
|
: mTagData(nullptr)
|
2013-03-11 02:00:23 +04:00
|
|
|
, mTagName(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// aTagData must not need release (i.e. be a string from the text segment)
|
2013-03-26 01:57:28 +04:00
|
|
|
ProfileEntry::ProfileEntry(char aTagName, const char *aTagData)
|
2013-03-11 02:00:23 +04:00
|
|
|
: mTagData(aTagData)
|
|
|
|
, mTagName(aTagName)
|
|
|
|
{ }
|
|
|
|
|
2013-07-11 08:27:04 +04:00
|
|
|
ProfileEntry::ProfileEntry(char aTagName, ProfilerMarker *aTagMarker)
|
|
|
|
: mTagMarker(aTagMarker)
|
|
|
|
, mTagName(aTagName)
|
|
|
|
{ }
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
ProfileEntry::ProfileEntry(char aTagName, void *aTagPtr)
|
2013-03-11 02:00:23 +04:00
|
|
|
: mTagPtr(aTagPtr)
|
|
|
|
, mTagName(aTagName)
|
|
|
|
{ }
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
ProfileEntry::ProfileEntry(char aTagName, double aTagFloat)
|
2013-03-11 02:00:23 +04:00
|
|
|
: mTagFloat(aTagFloat)
|
|
|
|
, mTagName(aTagName)
|
|
|
|
{ }
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
ProfileEntry::ProfileEntry(char aTagName, uintptr_t aTagOffset)
|
2013-03-11 02:00:23 +04:00
|
|
|
: mTagOffset(aTagOffset)
|
|
|
|
, mTagName(aTagName)
|
|
|
|
{ }
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
ProfileEntry::ProfileEntry(char aTagName, Address aTagAddress)
|
2013-03-11 02:00:23 +04:00
|
|
|
: mTagAddress(aTagAddress)
|
|
|
|
, mTagName(aTagName)
|
|
|
|
{ }
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
ProfileEntry::ProfileEntry(char aTagName, int aTagLine)
|
2013-03-11 02:00:23 +04:00
|
|
|
: mTagLine(aTagLine)
|
|
|
|
, mTagName(aTagName)
|
|
|
|
{ }
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
ProfileEntry::ProfileEntry(char aTagName, char aTagChar)
|
2013-03-11 02:00:23 +04:00
|
|
|
: mTagChar(aTagChar)
|
|
|
|
, mTagName(aTagName)
|
|
|
|
{ }
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
bool ProfileEntry::is_ent_hint(char hintChar) {
|
2013-03-11 02:00:23 +04:00
|
|
|
return mTagName == 'h' && mTagChar == hintChar;
|
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
bool ProfileEntry::is_ent_hint() {
|
2013-03-11 02:00:23 +04:00
|
|
|
return mTagName == 'h';
|
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
bool ProfileEntry::is_ent(char tagChar) {
|
2013-03-11 02:00:23 +04:00
|
|
|
return mTagName == tagChar;
|
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
void* ProfileEntry::get_tagPtr() {
|
2013-03-11 02:00:23 +04:00
|
|
|
// No consistency checking. Oh well.
|
|
|
|
return mTagPtr;
|
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
void ProfileEntry::log()
|
2013-03-11 02:00:23 +04:00
|
|
|
{
|
|
|
|
// There is no compiler enforced mapping between tag chars
|
|
|
|
// and union variant fields, so the following was derived
|
|
|
|
// by looking through all the use points of TableTicker.cpp.
|
2013-09-25 19:28:34 +04:00
|
|
|
// mTagMarker (ProfilerMarker*) m
|
|
|
|
// mTagData (const char*) c,s
|
|
|
|
// mTagPtr (void*) d,l,L,B (immediate backtrace), S(start-of-stack)
|
2013-03-11 02:00:23 +04:00
|
|
|
// mTagLine (int) n,f
|
|
|
|
// mTagChar (char) h
|
|
|
|
// mTagFloat (double) r,t
|
|
|
|
switch (mTagName) {
|
2013-07-11 08:27:04 +04:00
|
|
|
case 'm':
|
|
|
|
LOGF("%c \"%s\"", mTagName, mTagMarker->GetMarkerName()); break;
|
|
|
|
case 'c': case 's':
|
2013-03-11 02:00:23 +04:00
|
|
|
LOGF("%c \"%s\"", mTagName, mTagData); break;
|
2013-09-25 19:28:34 +04:00
|
|
|
case 'd': case 'l': case 'L': case 'B': case 'S':
|
2013-03-11 02:00:23 +04:00
|
|
|
LOGF("%c %p", mTagName, mTagPtr); break;
|
|
|
|
case 'n': case 'f':
|
|
|
|
LOGF("%c %d", mTagName, mTagLine); break;
|
|
|
|
case 'h':
|
|
|
|
LOGF("%c \'%c\'", mTagName, mTagChar); break;
|
|
|
|
case 'r': case 't':
|
|
|
|
LOGF("%c %f", mTagName, mTagFloat); break;
|
|
|
|
default:
|
|
|
|
LOGF("'%c' unknown_tag", mTagName); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
std::ostream& operator<<(std::ostream& stream, const ProfileEntry& entry)
|
|
|
|
{
|
|
|
|
if (entry.mTagName == 'r' || entry.mTagName == 't') {
|
|
|
|
stream << entry.mTagName << "-" << std::fixed << entry.mTagFloat << "\n";
|
|
|
|
} else if (entry.mTagName == 'l' || entry.mTagName == 'L') {
|
|
|
|
// Bug 739800 - Force l-tag addresses to have a "0x" prefix on all platforms
|
|
|
|
// Additionally, stringstream seemed to be ignoring formatter flags.
|
|
|
|
char tagBuff[1024];
|
|
|
|
unsigned long long pc = (unsigned long long)(uintptr_t)entry.mTagPtr;
|
|
|
|
snprintf(tagBuff, 1024, "%c-%#llx\n", entry.mTagName, pc);
|
|
|
|
stream << tagBuff;
|
|
|
|
} else if (entry.mTagName == 'd') {
|
|
|
|
// TODO implement 'd' tag for text profile
|
|
|
|
} else {
|
|
|
|
stream << entry.mTagName << "-" << entry.mTagData << "\n";
|
|
|
|
}
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
// END ProfileEntry
|
2013-03-11 02:00:23 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2013-03-26 01:57:28 +04:00
|
|
|
// BEGIN ThreadProfile
|
2013-03-11 02:00:23 +04:00
|
|
|
|
|
|
|
#define DYNAMIC_MAX_STRING 512
|
|
|
|
|
2013-04-04 02:59:17 +04:00
|
|
|
ThreadProfile::ThreadProfile(const char* aName, int aEntrySize,
|
2013-09-25 19:28:34 +04:00
|
|
|
PseudoStack *aStack, Thread::tid_t aThreadId,
|
2013-04-04 02:59:17 +04:00
|
|
|
PlatformData* aPlatform,
|
2013-09-11 22:50:46 +04:00
|
|
|
bool aIsMainThread, void *aStackTop)
|
2013-03-11 02:00:23 +04:00
|
|
|
: mWritePos(0)
|
|
|
|
, mLastFlushPos(0)
|
|
|
|
, mReadPos(0)
|
|
|
|
, mEntrySize(aEntrySize)
|
|
|
|
, mPseudoStack(aStack)
|
2013-03-26 01:57:28 +04:00
|
|
|
, mMutex("ThreadProfile::mMutex")
|
2013-03-29 23:34:49 +04:00
|
|
|
, mName(strdup(aName))
|
|
|
|
, mThreadId(aThreadId)
|
|
|
|
, mIsMainThread(aIsMainThread)
|
2013-04-04 02:59:17 +04:00
|
|
|
, mPlatformData(aPlatform)
|
2013-09-27 20:08:45 +04:00
|
|
|
, mGeneration(0)
|
|
|
|
, mPendingGenerationFlush(0)
|
2013-09-11 22:50:46 +04:00
|
|
|
, mStackTop(aStackTop)
|
2013-03-11 02:00:23 +04:00
|
|
|
{
|
2013-03-26 01:57:28 +04:00
|
|
|
mEntries = new ProfileEntry[mEntrySize];
|
2013-03-11 02:00:23 +04:00
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
ThreadProfile::~ThreadProfile()
|
2013-03-11 02:00:23 +04:00
|
|
|
{
|
2013-03-29 23:34:49 +04:00
|
|
|
free(mName);
|
2013-03-11 02:00:23 +04:00
|
|
|
delete[] mEntries;
|
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
void ThreadProfile::addTag(ProfileEntry aTag)
|
2013-03-11 02:00:23 +04:00
|
|
|
{
|
|
|
|
// Called from signal, call only reentrant functions
|
|
|
|
mEntries[mWritePos] = aTag;
|
2013-07-11 08:27:04 +04:00
|
|
|
mWritePos = mWritePos + 1;
|
|
|
|
if (mWritePos >= mEntrySize) {
|
|
|
|
mPendingGenerationFlush++;
|
|
|
|
mWritePos = mWritePos % mEntrySize;
|
|
|
|
}
|
2013-03-11 02:00:23 +04:00
|
|
|
if (mWritePos == mReadPos) {
|
|
|
|
// Keep one slot open
|
2013-03-26 01:57:28 +04:00
|
|
|
mEntries[mReadPos] = ProfileEntry();
|
2013-03-11 02:00:23 +04:00
|
|
|
mReadPos = (mReadPos + 1) % mEntrySize;
|
|
|
|
}
|
|
|
|
// we also need to move the flush pos to ensure we
|
|
|
|
// do not pass it
|
|
|
|
if (mWritePos == mLastFlushPos) {
|
|
|
|
mLastFlushPos = (mLastFlushPos + 1) % mEntrySize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// flush the new entries
|
2013-03-26 01:57:28 +04:00
|
|
|
void ThreadProfile::flush()
|
2013-03-11 02:00:23 +04:00
|
|
|
{
|
|
|
|
mLastFlushPos = mWritePos;
|
2013-07-11 08:27:04 +04:00
|
|
|
mGeneration += mPendingGenerationFlush;
|
|
|
|
mPendingGenerationFlush = 0;
|
2013-03-11 02:00:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// discards all of the entries since the last flush()
|
|
|
|
// NOTE: that if mWritePos happens to wrap around past
|
|
|
|
// mLastFlushPos we actually only discard mWritePos - mLastFlushPos entries
|
|
|
|
//
|
|
|
|
// r = mReadPos
|
|
|
|
// w = mWritePos
|
|
|
|
// f = mLastFlushPos
|
|
|
|
//
|
|
|
|
// r f w
|
|
|
|
// |-----------------------------|
|
|
|
|
// | abcdefghijklmnopq | -> 'abcdefghijklmnopq'
|
|
|
|
// |-----------------------------|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// mWritePos and mReadPos have passed mLastFlushPos
|
|
|
|
// f
|
|
|
|
// w r
|
|
|
|
// |-----------------------------|
|
|
|
|
// |ABCDEFGHIJKLMNOPQRSqrstuvwxyz|
|
|
|
|
// |-----------------------------|
|
|
|
|
// w
|
|
|
|
// r
|
|
|
|
// |-----------------------------|
|
|
|
|
// |ABCDEFGHIJKLMNOPQRSqrstuvwxyz| -> ''
|
|
|
|
// |-----------------------------|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// mWritePos will end up the same as mReadPos
|
|
|
|
// r
|
|
|
|
// w f
|
|
|
|
// |-----------------------------|
|
|
|
|
// |ABCDEFGHIJKLMklmnopqrstuvwxyz|
|
|
|
|
// |-----------------------------|
|
|
|
|
// r
|
|
|
|
// w
|
|
|
|
// |-----------------------------|
|
|
|
|
// |ABCDEFGHIJKLMklmnopqrstuvwxyz| -> ''
|
|
|
|
// |-----------------------------|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// mWritePos has moved past mReadPos
|
|
|
|
// w r f
|
|
|
|
// |-----------------------------|
|
|
|
|
// |ABCDEFdefghijklmnopqrstuvwxyz|
|
|
|
|
// |-----------------------------|
|
|
|
|
// r w
|
|
|
|
// |-----------------------------|
|
|
|
|
// |ABCDEFdefghijklmnopqrstuvwxyz| -> 'defghijkl'
|
|
|
|
// |-----------------------------|
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
void ThreadProfile::erase()
|
2013-03-11 02:00:23 +04:00
|
|
|
{
|
|
|
|
mWritePos = mLastFlushPos;
|
2013-07-11 08:27:04 +04:00
|
|
|
mPendingGenerationFlush = 0;
|
2013-03-11 02:00:23 +04:00
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
char* ThreadProfile::processDynamicTag(int readPos,
|
2013-03-11 02:00:23 +04:00
|
|
|
int* tagsConsumed, char* tagBuff)
|
|
|
|
{
|
|
|
|
int readAheadPos = (readPos + 1) % mEntrySize;
|
|
|
|
int tagBuffPos = 0;
|
|
|
|
|
|
|
|
// Read the string stored in mTagData until the null character is seen
|
|
|
|
bool seenNullByte = false;
|
|
|
|
while (readAheadPos != mLastFlushPos && !seenNullByte) {
|
|
|
|
(*tagsConsumed)++;
|
2013-03-26 01:57:28 +04:00
|
|
|
ProfileEntry readAheadEntry = mEntries[readAheadPos];
|
2013-03-11 02:00:23 +04:00
|
|
|
for (size_t pos = 0; pos < sizeof(void*); pos++) {
|
|
|
|
tagBuff[tagBuffPos] = readAheadEntry.mTagChars[pos];
|
|
|
|
if (tagBuff[tagBuffPos] == '\0' || tagBuffPos == DYNAMIC_MAX_STRING-2) {
|
|
|
|
seenNullByte = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tagBuffPos++;
|
|
|
|
}
|
|
|
|
if (!seenNullByte)
|
|
|
|
readAheadPos = (readAheadPos + 1) % mEntrySize;
|
|
|
|
}
|
|
|
|
return tagBuff;
|
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
void ThreadProfile::IterateTags(IterateTagsCallback aCallback)
|
2013-03-11 02:00:23 +04:00
|
|
|
{
|
2013-03-26 01:57:28 +04:00
|
|
|
MOZ_ASSERT(aCallback);
|
|
|
|
|
|
|
|
int readPos = mReadPos;
|
|
|
|
while (readPos != mLastFlushPos) {
|
|
|
|
// Number of tag consumed
|
|
|
|
int incBy = 1;
|
|
|
|
const ProfileEntry& entry = mEntries[readPos];
|
|
|
|
|
|
|
|
// Read ahead to the next tag, if it's a 'd' tag process it now
|
|
|
|
const char* tagStringData = entry.mTagData;
|
|
|
|
int readAheadPos = (readPos + 1) % mEntrySize;
|
|
|
|
char tagBuff[DYNAMIC_MAX_STRING];
|
|
|
|
// Make sure the string is always null terminated if it fills up DYNAMIC_MAX_STRING-2
|
|
|
|
tagBuff[DYNAMIC_MAX_STRING-1] = '\0';
|
|
|
|
|
|
|
|
if (readAheadPos != mLastFlushPos && mEntries[readAheadPos].mTagName == 'd') {
|
|
|
|
tagStringData = processDynamicTag(readPos, &incBy, tagBuff);
|
|
|
|
}
|
|
|
|
|
|
|
|
aCallback(entry, tagStringData);
|
2013-03-11 02:00:23 +04:00
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
readPos = (readPos + incBy) % mEntrySize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadProfile::ToStreamAsJSON(std::ostream& stream)
|
|
|
|
{
|
|
|
|
JSCustomObjectBuilder b;
|
|
|
|
JSCustomObject *profile = b.CreateObject();
|
|
|
|
BuildJSObject(b, profile);
|
|
|
|
b.Serialize(profile, stream);
|
|
|
|
b.DeleteObject(profile);
|
|
|
|
}
|
|
|
|
|
2013-09-06 03:10:37 +04:00
|
|
|
JSObject* ThreadProfile::ToJSObject(JSContext *aCx)
|
2013-03-26 01:57:28 +04:00
|
|
|
{
|
|
|
|
JSObjectBuilder b(aCx);
|
2013-09-06 03:10:37 +04:00
|
|
|
JS::RootedObject profile(aCx, b.CreateObject());
|
2013-03-26 01:57:28 +04:00
|
|
|
BuildJSObject(b, profile);
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2013-09-06 03:10:37 +04:00
|
|
|
template <typename Builder>
|
2013-09-25 19:28:34 +04:00
|
|
|
void ThreadProfile::BuildJSObject(Builder& b,
|
|
|
|
typename Builder::ObjectHandle profile)
|
|
|
|
{
|
2013-03-29 23:34:49 +04:00
|
|
|
// Thread meta data
|
2013-03-21 13:17:23 +04:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Plugin) {
|
|
|
|
// TODO Add the proper plugin name
|
|
|
|
b.DefineProperty(profile, "name", "Plugin");
|
|
|
|
} else {
|
|
|
|
b.DefineProperty(profile, "name", mName);
|
|
|
|
}
|
|
|
|
|
2013-09-25 19:28:34 +04:00
|
|
|
b.DefineProperty(profile, "tid", static_cast<int>(mThreadId));
|
2013-03-29 23:34:49 +04:00
|
|
|
|
2013-09-06 03:10:37 +04:00
|
|
|
typename Builder::RootedArray samples(b.context(), b.CreateArray());
|
2013-03-11 02:00:23 +04:00
|
|
|
b.DefineProperty(profile, "samples", samples);
|
|
|
|
|
2013-09-06 03:10:37 +04:00
|
|
|
typename Builder::RootedObject sample(b.context());
|
|
|
|
typename Builder::RootedArray frames(b.context());
|
2013-07-11 08:27:04 +04:00
|
|
|
typename Builder::RootedArray markers(b.context());
|
2013-03-11 02:00:23 +04:00
|
|
|
|
|
|
|
int readPos = mReadPos;
|
|
|
|
while (readPos != mLastFlushPos) {
|
|
|
|
// Number of tag consumed
|
|
|
|
int incBy = 1;
|
2013-03-26 01:57:28 +04:00
|
|
|
ProfileEntry entry = mEntries[readPos];
|
2013-03-11 02:00:23 +04:00
|
|
|
|
|
|
|
// Read ahead to the next tag, if it's a 'd' tag process it now
|
|
|
|
const char* tagStringData = entry.mTagData;
|
|
|
|
int readAheadPos = (readPos + 1) % mEntrySize;
|
|
|
|
char tagBuff[DYNAMIC_MAX_STRING];
|
|
|
|
// Make sure the string is always null terminated if it fills up
|
|
|
|
// DYNAMIC_MAX_STRING-2
|
|
|
|
tagBuff[DYNAMIC_MAX_STRING-1] = '\0';
|
|
|
|
|
|
|
|
if (readAheadPos != mLastFlushPos && mEntries[readAheadPos].mTagName == 'd') {
|
|
|
|
tagStringData = processDynamicTag(readPos, &incBy, tagBuff);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (entry.mTagName) {
|
2013-03-26 01:57:28 +04:00
|
|
|
case 'm':
|
|
|
|
{
|
|
|
|
if (sample) {
|
2013-07-11 08:27:04 +04:00
|
|
|
if (!markers) {
|
|
|
|
markers = b.CreateArray();
|
|
|
|
b.DefineProperty(sample, "marker", markers);
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
2013-07-11 08:27:04 +04:00
|
|
|
entry.getMarker()->BuildJSObject(b, markers);
|
2013-03-26 01:57:28 +04:00
|
|
|
}
|
|
|
|
}
|
2013-03-11 02:00:23 +04:00
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
{
|
|
|
|
if (sample) {
|
|
|
|
b.DefineProperty(sample, "responsiveness", entry.mTagFloat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-10-08 18:05:25 +04:00
|
|
|
case 'p':
|
|
|
|
{
|
|
|
|
if (sample) {
|
|
|
|
b.DefineProperty(sample, "power", entry.mTagFloat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-03-11 02:00:23 +04:00
|
|
|
case 'f':
|
|
|
|
{
|
|
|
|
if (sample) {
|
|
|
|
b.DefineProperty(sample, "frameNumber", entry.mTagLine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
{
|
|
|
|
if (sample) {
|
|
|
|
b.DefineProperty(sample, "time", entry.mTagFloat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-01-30 22:13:23 +04:00
|
|
|
case 's':
|
|
|
|
sample = b.CreateObject();
|
|
|
|
b.DefineProperty(sample, "name", tagStringData);
|
|
|
|
frames = b.CreateArray();
|
|
|
|
b.DefineProperty(sample, "frames", frames);
|
|
|
|
b.ArrayPush(samples, sample);
|
|
|
|
// Created lazily
|
|
|
|
markers = nullptr;
|
|
|
|
// Fall though to create a label for the 's' tag
|
2013-03-11 02:00:23 +04:00
|
|
|
case 'c':
|
|
|
|
case 'l':
|
|
|
|
{
|
|
|
|
if (sample) {
|
2013-09-06 03:10:37 +04:00
|
|
|
typename Builder::RootedObject frame(b.context(), b.CreateObject());
|
2013-03-11 02:00:23 +04:00
|
|
|
if (entry.mTagName == 'l') {
|
|
|
|
// Bug 753041
|
|
|
|
// We need a double cast here to tell GCC that we don't want to sign
|
|
|
|
// extend 32-bit addresses starting with 0xFXXXXXX.
|
|
|
|
unsigned long long pc = (unsigned long long)(uintptr_t)entry.mTagPtr;
|
|
|
|
snprintf(tagBuff, DYNAMIC_MAX_STRING, "%#llx", pc);
|
|
|
|
b.DefineProperty(frame, "location", tagBuff);
|
|
|
|
} else {
|
|
|
|
b.DefineProperty(frame, "location", tagStringData);
|
|
|
|
readAheadPos = (readPos + incBy) % mEntrySize;
|
|
|
|
if (readAheadPos != mLastFlushPos &&
|
|
|
|
mEntries[readAheadPos].mTagName == 'n') {
|
|
|
|
b.DefineProperty(frame, "line",
|
|
|
|
mEntries[readAheadPos].mTagLine);
|
|
|
|
incBy++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
b.ArrayPush(frames, frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
readPos = (readPos + incBy) % mEntrySize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-06 03:10:37 +04:00
|
|
|
template void ThreadProfile::BuildJSObject<JSObjectBuilder>(JSObjectBuilder& b,
|
|
|
|
JS::HandleObject profile);
|
|
|
|
template void ThreadProfile::BuildJSObject<JSCustomObjectBuilder>(JSCustomObjectBuilder& b,
|
|
|
|
JSCustomObject *profile);
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
PseudoStack* ThreadProfile::GetPseudoStack()
|
2013-03-11 02:00:23 +04:00
|
|
|
{
|
|
|
|
return mPseudoStack;
|
|
|
|
}
|
|
|
|
|
2013-09-25 19:28:34 +04:00
|
|
|
void ThreadProfile::BeginUnwind()
|
|
|
|
{
|
|
|
|
mMutex.Lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadProfile::EndUnwind()
|
|
|
|
{
|
|
|
|
mMutex.Unlock();
|
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
mozilla::Mutex* ThreadProfile::GetMutex()
|
2013-03-11 02:00:23 +04:00
|
|
|
{
|
|
|
|
return &mMutex;
|
|
|
|
}
|
|
|
|
|
2013-03-26 01:57:28 +04:00
|
|
|
std::ostream& operator<<(std::ostream& stream, const ThreadProfile& profile)
|
|
|
|
{
|
|
|
|
int readPos = profile.mReadPos;
|
|
|
|
while (readPos != profile.mLastFlushPos) {
|
|
|
|
stream << profile.mEntries[readPos];
|
|
|
|
readPos = (readPos + 1) % profile.mEntrySize;
|
|
|
|
}
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
// END ThreadProfile
|
2013-03-11 02:00:23 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|