Revision: 17142
Author: [email protected]
Date: Thu Oct 10 13:15:47 2013 UTC
Log: Add column getter to CpuProfileNode
CpuProfileNode currently exposes only line number which is not enough for
the cases when there is more than one function on the same line. This
change exposes column number on CpuProfileNode.
BUG=302537
[email protected], [email protected]
Review URL: https://codereview.chromium.org/25541003
http://code.google.com/p/v8/source/detail?r=17142
Modified:
/branches/bleeding_edge/include/v8-profiler.h
/branches/bleeding_edge/src/api.cc
/branches/bleeding_edge/src/cpu-profiler.cc
/branches/bleeding_edge/src/cpu-profiler.h
/branches/bleeding_edge/src/log.cc
/branches/bleeding_edge/src/log.h
/branches/bleeding_edge/src/profile-generator-inl.h
/branches/bleeding_edge/src/profile-generator.cc
/branches/bleeding_edge/src/profile-generator.h
/branches/bleeding_edge/test/cctest/test-cpu-profiler.cc
=======================================
--- /branches/bleeding_edge/include/v8-profiler.h Mon Sep 30 13:28:23 2013
UTC
+++ /branches/bleeding_edge/include/v8-profiler.h Thu Oct 10 13:15:47 2013
UTC
@@ -57,6 +57,12 @@
*/
int GetLineNumber() const;
+ /**
+ * Returns 1-based number of the column where the function originates.
+ * kNoColumnNumberInfo if no column number information is available.
+ */
+ int GetColumnNumber() const;
+
/** Returns bailout reason for the function
* if the optimization was disabled for it.
*/
@@ -80,6 +86,7 @@
const CpuProfileNode* GetChild(int index) const;
static const int kNoLineNumberInfo = Message::kNoLineNumberInfo;
+ static const int kNoColumnNumberInfo = Message::kNoColumnInfo;
};
=======================================
--- /branches/bleeding_edge/src/api.cc Wed Oct 2 09:01:40 2013 UTC
+++ /branches/bleeding_edge/src/api.cc Thu Oct 10 13:15:47 2013 UTC
@@ -6926,6 +6926,12 @@
int CpuProfileNode::GetLineNumber() const {
return reinterpret_cast<const
i::ProfileNode*>(this)->entry()->line_number();
}
+
+
+int CpuProfileNode::GetColumnNumber() const {
+ return reinterpret_cast<const i::ProfileNode*>(this)->
+ entry()->column_number();
+}
const char* CpuProfileNode::GetBailoutReason() const {
=======================================
--- /branches/bleeding_edge/src/cpu-profiler.cc Thu Oct 10 13:03:41 2013 UTC
+++ /branches/bleeding_edge/src/cpu-profiler.cc Thu Oct 10 13:15:47 2013 UTC
@@ -261,7 +261,7 @@
Code* code,
SharedFunctionInfo* shared,
CompilationInfo* info,
- Name* source, int line) {
+ Name* source, int line, int column) {
if (FilterOutCodeCreateEvent(tag)) return;
CodeEventsContainer evt_rec(CodeEventRecord::CODE_CREATION);
CodeCreateEventRecord* rec = &evt_rec.CodeCreateEventRecord_;
@@ -271,7 +271,8 @@
profiles_->GetFunctionName(shared->DebugName()),
CodeEntry::kEmptyNamePrefix,
profiles_->GetName(source),
- line);
+ line,
+ column);
if (info) {
rec->entry->set_no_frame_ranges(info->ReleaseNoFrameRanges());
}
=======================================
--- /branches/bleeding_edge/src/cpu-profiler.h Fri Sep 6 06:25:06 2013 UTC
+++ /branches/bleeding_edge/src/cpu-profiler.h Thu Oct 10 13:15:47 2013 UTC
@@ -238,7 +238,7 @@
Code* code,
SharedFunctionInfo* shared,
CompilationInfo* info,
- Name* source, int line);
+ Name* source, int line, int column);
virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, int args_count);
virtual void CodeMovingGCEvent() {}
=======================================
--- /branches/bleeding_edge/src/log.cc Fri Oct 4 08:17:11 2013 UTC
+++ /branches/bleeding_edge/src/log.cc Thu Oct 10 13:15:47 2013 UTC
@@ -212,7 +212,7 @@
Code* code,
SharedFunctionInfo* shared,
CompilationInfo* info,
- Name* source, int line) {
+ Name* source, int line, int column) {
name_buffer_->Init(tag);
name_buffer_->AppendBytes(ComputeMarker(code));
name_buffer_->AppendString(shared->DebugName());
@@ -1232,10 +1232,11 @@
SharedFunctionInfo* shared,
CompilationInfo* info,
Name* source, int line, int column) {
- PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, source, line));
+ PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, source, line,
column));
if (!is_logging_code_events()) return;
- CALL_LISTENERS(CodeCreateEvent(tag, code, shared, info, source, line));
+ CALL_LISTENERS(CodeCreateEvent(tag, code, shared, info, source, line,
+ column));
if (!FLAG_log_code || !log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
=======================================
--- /branches/bleeding_edge/src/log.h Mon Sep 30 13:53:21 2013 UTC
+++ /branches/bleeding_edge/src/log.h Thu Oct 10 13:15:47 2013 UTC
@@ -471,7 +471,7 @@
SharedFunctionInfo* shared,
CompilationInfo* info,
Name* source,
- int line) = 0;
+ int line, int column) = 0;
virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code,
int args_count) = 0;
@@ -510,7 +510,7 @@
SharedFunctionInfo* shared,
CompilationInfo* info,
Name* source,
- int line);
+ int line, int column);
virtual void RegExpCodeCreateEvent(Code* code, String* source);
virtual void CallbackEvent(Name* name, Address entry_point) { }
=======================================
--- /branches/bleeding_edge/src/profile-generator-inl.h Thu Sep 5 13:20:51
2013 UTC
+++ /branches/bleeding_edge/src/profile-generator-inl.h Thu Oct 10 13:15:47
2013 UTC
@@ -47,13 +47,15 @@
const char* name,
const char* name_prefix,
const char* resource_name,
- int line_number)
+ int line_number,
+ int column_number)
: tag_(tag),
builtin_id_(Builtins::builtin_count),
name_prefix_(name_prefix),
name_(name),
resource_name_(resource_name),
line_number_(line_number),
+ column_number_(column_number),
shared_id_(0),
script_id_(v8::Script::kNoScriptId),
no_frame_ranges_(NULL),
=======================================
--- /branches/bleeding_edge/src/profile-generator.cc Wed Sep 11 07:14:41
2013 UTC
+++ /branches/bleeding_edge/src/profile-generator.cc Thu Oct 10 13:15:47
2013 UTC
@@ -546,12 +546,14 @@
const char* name,
const char* name_prefix,
const char* resource_name,
- int line_number) {
+ int line_number,
+ int column_number) {
CodeEntry* code_entry = new CodeEntry(tag,
name,
name_prefix,
resource_name,
- line_number);
+ line_number,
+ column_number);
code_entries_.Add(code_entry);
return code_entry;
}
=======================================
--- /branches/bleeding_edge/src/profile-generator.h Wed Sep 11 07:14:41
2013 UTC
+++ /branches/bleeding_edge/src/profile-generator.h Thu Oct 10 13:15:47
2013 UTC
@@ -77,7 +77,9 @@
const char* name,
const char* name_prefix = CodeEntry::kEmptyNamePrefix,
const char* resource_name =
CodeEntry::kEmptyResourceName,
- int line_number =
v8::CpuProfileNode::kNoLineNumberInfo));
+ int line_number = v8::CpuProfileNode::kNoLineNumberInfo,
+ int column_number =
+ v8::CpuProfileNode::kNoColumnNumberInfo));
~CodeEntry();
INLINE(bool is_js_function() const) { return is_js_function_tag(tag_); }
@@ -86,6 +88,7 @@
INLINE(const char* name() const) { return name_; }
INLINE(const char* resource_name() const) { return resource_name_; }
INLINE(int line_number() const) { return line_number_; }
+ int column_number() const { return column_number_; }
INLINE(void set_shared_id(int shared_id)) { shared_id_ = shared_id; }
INLINE(int script_id() const) { return script_id_; }
INLINE(void set_script_id(int script_id)) { script_id_ = script_id; }
@@ -119,6 +122,7 @@
const char* name_;
const char* resource_name_;
int line_number_;
+ int column_number_;
int shared_id_;
int script_id_;
List<OffsetRange>* no_frame_ranges_;
@@ -304,7 +308,8 @@
const char* name,
const char* name_prefix = CodeEntry::kEmptyNamePrefix,
const char* resource_name = CodeEntry::kEmptyResourceName,
- int line_number = v8::CpuProfileNode::kNoLineNumberInfo);
+ int line_number = v8::CpuProfileNode::kNoLineNumberInfo,
+ int column_number = v8::CpuProfileNode::kNoColumnNumberInfo);
// Called from profile generator thread.
void AddPathToCurrentProfiles(const Vector<CodeEntry*>& path);
=======================================
--- /branches/bleeding_edge/test/cctest/test-cpu-profiler.cc Thu Oct 10
13:03:41 2013 UTC
+++ /branches/bleeding_edge/test/cctest/test-cpu-profiler.cc Thu Oct 10
13:15:47 2013 UTC
@@ -1389,3 +1389,56 @@
cpu_profiler->DeleteAllCpuProfiles();
}
+
+
+static void CheckFunctionDetails(const v8::CpuProfileNode* node,
+ const char* name, const char* script_name, int script_id,
+ int line, int column) {
+ CHECK_EQ(v8::String::New(name), node->GetFunctionName());
+ CHECK_EQ(v8::String::New(script_name), node->GetScriptResourceName());
+ CHECK_EQ(script_id, node->GetScriptId());
+ CHECK_EQ(line, node->GetLineNumber());
+ CHECK_EQ(column, node->GetColumnNumber());
+}
+
+
+TEST(FunctionDetails) {
+ const char* extensions[] = { "v8/profiler" };
+ v8::ExtensionConfiguration config(1, extensions);
+ LocalContext env(&config);
+ v8::HandleScope handleScope(env->GetIsolate());
+
+ v8::CpuProfiler* profiler = env->GetIsolate()->GetCpuProfiler();
+ CHECK_EQ(0, profiler->GetProfileCount());
+ v8::Handle<v8::Script> script_a = v8::Script::Compile(v8::String::New(
+ " function foo\n() { try { bar(); } catch(e) {} }\n"
+ " function bar() { startProfiling(); }\n"),
v8::String::New("script_a"));
+ script_a->Run();
+ v8::Handle<v8::Script> script_b = v8::Script::Compile(v8::String::New(
+ "\n\n function baz() { try { foo(); } catch(e) {} }\n"
+ "\n\nbaz();\n"
+ "stopProfiling();\n"), v8::String::New("script_b"));
+ script_b->Run();
+ CHECK_EQ(1, profiler->GetProfileCount());
+ const v8::CpuProfile* profile = profiler->GetCpuProfile(0);
+ const v8::CpuProfileNode* current = profile->GetTopDownRoot();
+ reinterpret_cast<ProfileNode*>(
+ const_cast<v8::CpuProfileNode*>(current))->Print(0);
+ // The tree should look like this:
+ // 0 (root) 0 #1
+ // 0 (anonymous function) 19 #2 no reason script_b:1
+ // 0 baz 19 #3 TryCatchStatement script_b:3
+ // 0 foo 18 #4 TryCatchStatement script_a:2
+ // 1 bar 18 #5 no reason script_a:3
+ const v8::CpuProfileNode* root = profile->GetTopDownRoot();
+ const v8::CpuProfileNode* script = GetChild(root,
+ ProfileGenerator::kAnonymousFunctionName);
+ CheckFunctionDetails(script, ProfileGenerator::kAnonymousFunctionName,
+ "script_b", script_b->GetId(), 1, 1);
+ const v8::CpuProfileNode* baz = GetChild(script, "baz");
+ CheckFunctionDetails(baz, "baz", "script_b", script_b->GetId(), 3, 16);
+ const v8::CpuProfileNode* foo = GetChild(baz, "foo");
+ CheckFunctionDetails(foo, "foo", "script_a", script_a->GetId(), 2, 1);
+ const v8::CpuProfileNode* bar = GetChild(foo, "bar");
+ CheckFunctionDetails(bar, "bar", "script_a", script_a->GetId(), 3, 14);
+}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.