Author: [email protected]
Date: Tue Feb  3 02:52:02 2009
New Revision: 1216

Modified:
    branches/bleeding_edge/src/compiler.cc
    branches/bleeding_edge/src/factory.cc
    branches/bleeding_edge/src/log.cc
    branches/bleeding_edge/src/log.h
    branches/bleeding_edge/src/objects-inl.h
    branches/bleeding_edge/src/objects.cc
    branches/bleeding_edge/src/objects.h
    branches/bleeding_edge/tools/tickprocessor.py

Log:
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

Modified: branches/bleeding_edge/src/compiler.cc
==============================================================================
--- branches/bleeding_edge/src/compiler.cc      (original)
+++ branches/bleeding_edge/src/compiler.cc      Tue Feb  3 02:52:02 2009
@@ -293,7 +293,18 @@
    }

    // 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);

Modified: branches/bleeding_edge/src/factory.cc
==============================================================================
--- branches/bleeding_edge/src/factory.cc       (original)
+++ branches/bleeding_edge/src/factory.cc       Tue Feb  3 02:52:02 2009
@@ -160,6 +160,7 @@
    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;
  }


Modified: branches/bleeding_edge/src/log.cc
==============================================================================
--- branches/bleeding_edge/src/log.cc   (original)
+++ branches/bleeding_edge/src/log.cc   Tue Feb  3 02:52:02 2009
@@ -588,6 +588,22 @@
  }


+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;

Modified: branches/bleeding_edge/src/log.h
==============================================================================
--- branches/bleeding_edge/src/log.h    (original)
+++ branches/bleeding_edge/src/log.h    Tue Feb  3 02:52:02 2009
@@ -163,6 +163,8 @@
    // 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.

Modified: branches/bleeding_edge/src/objects-inl.h
==============================================================================
--- branches/bleeding_edge/src/objects-inl.h    (original)
+++ branches/bleeding_edge/src/objects-inl.h    Tue Feb  3 02:52:02 2009
@@ -1989,6 +1989,7 @@
  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)

Modified: branches/bleeding_edge/src/objects.cc
==============================================================================
--- branches/bleeding_edge/src/objects.cc       (original)
+++ branches/bleeding_edge/src/objects.cc       Tue Feb  3 02:52:02 2009
@@ -6775,6 +6775,61 @@
  }


+// 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.

Modified: branches/bleeding_edge/src/objects.h
==============================================================================
--- branches/bleeding_edge/src/objects.h        (original)
+++ branches/bleeding_edge/src/objects.h        Tue Feb  3 02:52:02 2009
@@ -2537,6 +2537,9 @@
    // [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 @@
    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);

Modified: branches/bleeding_edge/tools/tickprocessor.py
==============================================================================
--- branches/bleeding_edge/tools/tickprocessor.py       (original)
+++ branches/bleeding_edge/tools/tickprocessor.py       Tue Feb  3 02:52:02 2009
@@ -104,7 +104,10 @@

    def ToString(self):
      name = self.name
-    if name == '': name = '<anonymous>'
+    if name == '':
+      name = '<anonymous>'
+    elif name.startswith(' '):
+      name = '<anonymous>' + name
      return self.type + ': ' + name



--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to