Adding src_file_name:line_number into perf log entries for compiled JS functions.
Thus, instead of the following profiler records: 1.5% 1.5% LazyCompile: <anonymous> we'll now have these: 1.5% 1.5% LazyCompile: <anonymous> richards.js:309 Basically, I translated two functions from messages.js into C++. In the next CL I will update messages.js to use added native functions. Review URL: http://codereview.chromium.org/19537 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1216 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
e9a496a5fe
commit
3835e915c4
@ -293,7 +293,18 @@ bool Compiler::CompileLazy(Handle<SharedFunctionInfo> shared,
|
||||
}
|
||||
|
||||
// Generate the code, update the function info, and return the code.
|
||||
LOG(CodeCreateEvent("LazyCompile", *code, *lit->name()));
|
||||
#ifdef ENABLE_LOGGING_AND_PROFILING
|
||||
if (script->name()->IsString()) {
|
||||
int lineNum = script->GetLineNumber(start_position);
|
||||
if (lineNum > 0) {
|
||||
lineNum += script->line_offset()->value() + 1;
|
||||
}
|
||||
LOG(CodeCreateEvent("LazyCompile", *code, *lit->name(),
|
||||
String::cast(script->name()), lineNum));
|
||||
} else {
|
||||
LOG(CodeCreateEvent("LazyCompile", *code, *lit->name()));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Update the shared function info with the compiled code.
|
||||
shared->set_code(*code);
|
||||
|
@ -160,6 +160,7 @@ Handle<Script> Factory::NewScript(Handle<String> source) {
|
||||
script->set_column_offset(Smi::FromInt(0));
|
||||
script->set_type(Smi::FromInt(SCRIPT_TYPE_NORMAL));
|
||||
script->set_wrapper(*Factory::NewProxy(0, TENURED));
|
||||
script->set_line_ends(Heap::undefined_value());
|
||||
return script;
|
||||
}
|
||||
|
||||
|
16
src/log.cc
16
src/log.cc
@ -588,6 +588,22 @@ void Logger::CodeCreateEvent(const char* tag, Code* code, String* name) {
|
||||
}
|
||||
|
||||
|
||||
void Logger::CodeCreateEvent(const char* tag, Code* code, String* name,
|
||||
String* source, int line) {
|
||||
#ifdef ENABLE_LOGGING_AND_PROFILING
|
||||
if (logfile_ == NULL || !FLAG_log_code) return;
|
||||
ScopedLock sl(mutex_);
|
||||
SmartPointer<char> str =
|
||||
name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
|
||||
SmartPointer<char> sourcestr =
|
||||
source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
|
||||
fprintf(logfile_, "code-creation,%s,0x%x,%d,\"%s %s:%d\"\n", tag,
|
||||
reinterpret_cast<unsigned int>(code->address()),
|
||||
code->instruction_size(), *str, *sourcestr, line);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Logger::CodeCreateEvent(const char* tag, Code* code, int args_count) {
|
||||
#ifdef ENABLE_LOGGING_AND_PROFILING
|
||||
if (logfile_ == NULL || !FLAG_log_code) return;
|
||||
|
@ -163,6 +163,8 @@ class Logger {
|
||||
// Emits a code create event.
|
||||
static void CodeCreateEvent(const char* tag, Code* code, const char* source);
|
||||
static void CodeCreateEvent(const char* tag, Code* code, String* name);
|
||||
static void CodeCreateEvent(const char* tag, Code* code, String* name,
|
||||
String* source, int line);
|
||||
static void CodeCreateEvent(const char* tag, Code* code, int args_count);
|
||||
static void CodeAllocateEvent(Code* code, Assembler* assem);
|
||||
// Emits a code move event.
|
||||
|
@ -1989,6 +1989,7 @@ ACCESSORS(Script, line_offset, Smi, kLineOffsetOffset)
|
||||
ACCESSORS(Script, column_offset, Smi, kColumnOffsetOffset)
|
||||
ACCESSORS(Script, wrapper, Proxy, kWrapperOffset)
|
||||
ACCESSORS(Script, type, Smi, kTypeOffset)
|
||||
ACCESSORS(Script, line_ends, Object, kLineEndsOffset)
|
||||
|
||||
ACCESSORS(DebugInfo, shared, SharedFunctionInfo, kSharedFunctionInfoIndex)
|
||||
ACCESSORS(DebugInfo, original_code, Code, kOriginalCodeIndex)
|
||||
|
@ -6775,6 +6775,61 @@ Object* Dictionary::TransformPropertiesToFastFor(JSObject* obj,
|
||||
}
|
||||
|
||||
|
||||
// Init line_ends array with code positions of line ends inside script source
|
||||
void Script::InitLineEnds() {
|
||||
if (!line_ends()->IsUndefined()) return;
|
||||
|
||||
Handle<String> src(String::cast(source()));
|
||||
const int src_len = src->length();
|
||||
Handle<JSArray> array = Factory::NewJSArray(0);
|
||||
int array_index = 0;
|
||||
Handle<String> new_line = Factory::NewStringFromAscii(CStrVector("\n"));
|
||||
int position = 0;
|
||||
while (position < src_len) {
|
||||
position = Runtime::StringMatch(src, new_line, position);
|
||||
if (position != -1) {
|
||||
SetElement(array, array_index++, Handle<Smi>(Smi::FromInt(position++)));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If the script does not end with a line ending add the final end position
|
||||
// as just past the last line ending.
|
||||
if (array_index == 0 ||
|
||||
(Smi::cast(array->GetElement(array_index - 1))->value() != src_len - 1)) {
|
||||
SetElement(array, array_index++, Handle<Smi>(Smi::FromInt(src_len)));
|
||||
}
|
||||
|
||||
Handle<FixedArray> fixed_array = Factory::NewFixedArray(0);
|
||||
set_line_ends(fixed_array->AddKeysFromJSArray(*array));
|
||||
ASSERT(line_ends()->IsFixedArray());
|
||||
}
|
||||
|
||||
|
||||
// Convert code position into line number
|
||||
int Script::GetLineNumber(int code_pos) {
|
||||
InitLineEnds();
|
||||
FixedArray* line_ends_array = FixedArray::cast(line_ends());
|
||||
|
||||
int line = -1;
|
||||
if (code_pos <= (Smi::cast(line_ends_array->get(0)))->value()) {
|
||||
line = 0;
|
||||
} else {
|
||||
const int line_ends_length = line_ends_array->length();
|
||||
for (int i = 1; i < line_ends_length; ++i) {
|
||||
if ((Smi::cast(line_ends_array->get(i - 1)))->value() < code_pos &&
|
||||
code_pos <= (Smi::cast(line_ends_array->get(i)))->value()) {
|
||||
line = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return line != -1 ? line + line_offset()->value() : line;
|
||||
}
|
||||
|
||||
|
||||
// Check if there is a break point at this code position.
|
||||
bool DebugInfo::HasBreakPoint(int code_position) {
|
||||
// Get the break point info object for this code position.
|
||||
|
@ -2537,6 +2537,9 @@ class Script: public Struct {
|
||||
// [type]: the script type.
|
||||
DECL_ACCESSORS(type, Smi)
|
||||
|
||||
// [line_ends]: array of line ends positions
|
||||
DECL_ACCESSORS(line_ends, Object)
|
||||
|
||||
static inline Script* cast(Object* obj);
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -2544,13 +2547,17 @@ class Script: public Struct {
|
||||
void ScriptVerify();
|
||||
#endif
|
||||
|
||||
void InitLineEnds();
|
||||
int GetLineNumber(int code_position);
|
||||
|
||||
static const int kSourceOffset = HeapObject::kHeaderSize;
|
||||
static const int kNameOffset = kSourceOffset + kPointerSize;
|
||||
static const int kLineOffsetOffset = kNameOffset + kPointerSize;
|
||||
static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize;
|
||||
static const int kWrapperOffset = kColumnOffsetOffset + kPointerSize;
|
||||
static const int kTypeOffset = kWrapperOffset + kPointerSize;
|
||||
static const int kSize = kTypeOffset + kPointerSize;
|
||||
static const int kLineEndsOffset = kTypeOffset + kPointerSize;
|
||||
static const int kSize = kLineEndsOffset + kPointerSize;
|
||||
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(Script);
|
||||
|
@ -104,7 +104,10 @@ class JSCodeEntry(CodeEntry):
|
||||
|
||||
def ToString(self):
|
||||
name = self.name
|
||||
if name == '': name = '<anonymous>'
|
||||
if name == '':
|
||||
name = '<anonymous>'
|
||||
elif name.startswith(' '):
|
||||
name = '<anonymous>' + name
|
||||
return self.type + ': ' + name
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user