Revision: 3154
Author: [email protected]
Date: Wed Oct 28 02:13:11 2009
Log: Fix crbug/24815. Changes affect profiler "lazy" mode used for V8 in  
Chromium.

- don't engage the processing thread of CPU profiling until the first time  
profiling is resumed, this saves us a thread allocation for the majority of  
users;
- don't log shared libraries addresses: this is useless for JS-only  
profiling, and also consumes time on startup.

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

Modified:
  /branches/bleeding_edge/src/log.cc
  /branches/bleeding_edge/test/cctest/test-log.cc

=======================================
--- /branches/bleeding_edge/src/log.cc  Thu Oct 15 00:50:23 2009
+++ /branches/bleeding_edge/src/log.cc  Wed Oct 28 02:13:11 2009
@@ -125,6 +125,9 @@
    bool overflow_;  // Tell whether a buffer overflow has occurred.
    Semaphore* buffer_semaphore_;  // Sempahore used for buffer  
synchronization.

+  // Tells whether profiler is engaged, that is, processing thread is  
stated.
+  bool engaged_;
+
    // Tells whether worker thread should continue running.
    bool running_;

@@ -243,17 +246,25 @@
  //
  // Profiler implementation.
  //
-Profiler::Profiler() {
-  buffer_semaphore_ = OS::CreateSemaphore(0);
-  head_ = 0;
-  tail_ = 0;
-  overflow_ = false;
-  running_ = false;
+Profiler::Profiler()
+    : head_(0),
+      tail_(0),
+      overflow_(false),
+      buffer_semaphore_(OS::CreateSemaphore(0)),
+      engaged_(false),
+      running_(false) {
  }


  void Profiler::Engage() {
-  OS::LogSharedLibraryAddresses();
+  if (engaged_) return;
+  engaged_ = true;
+
+  // TODO(mnaganov): This is actually "Chromium" mode. Flags need to be  
revised.
+  // http://code.google.com/p/v8/issues/detail?id=487
+  if (!FLAG_prof_lazy) {
+    OS::LogSharedLibraryAddresses();
+  }

    // Start thread processing the profiler buffer.
    running_ = true;
@@ -268,6 +279,8 @@


  void Profiler::Disengage() {
+  if (!engaged_) return;
+
    // Stop receiving ticks.
    Logger::ticker_->ClearProfiler();

@@ -1053,6 +1066,7 @@
    }
    if (modules_to_enable & PROFILER_MODULE_CPU) {
      if (FLAG_prof_lazy) {
+      profiler_->Engage();
        LOG(UncheckedStringEvent("profiler", "resume"));
        FLAG_log_code = true;
        LogCompiledFunctions();
@@ -1245,7 +1259,9 @@
      } else {
        is_logging_ = true;
      }
-    profiler_->Engage();
+    if (!FLAG_prof_lazy) {
+      profiler_->Engage();
+    }
    }

    LogMessageBuilder::set_write_failure_handler(StopLoggingAndProfiling);
=======================================
--- /branches/bleeding_edge/test/cctest/test-log.cc     Wed Oct  7 05:20:02 2009
+++ /branches/bleeding_edge/test/cctest/test-log.cc     Wed Oct 28 02:13:11 2009
@@ -256,11 +256,10 @@
    // No sampling should happen prior to resuming profiler.
    CHECK(!LoggerTestHelper::IsSamplerActive());

-  // Read initial logged data (static libs map).
    EmbeddedVector<char, 102400> buffer;
+  // Nothing must be logged until profiling is resumed.
    int log_pos = GetLogLines(0, &buffer);
-  CHECK_GT(log_pos, 0);
-  CHECK_GT(buffer.length(), log_pos);
+  CHECK_EQ(0, log_pos);

    CompileAndRunScript("var a = (function(x) { return x + 1; })(10);");


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

Reply via email to