Revision: 4285
Author: [email protected]
Date: Thu Mar 25 07:55:53 2010
Log: Align OProfile agent invocations style with logging.

This allows to unclutter logging-related code.
I also fixed compilation issues with 'profilingsupport=off'.

Review URL: http://codereview.chromium.org/1317003
http://code.google.com/p/v8/source/detail?r=4285

Modified:
 /branches/bleeding_edge/src/code-stubs.cc
 /branches/bleeding_edge/src/compiler.cc
 /branches/bleeding_edge/src/compiler.h
 /branches/bleeding_edge/src/oprofile-agent.cc
 /branches/bleeding_edge/src/oprofile-agent.h
 /branches/bleeding_edge/src/platform.h

=======================================
--- /branches/bleeding_edge/src/code-stubs.cc   Mon Mar  1 08:24:05 2010
+++ /branches/bleeding_edge/src/code-stubs.cc   Thu Mar 25 07:55:53 2010
@@ -61,13 +61,9 @@
 void CodeStub::RecordCodeGeneration(Code* code, MacroAssembler* masm) {
   code->set_major_key(MajorKey());

-#ifdef ENABLE_OPROFILE_AGENT
-  // Register the generated stub with the OPROFILE agent.
-  OProfileAgent::CreateNativeCodeRegion(GetName(),
-                                        code->instruction_start(),
-                                        code->instruction_size());
-#endif
-
+  OPROFILE(CreateNativeCodeRegion(GetName(),
+                                  code->instruction_start(),
+                                  code->instruction_size()));
   LOG(CodeCreateEvent(Logger::STUB_TAG, code, GetName()));
   Counters::total_stubs_code_size.Increment(code->instruction_size());

=======================================
--- /branches/bleeding_edge/src/compiler.cc     Wed Mar 24 03:36:18 2010
+++ /branches/bleeding_edge/src/compiler.cc     Thu Mar 25 07:55:53 2010
@@ -235,27 +235,19 @@
     return Handle<SharedFunctionInfo>::null();
   }

-#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
- // Log the code generation for the script. Check explicit whether logging is
-  // to avoid allocating when not required.
-  if (Logger::is_logging() || OProfileAgent::is_enabled()) {
-    if (script->name()->IsString()) {
-      SmartPointer<char> data =
-          String::cast(script->name())->ToCString(DISALLOW_NULLS);
-      LOG(CodeCreateEvent(is_eval ? Logger::EVAL_TAG : Logger::SCRIPT_TAG,
-                          *code, *data));
-      OProfileAgent::CreateNativeCodeRegion(*data,
-                                            code->instruction_start(),
-                                            code->instruction_size());
-    } else {
-      LOG(CodeCreateEvent(is_eval ? Logger::EVAL_TAG : Logger::SCRIPT_TAG,
-                          *code, ""));
-      OProfileAgent::CreateNativeCodeRegion(is_eval ? "Eval" : "Script",
-                                            code->instruction_start(),
-                                            code->instruction_size());
-    }
-  }
-#endif
+  if (script->name()->IsString()) {
+    LOG(CodeCreateEvent(is_eval ? Logger::EVAL_TAG : Logger::SCRIPT_TAG,
+                        *code, String::cast(script->name())));
+    OPROFILE(CreateNativeCodeRegion(String::cast(script->name()),
+                                    code->instruction_start(),
+                                    code->instruction_size()));
+  } else {
+    LOG(CodeCreateEvent(is_eval ? Logger::EVAL_TAG : Logger::SCRIPT_TAG,
+                        *code, ""));
+    OPROFILE(CreateNativeCodeRegion(is_eval ? "Eval" : "Script",
+                                    code->instruction_start(),
+                                    code->instruction_size()));
+  }

   // Allocate function.
   Handle<SharedFunctionInfo> result =
@@ -443,14 +435,12 @@
     return false;
   }

-#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
-  LogCodeCreateEvent(Logger::LAZY_COMPILE_TAG,
-                     name,
-                     Handle<String>(shared->inferred_name()),
-                     start_position,
-                     info->script(),
-                     code);
-#endif
+  RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG,
+                            name,
+                            Handle<String>(shared->inferred_name()),
+                            start_position,
+                            info->script(),
+                            code);

   // Update the shared function info with the compiled code.
   shared->set_code(*code);
@@ -578,15 +568,12 @@
     }

     // Function compilation complete.
