Fixing a few bugs to make the --log-state-change option work.
authorolehougaard <olehougaard@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 11 Feb 2009 07:38:31 +0000 (07:38 +0000)
committerolehougaard <olehougaard@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 11 Feb 2009 07:38:31 +0000 (07:38 +0000)
Review URL: http://codereview.chromium.org/20220

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1247 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/log.cc
src/log.h

index 5d035ed53ff4cb6ae355eba349382d327748635c..c0aa28bd34c14e328fbdcb2de18f341c345045b7 100644 (file)
@@ -226,7 +226,7 @@ void Profiler::Engage() {
   // Register to get ticks.
   Logger::ticker_->SetProfiler(this);
 
-  LOG(StringEvent("profiler", "begin"));
+  LOG(UncheckedStringEvent("profiler", "begin"));
 }
 
 
@@ -245,7 +245,7 @@ void Profiler::Disengage() {
   Insert(&sample);
   Join();
 
-  LOG(StringEvent("profiler", "end"));
+  LOG(UncheckedStringEvent("profiler", "end"));
 }
 
 
@@ -282,11 +282,18 @@ void Logger::Preamble(const char* content) {
 
 void Logger::StringEvent(const char* name, const char* value) {
 #ifdef ENABLE_LOGGING_AND_PROFILING
-  if (logfile_ == NULL || !FLAG_log) return;
+  if (FLAG_log) UncheckedStringEvent(name, value);
+#endif
+}
+
+
+#ifdef ENABLE_LOGGING_AND_PROFILING
+void Logger::UncheckedStringEvent(const char* name, const char* value) {
+  if (logfile_ == NULL) return;
   ScopedLock sl(mutex_);
   fprintf(logfile_, "%s,\"%s\"\n", name, value);
-#endif
 }
+#endif
 
 
 void Logger::IntEvent(const char* name, int value) {
@@ -808,7 +815,7 @@ bool Logger::Setup() {
 
   bool open_log_file = FLAG_log || FLAG_log_api || FLAG_log_code
       || FLAG_log_gc || FLAG_log_handles || FLAG_log_suspect
-      || FLAG_log_regexp;
+      || FLAG_log_regexp || FLAG_log_state_changes;
 
   // If we're logging anything, we need to open the log file.
   if (open_log_file) {
@@ -931,6 +938,8 @@ void Logger::EnableSlidingStateWindow() {
 #ifdef ENABLE_LOGGING_AND_PROFILING
 static const char* StateToString(StateTag state) {
   switch (state) {
+    case JS:
+      return "JS";
     case GC:
       return "GC";
     case COMPILER:
@@ -949,9 +958,9 @@ VMState::VMState(StateTag state) {
   Logger::current_state_ = this;
 
   if (FLAG_log_state_changes) {
-    LOG(StringEvent("Entering", StateToString(state_)));
+    LOG(UncheckedStringEvent("Entering", StateToString(state_)));
     if (previous_) {
-      LOG(StringEvent("From", StateToString(previous_->state_)));
+      LOG(UncheckedStringEvent("From", StateToString(previous_->state_)));
     }
   }
 }
@@ -961,9 +970,9 @@ VMState::~VMState() {
   Logger::current_state_ = previous_;
 
   if (FLAG_log_state_changes) {
-    LOG(StringEvent("Leaving", StateToString(state_)));
+    LOG(UncheckedStringEvent("Leaving", StateToString(state_)));
     if (previous_) {
-      LOG(StringEvent("To", StateToString(previous_->state_)));
+      LOG(UncheckedStringEvent("To", StateToString(previous_->state_)));
     }
   }
 }
index 3da22f8dd73ce20c5bef562488f477fb0ef40de9..23996911b951a8dbbb6b1d6131ed269da4d72848 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -224,6 +224,9 @@ class Logger {
 
   static void ApiEvent(const char* name, ...);
 
+  // Logs a StringEvent regardless of whether FLAG_log is true.
+  static void UncheckedStringEvent(const char* name, const char* value);
+
   // When logging is active, logfile_ refers the file
   // events are written to.
   static FILE* logfile_;