[profiler] Add script name to v8.log with --log-source-code.

This also changes logging of code address to Code::instruction_start rather
than Code::address().

Bug: v8:6239
Change-Id: I4ef975630574e23409123468a3f7fb8fe6ad39e7
Reviewed-on: https://chromium-review.googlesource.com/605887
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47266}
This commit is contained in:
Jaroslav Sevcik 2017-08-08 15:31:38 +02:00 committed by Commit Bot
parent e6f5a80f0e
commit 92d13a12fc
3 changed files with 23 additions and 10 deletions

View File

@ -850,7 +850,7 @@ void Logger::CodeDeoptEvent(Code* code, DeoptKind kind, Address pc,
? static_cast<int>(timer_.Elapsed().InMicroseconds())
: -1;
msg.Append("code-deopt,%d,%d,", since_epoch, code->CodeSize());
msg.AppendAddress(code->address());
msg.AppendAddress(code->instruction_start());
// Deoptimization position.
std::ostringstream deopt_location;
@ -1053,8 +1053,8 @@ void AppendCodeCreateHeader(Log::MessageBuilder* msg,
? static_cast<int>(timer->Elapsed().InMicroseconds())
: -1;
msg->Append("%d,", timestamp);
msg->AppendAddress(code->address());
msg->Append(",%d,", code->ExecutableSize());
msg->AppendAddress(code->instruction_start());
msg->Append(",%d,", code->instruction_size());
}
} // namespace
@ -1155,6 +1155,16 @@ void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
String* source_code = String::cast(source_object);
os << "script," << script_id << ",\"";
msg.AppendUnbufferedCString(os.str().c_str());
// Log the script name.
if (script->name()->IsString()) {
msg.AppendUnbufferedHeapString(String::cast(script->name()));
msg.AppendUnbufferedCString("\",\"");
} else {
msg.AppendUnbufferedCString("<unknown>\",\"");
}
// Log the source code.
msg.AppendUnbufferedHeapString(source_code);
os.str("");
os << "\"" << std::endl;
@ -1184,8 +1194,8 @@ void Logger::CodeCreateEvent(CodeEventListener::LogEventsAndTags tag,
// <function-id> is an index into the <fns> function table
// <fns> is the function table encoded as a sequence of strings
// S<shared-function-info-address>
os << "code-source-info," << static_cast<void*>(code->address()) << ","
<< script_id << "," << shared->start_position() << ","
os << "code-source-info," << static_cast<void*>(code->instruction_start())
<< "," << script_id << "," << shared->start_position() << ","
<< shared->end_position() << ",";
SourcePositionTableIterator iterator(code->source_position_table());

View File

@ -1025,8 +1025,11 @@ function unescapeString(s) {
return s.join("");
}
JsonProfile.prototype.addScriptSource = function(script, source) {
this.scripts_[script] = unescapeString(source);
JsonProfile.prototype.addScriptSource = function(script, url, source) {
this.scripts_[script] = {
name : unescapeString(url),
source : unescapeString(source)
};
};

View File

@ -120,7 +120,7 @@ function TickProcessor(
parsers: [parseInt, parseInt, parseInt, parseInt, null, null, null],
processor: this.processCodeSourceInfo },
'script': {
parsers: [parseInt, null],
parsers: [parseInt, null, null],
processor: this.processCodeScript },
'sfi-move': { parsers: [parseInt, parseInt],
processor: this.processFunctionMove },
@ -330,8 +330,8 @@ TickProcessor.prototype.processCodeSourceInfo = function(
endPos, sourcePositions, inliningPositions, inlinedFunctions);
};
TickProcessor.prototype.processCodeScript = function(script, source) {
this.profile_.addScriptSource(script, source);
TickProcessor.prototype.processCodeScript = function(script, url, source) {
this.profile_.addScriptSource(script, url, source);
};
TickProcessor.prototype.processFunctionMove = function(from, to) {