Bug 778979 - Part 5: Expose the line number in the JSON output of SPS. r=ehsan

This commit is contained in:
Alex Crichton 2012-08-06 15:58:47 -07:00
parent fcbfdf2479
commit 7995a3b3e5

View File

@ -30,6 +30,9 @@
#include "nsDirectoryServiceUtils.h"
#include "nsDirectoryServiceDefs.h"
// JS
#include "jsdbgapi.h"
// we eventually want to make this runtime switchable
#if defined(MOZ_PROFILING) && (defined(XP_UNIX) && !defined(XP_MACOSX))
#ifndef ANDROID
@ -129,6 +132,11 @@ public:
, mTagName(aTagName)
{ }
ProfileEntry(char aTagName, int aTagLine)
: mTagLine(aTagLine)
, mTagName(aTagName)
{ }
friend std::ostream& operator<<(std::ostream& stream, const ProfileEntry& entry);
private:
@ -140,6 +148,7 @@ private:
double mTagFloat;
Address mTagAddress;
uintptr_t mTagOffset;
int mTagLine;
};
char mTagName;
};
@ -331,6 +340,13 @@ public:
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);
}
@ -624,8 +640,11 @@ JSObject* TableTicker::ToJSObject(JSContext *aCx)
}
static
void addProfileEntry(volatile StackEntry &entry, ThreadProfile &aProfile)
void addProfileEntry(volatile StackEntry &entry, ThreadProfile &aProfile,
ProfileStack *stack, void *lastpc)
{
int lineno = -1;
// First entry has tagName 's' (start)
// Check for magic pointer bit 1 to indicate copy
const char* sampleLabel = entry.label();
@ -646,8 +665,30 @@ void addProfileEntry(volatile StackEntry &entry, ThreadProfile &aProfile)
// Cast to *((void**) to pass the text data to a void*
aProfile.addTag(ProfileEntry('d', *((void**)(&text[0]))));
}
if (entry.js()) {
if (!entry.pc()) {
// The JIT only allows the top-most entry to have a NULL pc
MOZ_ASSERT(&entry == &stack->mStack[stack->stackSize() - 1]);
// If stack-walking was disabled, then that's just unfortunate
if (lastpc) {
jsbytecode *jspc = js::ProfilingGetPC(stack->mRuntime, entry.script(),
lastpc);
if (jspc) {
lineno = JS_PCToLineNumber(NULL, entry.script(), jspc);
}
}
} else {
lineno = JS_PCToLineNumber(NULL, entry.script(), entry.pc());
}
} else {
lineno = entry.line();
}
} else {
aProfile.addTag(ProfileEntry('c', sampleLabel));
lineno = entry.line();
}
if (lineno != -1) {
aProfile.addTag(ProfileEntry('n', lineno));
}
}
@ -746,7 +787,7 @@ void TableTicker::doBacktrace(ThreadProfile &aProfile, TickSample* aSample)
if (entry.stackAddress() < array.sp_array[i-1] && entry.stackAddress())
break;
addProfileEntry(entry, aProfile);
addProfileEntry(entry, aProfile, stack, array.array[0]);
pseudoStackPos++;
}
@ -812,7 +853,7 @@ void doSampleStackTrace(ProfileStack *aStack, ThreadProfile &aProfile, TickSampl
// followed by 0 or more 'c' tags.
aProfile.addTag(ProfileEntry('s', "(root)"));
for (uint32_t i = 0; i < aStack->stackSize(); i++) {
addProfileEntry(aStack->mStack[i], aProfile);
addProfileEntry(aStack->mStack[i], aProfile, aStack, nullptr);
}
#ifdef ENABLE_SPS_LEAF_DATA
if (sample) {