-
-#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
-    LogCodeCreateEvent(Logger::FUNCTION_TAG,
-                       literal->name(),
-                       literal->inferred_name(),
-                       literal->start_position(),
-                       script,
-                       code);
-#endif
+    RecordFunctionCompilation(Logger::FUNCTION_TAG,
+                              literal->name(),
+                              literal->inferred_name(),
+                              literal->start_position(),
+                              script,
+                              code);
   }

   // Create a boilerplate function.
@@ -628,13 +615,12 @@
 }


-#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
-void Compiler::LogCodeCreateEvent(Logger::LogEventsAndTags tag,
-                                  Handle<String> name,
-                                  Handle<String> inferred_name,
-                                  int start_position,
-                                  Handle<Script> script,
-                                  Handle<Code> code) {
+void Compiler::RecordFunctionCompilation(Logger::LogEventsAndTags tag,
+                                         Handle<String> name,
+                                         Handle<String> inferred_name,
+                                         int start_position,
+                                         Handle<Script> script,
+                                         Handle<Code> code) {
   // Log the code generation. If source information is available
   // include script name and line number. Check explicitly whether
   // logging is enabled as finding the line number is not free.
@@ -642,21 +628,21 @@
     Handle<String> func_name(name->length() > 0 ? *name : *inferred_name);
     if (script->name()->IsString()) {
       int line_num = GetScriptLineNumber(script, start_position) + 1;
+      USE(line_num);
       LOG(CodeCreateEvent(tag, *code, *func_name,
                           String::cast(script->name()), line_num));
-      OProfileAgent::CreateNativeCodeRegion(*func_name,
-                                            String::cast(script->name()),
-                                            line_num,
-                                            code->instruction_start(),
-                                            code->instruction_size());
+      OPROFILE(CreateNativeCodeRegion(*func_name,
+                                      String::cast(script->name()),
+                                      line_num,
+                                      code->instruction_start(),
+                                      code->instruction_size()));
     } else {
       LOG(CodeCreateEvent(tag, *code, *func_name));
-      OProfileAgent::CreateNativeCodeRegion(*func_name,
-                                            code->instruction_start(),
-                                            code->instruction_size());
+      OPROFILE(CreateNativeCodeRegion(*func_name,
+                                      code->instruction_start(),
+                                      code->instruction_size()));
     }
   }
 }
-#endif

 } }  // namespace v8::internal
=======================================
--- /branches/bleeding_edge/src/compiler.h      Mon Mar 22 23:04:44 2010
+++ /branches/bleeding_edge/src/compiler.h      Thu Mar 25 07:55:53 2010
@@ -266,15 +266,12 @@
                               Handle<Script> script);

  private:
-
-#if defined ENABLE_LOGGING_AND_PROFILING || defined ENABLE_OPROFILE_AGENT
-  static void LogCodeCreateEvent(Logger::LogEventsAndTags tag,
-                                 Handle<String> name,
-                                 Handle<String> inferred_name,
-                                 int start_position,
-                                 Handle<Script> script,
-                                 Handle<Code> code);
-#endif
+  static void RecordFunctionCompilation(Logger::LogEventsAndTags tag,
+                                        Handle<String> name,
+                                        Handle<String> inferred_name,
+                                        int start_position,
+                                        Handle<Script> script,
+                                        Handle<Code> code);
 };


