Index: src/log.cc |
diff --git a/src/log.cc b/src/log.cc |
index e149fdb17a89ba80071bf76ee238df3e1159a7fc..14d1f00993d1af986760e8eab217154eb9543cae 100644 |
--- a/src/log.cc |
+++ b/src/log.cc |
@@ -813,12 +813,14 @@ void Logger::PauseProfiler() { |
if (FLAG_prof_lazy) { |
if (!FLAG_sliding_state_window) ticker_->Stop(); |
FLAG_log_code = false; |
+ // Must be the same message as Log::kDynamicBufferSeal. |
LOG(UncheckedStringEvent("profiler", "pause")); |
} |
} |
void Logger::ResumeProfiler() { |
+ if (!Log::IsEnabled()) return; |
if (FLAG_prof_lazy) { |
LOG(UncheckedStringEvent("profiler", "resume")); |
FLAG_log_code = true; |
@@ -829,6 +831,14 @@ void Logger::ResumeProfiler() { |
} |
+// This function can be called when Log's mutex is acquired, |
+// either from main or Profiler's thread. |
+void Logger::StopLoggingAndProfiling() { |
+ Log::stop(); |
+ PauseProfiler(); |
+} |
+ |
+ |
bool Logger::IsProfilerSamplerActive() { |
return ticker_->IsActive(); |
} |
@@ -995,6 +1005,8 @@ bool Logger::Setup() { |
profiler_->Engage(); |
} |
+ LogMessageBuilder::write_failure_handler = StopLoggingAndProfiling; |
+ |
return true; |
#else |
@@ -1005,6 +1017,8 @@ bool Logger::Setup() { |
void Logger::TearDown() { |
#ifdef ENABLE_LOGGING_AND_PROFILING |
+ LogMessageBuilder::write_failure_handler = NULL; |
+ |
// Stop the profiler before closing the file. |
if (profiler_ != NULL) { |
profiler_->Disengage(); |