Revision: 3986
Author: [email protected]
Date: Mon Mar  1 02:41:34 2010
Log: Logging-related changes.

 - when logging 'open-tag' / 'close-tag' events, don't depend on
   FLAG_log (as it may be not enabled, e.g. in Chromium);

 - PauseProfiler / ResumeProfiler were supposing that they
   use 'is_logging_' var exclusively, thus preventing any
   other logging that may be turned on for diagnostic purposes.

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

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

=======================================
--- /branches/bleeding_edge/src/log.cc  Thu Feb 18 04:47:17 2010
+++ /branches/bleeding_edge/src/log.cc  Mon Mar  1 02:41:34 2010
@@ -329,7 +329,7 @@
 SlidingStateWindow* Logger::sliding_state_window_ = NULL;
 const char** Logger::log_events_ = NULL;
 CompressionHelper* Logger::compression_helper_ = NULL;
-bool Logger::is_logging_ = false;
+int Logger::logging_nesting_ = 0;
 int Logger::cpu_profiler_nesting_ = 0;
 int Logger::heap_profiler_nesting_ = 0;

@@ -389,12 +389,19 @@

 void Logger::IntEvent(const char* name, int value) {
 #ifdef ENABLE_LOGGING_AND_PROFILING
-  if (!Log::IsEnabled() || !FLAG_log) return;
+  if (FLAG_log) UncheckedIntEvent(name, value);
+#endif
+}
+
+
+#ifdef ENABLE_LOGGING_AND_PROFILING
+void Logger::UncheckedIntEvent(const char* name, int value) {
+  if (!Log::IsEnabled()) return;
   LogMessageBuilder msg;
   msg.Append("%s,%d\n", name, value);
   msg.WriteToLogFile();
-#endif
-}
+}
+#endif


 void Logger::HandleEvent(const char* name, Object** location) {
@@ -1169,19 +1176,18 @@
         // Must be the same message as Log::kDynamicBufferSeal.
         LOG(UncheckedStringEvent("profiler", "pause"));
       }
+      --logging_nesting_;
     }
   }
   if (flags &
       (PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) {
     if (--heap_profiler_nesting_ == 0) {
       FLAG_log_gc = false;
+      --logging_nesting_;
     }
   }
   if (tag != 0) {
-    IntEvent("close-tag", tag);
-  }
-  if (GetActiveProfilerModules() == PROFILER_MODULE_NONE) {
-    is_logging_ = false;
+    UncheckedIntEvent("close-tag", tag);
   }
 }