=======================================
--- /branches/bleeding_edge/src/oprofile-agent.cc       Wed Sep  9 03:49:40 2009
+++ /branches/bleeding_edge/src/oprofile-agent.cc       Thu Mar 25 07:55:53 2010
@@ -32,10 +32,6 @@
 namespace v8 {
 namespace internal {

-#ifdef ENABLE_OPROFILE_AGENT
-op_agent_t OProfileAgent::handle_ = NULL;
-#endif
-

 bool OProfileAgent::Initialize() {
 #ifdef ENABLE_OPROFILE_AGENT
@@ -68,49 +64,45 @@
   }
 #endif
 }
+
+
+#ifdef ENABLE_OPROFILE_AGENT
+op_agent_t OProfileAgent::handle_ = NULL;


 void OProfileAgent::CreateNativeCodeRegion(const char* name,
     const void* ptr, unsigned int size) {
-#ifdef ENABLE_OPROFILE_AGENT
-  if (handle_ == NULL) return;
   op_write_native_code(handle_, name, (uint64_t)ptr, ptr, size);
-#endif
 }


 void OProfileAgent::CreateNativeCodeRegion(String* name,
     const void* ptr, unsigned int size) {
-#ifdef ENABLE_OPROFILE_AGENT
-  if (handle_ != NULL) {
-    const char* func_name;
-    SmartPointer<char> str =
-        name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
-    func_name = name->length() > 0 ? *str : "<anonymous>";
-    CreateNativeCodeRegion(func_name, ptr, size);
-  }
-#endif
+  const char* func_name;
+  SmartPointer<char> str =
+      name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
+  func_name = name->length() > 0 ? *str : "<anonymous>";
+  CreateNativeCodeRegion(func_name, ptr, size);
 }


 void OProfileAgent::CreateNativeCodeRegion(String* name, String* source,
     int line_num, const void* ptr, unsigned int size) {
-#ifdef ENABLE_OPROFILE_AGENT
-  if (handle_ != NULL) {
- Vector<char> buf = Vector<char>::New(OProfileAgent::kFormattingBufSize);
-    const char* func_name;
-    SmartPointer<char> str =
-        name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
-    func_name = name->length() > 0 ? *str : "<anonymous>";
-    SmartPointer<char> source_str =
-        source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
-    if (v8::internal::OS::SNPrintF(buf, "%s %s:%d",
- func_name, *source_str, line_num) != -1) {
-      CreateNativeCodeRegion(buf.start(), ptr, size);
-    } else {
-      CreateNativeCodeRegion("<script/func name too long>", ptr, size);
-    }
-  }
-#endif
-}
-} }
+  Vector<char> buf = Vector<char>::New(OProfileAgent::kFormattingBufSize);
+  const char* func_name;
+  SmartPointer<char> str =
+      name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
+  func_name = name->length() > 0 ? *str : "<anonymous>";
+  SmartPointer<char> source_str =
+      source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
+  if (v8::internal::OS::SNPrintF(buf, "%s %s:%d",
+                                 func_name, *source_str, line_num) != -1) {
+    CreateNativeCodeRegion(buf.start(), ptr, size);
+  } else {
+    CreateNativeCodeRegion("<script/func name too long>", ptr, size);
+  }
+}
+
+#endif  // ENABLE_OPROFILE_AGENT
+
+} }  // namespace v8::internal
=======================================
--- /branches/bleeding_edge/src/oprofile-agent.h        Wed Sep  9 03:49:40 2009
+++ /branches/bleeding_edge/src/oprofile-agent.h        Thu Mar 25 07:55:53 2010
@@ -37,6 +37,14 @@
 // system headers (they have __uint64_t), but is defined
 // in V8's headers.
 #include <opagent.h>  // NOLINT
+
+#define OPROFILE(Call)                             \
+  do {                                             \
+    if (v8::internal::OProfileAgent::is_enabled()) \
+      v8::internal::OProfileAgent::Call;           \
+  } while (false)
+#else
+#define OPROFILE(Call) ((void) 0)
 #endif

 namespace v8 {
@@ -46,13 +54,13 @@
  public:
   static bool Initialize();
   static void TearDown();
+#ifdef ENABLE_OPROFILE_AGENT
   static void CreateNativeCodeRegion(const char* name,
                                      const void* ptr, unsigned int size);
   static void CreateNativeCodeRegion(String* name,
                                      const void* ptr, unsigned int size);
static void CreateNativeCodeRegion(String* name, String* source, int line_num,
                                      const void* ptr, unsigned int size);
-#ifdef ENABLE_OPROFILE_AGENT
   static bool is_enabled() { return handle_ != NULL; }

  private:
=======================================
--- /branches/bleeding_edge/src/platform.h      Fri Mar 19 02:46:53 2010
+++ /branches/bleeding_edge/src/platform.h      Thu Mar 25 07:55:53 2010
@@ -505,7 +505,6 @@
 };


-#ifdef ENABLE_LOGGING_AND_PROFILING
// ----------------------------------------------------------------------------
 // Sampler
 //
@@ -533,6 +532,7 @@
   int frames_count;  // Number of captured frames.
 };

+#ifdef ENABLE_LOGGING_AND_PROFILING
 class Sampler {
  public:
   // Initialize sampler.

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

To unsubscribe from this group, send email to v8-dev+unsubscribegooglegroups.com or reply 
to this email with the words "REMOVE ME" as the subject.

Reply via email to