Bug 785922 - Add column information for JS functions to the profile.
These are the strings that are used to describe a function; the line and column
numbers describe where the function *starts*.
I don't know why we have basically the same code in two places, one instance for
the interpreter and one for JIT frames.
MozReview-Commit-ID: F0LEWLPNsS6
--- a/js/src/jit/JitcodeMap.cpp
+++ b/js/src/jit/JitcodeMap.cpp
@@ -330,39 +330,41 @@ JitcodeGlobalEntry::createScriptString(J
nameLength = strlen(nameStr.get());
hasName = true;
}
// Calculate filename length
const char* filenameStr = script->filename() ? script->filename() : "(null)";
size_t filenameLength = strlen(filenameStr);
- // Calculate lineno length
- bool hasLineno = false;
- size_t linenoLength = 0;
- char linenoStr[15];
+ // Calculate lineno + column length
+ bool haseLinenoAndColumn = false;
+ size_t linenoAndColumnLength = 0;
+ char linenoAndColumnStr[30];
if (hasName || (script->functionNonDelazifying() || script->isForEval())) {
- linenoLength = SprintfLiteral(linenoStr, "%zu", script->lineno());
- hasLineno = true;
+ linenoAndColumnLength =
+ SprintfLiteral(linenoAndColumnStr, "%zu:%zu",
+ script->lineno(), script->column());
+ haseLinenoAndColumn = true;
}
// Full profile string for scripts with functions is:
- // FuncName (FileName:Lineno)
+ // FuncName (FileName:Lineno:Column)
// Full profile string for scripts without functions is:
- // FileName:Lineno
+ // FileName:Lineno:Column
// Full profile string for scripts without functions and without linenos is:
// FileName
// Calculate full string length.
size_t fullLength = 0;
if (hasName) {
- MOZ_ASSERT(hasLineno);
- fullLength = nameLength + 2 + filenameLength + 1 + linenoLength + 1;
- } else if (hasLineno) {
- fullLength = filenameLength + 1 + linenoLength;
+ MOZ_ASSERT(haseLinenoAndColumn);
+ fullLength = nameLength + 2 + filenameLength + 1 + linenoAndColumnLength + 1;
+ } else if (haseLinenoAndColumn) {
+ fullLength = filenameLength + 1 + linenoAndColumnLength;
} else {
fullLength = filenameLength;
}
// Allocate string.
char* str = cx->pod_malloc<char>(fullLength + 1);
if (!str)
return nullptr;
@@ -376,21 +378,21 @@ JitcodeGlobalEntry::createScriptString(J
str[cur++] = ' ';
str[cur++] = '(';
}
// Fill string with filename chars.
memcpy(str + cur, filenameStr, filenameLength);
cur += filenameLength;
- // Fill lineno chars.
- if (hasLineno) {
+ // Fill lineno + column chars.
+ if (haseLinenoAndColumn) {
str[cur++] = ':';
- memcpy(str + cur, linenoStr, linenoLength);
- cur += linenoLength;
+ memcpy(str + cur, linenoAndColumnStr, linenoAndColumnLength);
+ cur += linenoAndColumnLength;
}
// Terminal ')' if necessary.
if (hasName)
str[cur++] = ')';
MOZ_ASSERT(cur == fullLength);
str[cur] = 0;
--- a/js/src/vm/GeckoProfiler.cpp
+++ b/js/src/vm/GeckoProfiler.cpp
@@ -297,37 +297,42 @@ GeckoProfilerRuntime::allocProfileString
filename = "<unknown>";
size_t lenFilename = strlen(filename);
// Get the line number and its length as a string.
uint64_t lineno = script->lineno();
size_t lenLineno = 1;
for (uint64_t i = lineno; i /= 10; lenLineno++);
+ // Get the column number and its length as a string.
+ uint64_t column = script->column();
+ size_t lenColumn = 1;
+ for (uint64_t i = column; i /= 10; lenColumn++);
+
// Determine the required buffer size.
- size_t len = lenFilename + lenLineno + 1; // +1 for the ":" separating them.
+ size_t len = lenFilename + 1 + lenLineno + 1 + lenColumn; // +1 for the ":" separating them.
if (atom) {
len += JS::GetDeflatedUTF8StringLength(atom) + 3; // +3 for the " (" and ")" it adds.
}
// Allocate the buffer.
UniqueChars cstr(js_pod_malloc<char>(len + 1));
if (!cstr)
return nullptr;
// Construct the descriptive string.
DebugOnly<size_t> ret;
if (atom) {
UniqueChars atomStr = StringToNewUTF8CharsZ(nullptr, *atom);
if (!atomStr)
return nullptr;
- ret = snprintf(cstr.get(), len + 1, "%s (%s:%" PRIu64 ")", atomStr.get(), filename, lineno);
+ ret = snprintf(cstr.get(), len + 1, "%s (%s:%" PRIu64 ":%" PRIu64 ")", atomStr.get(), filename, lineno, column);
} else {
- ret = snprintf(cstr.get(), len + 1, "%s:%" PRIu64, filename, lineno);
+ ret = snprintf(cstr.get(), len + 1, "%s:%" PRIu64 ":%" PRIu64, filename, lineno, column);
}
MOZ_ASSERT(ret == len, "Computed length should match actual length!");
return cstr;
}
void