@@ -1189,11 +1195,11 @@
 void Logger::ResumeProfiler(int flags, int tag) {
   if (!Log::IsEnabled()) return;
   if (tag != 0) {
-    IntEvent("open-tag", tag);
+    UncheckedIntEvent("open-tag", tag);
   }
   if (flags & PROFILER_MODULE_CPU) {
     if (cpu_profiler_nesting_++ == 0) {
-      is_logging_ = true;
+      ++logging_nesting_;
       if (FLAG_prof_lazy) {
         profiler_->Engage();
         LOG(UncheckedStringEvent("profiler", "resume"));
@@ -1209,7 +1215,7 @@
   if (flags &
       (PROFILER_MODULE_HEAP_STATS | PROFILER_MODULE_JS_CONSTRUCTORS)) {
     if (heap_profiler_nesting_++ == 0) {
-      is_logging_ = true;
+      ++logging_nesting_;
       FLAG_log_gc = true;
     }
   }
@@ -1482,14 +1488,16 @@
     compression_helper_ = new CompressionHelper(kCompressionWindowSize);
   }

-  is_logging_ = start_logging;
+  if (start_logging) {
+    logging_nesting_ = 1;
+  }

   if (FLAG_prof) {
     profiler_ = new Profiler();
     if (!FLAG_prof_auto) {
       profiler_->pause();
     } else {
-      is_logging_ = true;
+      logging_nesting_ = 1;
     }
     if (!FLAG_prof_lazy) {
       profiler_->Engage();
=======================================
--- /branches/bleeding_edge/src/log.h   Thu Feb 18 04:47:17 2010
+++ /branches/bleeding_edge/src/log.h   Mon Mar  1 02:41:34 2010
@@ -265,7 +265,7 @@
   }

   static bool is_logging() {
-    return is_logging_;
+    return logging_nesting_ > 0;
   }

   // Pause/Resume collection of profiling data.
@@ -330,6 +330,9 @@
   // Logs a StringEvent regardless of whether FLAG_log is true.
   static void UncheckedStringEvent(const char* name, const char* value);

+  // Logs an IntEvent regardless of whether FLAG_log is true.
+  static void UncheckedIntEvent(const char* name, int value);
+
   // Stops logging and profiling in case of insufficient resources.
   static void StopLoggingAndProfiling();

@@ -372,7 +375,7 @@

   friend class LoggerTestHelper;

-  static bool is_logging_;
+  static int logging_nesting_;
   static int cpu_profiler_nesting_;
   static int heap_profiler_nesting_;
 #else
=======================================
--- /branches/bleeding_edge/test/cctest/test-log.cc     Wed Feb 17 05:23:46 2010
+++ /branches/bleeding_edge/test/cctest/test-log.cc     Mon Mar  1 02:41:34 2010
@@ -174,12 +174,11 @@

 class ScopedLoggerInitializer {
  public:
-  explicit ScopedLoggerInitializer(bool log, bool prof_lazy)
-      : saved_log_(i::FLAG_log),
-        saved_prof_lazy_(i::FLAG_prof_lazy),
+  explicit ScopedLoggerInitializer(bool prof_lazy)
+      : saved_prof_lazy_(i::FLAG_prof_lazy),
         saved_prof_(i::FLAG_prof),
         saved_prof_auto_(i::FLAG_prof_auto),
-        trick_to_run_init_flags_(init_flags_(log, prof_lazy)),
+        trick_to_run_init_flags_(init_flags_(prof_lazy)),
         need_to_set_up_logger_(i::V8::IsRunning()),
         scope_(),
         env_(v8::Context::New()) {
@@ -193,14 +192,12 @@
     i::FLAG_prof_lazy = saved_prof_lazy_;
     i::FLAG_prof = saved_prof_;
     i::FLAG_prof_auto = saved_prof_auto_;
-    i::FLAG_log = saved_log_;
   }

   v8::Handle<v8::Context>& env() { return env_; }

  private:
-  static bool init_flags_(bool log, bool prof_lazy) {
-    i::FLAG_log = log;
+  static bool init_flags_(bool prof_lazy) {
     i::FLAG_prof = true;
     i::FLAG_prof_lazy = prof_lazy;
     i::FLAG_prof_auto = false;
@@ -208,7 +205,6 @@
     return prof_lazy;
   }

-  const bool saved_log_;
   const bool saved_prof_lazy_;
   const bool saved_prof_;
   const bool saved_prof_auto_;
@@ -320,7 +316,7 @@


 TEST(ProfLazyMode) {
-  ScopedLoggerInitializer initialize_logger(false, true);
+  ScopedLoggerInitializer initialize_logger(true);

   // No sampling should happen prior to resuming profiler.
   CHECK(!LoggerTestHelper::IsSamplerActive());
@@ -540,7 +536,7 @@
 }

 TEST(LogCallbacks) {
-  ScopedLoggerInitializer initialize_logger(false, false);
+  ScopedLoggerInitializer initialize_logger(false);
   LogBufferMatcher matcher;

   v8::Persistent<v8::FunctionTemplate> obj =
@@ -590,7 +586,7 @@
 }

 TEST(LogAccessorCallbacks) {
-  ScopedLoggerInitializer initialize_logger(false, false);
+  ScopedLoggerInitializer initialize_logger(false);
   LogBufferMatcher matcher;

   v8::Persistent<v8::FunctionTemplate> obj =
@@ -625,7 +621,7 @@


 TEST(LogTags) {
-  ScopedLoggerInitializer initialize_logger(true, false);
+  ScopedLoggerInitializer initialize_logger(false);
   LogBufferMatcher matcher;

   const char* open_tag = "open-tag,";
@@ -708,6 +704,35 @@
   CHECK_EQ(NULL, matcher.Find(open_tag3));
   CHECK_EQ(NULL, matcher.Find(close_tag3));
 }
+
+
+TEST(IsLoggingPreserved) {
+  ScopedLoggerInitializer initialize_logger(false);
+
+  CHECK(Logger::is_logging());
+  Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 1);
+  CHECK(Logger::is_logging());
+  Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 1);
+  CHECK(Logger::is_logging());
+
+  CHECK(Logger::is_logging());
+  Logger::ResumeProfiler(
+ v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
+  CHECK(Logger::is_logging());
+  Logger::PauseProfiler(
+ v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
+  CHECK(Logger::is_logging());
+
+  CHECK(Logger::is_logging());
+  Logger::ResumeProfiler(
+      v8::PROFILER_MODULE_CPU |
+ v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
+  CHECK(Logger::is_logging());
+  Logger::PauseProfiler(
+      v8::PROFILER_MODULE_CPU |
+ v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
+  CHECK(Logger::is_logging());
+}


 static inline bool IsStringEqualTo(const char* r, const char* s) {

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

Reply via email to