Chromium Code Reviews| Index: webrtc/call/rtc_event_log_helper_thread.cc |
| diff --git a/webrtc/call/rtc_event_log_helper_thread.cc b/webrtc/call/rtc_event_log_helper_thread.cc |
| index 93343129a1734d68b3179db049e9fdcbf5777a0b..a6574f3da445e7630fb17e3828a6bc9db52b0280 100644 |
| --- a/webrtc/call/rtc_event_log_helper_thread.cc |
| +++ b/webrtc/call/rtc_event_log_helper_thread.cc |
| @@ -36,6 +36,7 @@ RtcEventLogHelperThread::RtcEventLogHelperThread( |
| SwapQueue<ControlMessage>* message_queue, |
| SwapQueue<std::unique_ptr<rtclog::Event>>* event_queue, |
| rtc::Event* wake_up, |
| + rtc::Event* end_hibernation, |
| rtc::Event* stopped, |
| const Clock* const clock) |
| : message_queue_(message_queue), |
| @@ -52,11 +53,13 @@ RtcEventLogHelperThread::RtcEventLogHelperThread( |
| most_recent_event_(), |
| output_string_(), |
| wake_up_(wake_up), |
| + end_hibernation_(end_hibernation), |
| stopped_(stopped), |
| clock_(clock) { |
| RTC_DCHECK(message_queue_); |
| RTC_DCHECK(event_queue_); |
| RTC_DCHECK(wake_up_); |
| + RTC_DCHECK(end_hibernation_); |
| RTC_DCHECK(stopped_); |
| RTC_DCHECK(clock_); |
| thread_.Start(); |
| @@ -75,6 +78,7 @@ RtcEventLogHelperThread::~RtcEventLogHelperThread() { |
| LOG(LS_WARNING) << "Clearing message queue to terminate thread."; |
| message_queue_->Clear(); |
| } |
| + end_hibernation_->Set(); |
| wake_up_->Set(); // Wake up the output thread. |
| thread_.Stop(); // Wait for the thread to terminate. |
| } |
| @@ -98,8 +102,9 @@ bool RtcEventLogHelperThread::AppendEventToString(rtclog::Event* event) { |
| return stop; |
| } |
| -void RtcEventLogHelperThread::LogToMemory() { |
| +int RtcEventLogHelperThread::LogToMemory() { |
| RTC_DCHECK(!file_->Open()); |
| + int message_received = 0; |
| // Process each event earlier than the current time and append it to the |
| // appropriate history_. |
| @@ -115,7 +120,9 @@ void RtcEventLogHelperThread::LogToMemory() { |
| history_.push_back(std::move(most_recent_event_)); |
| } |
| has_recent_event_ = event_queue_->Remove(&most_recent_event_); |
| + message_received++; |
|
stefan-webrtc
2016/06/03 08:55:44
++message_received;
terelius
2016/06/08 11:47:29
Done.
|
| } |
| + return message_received; |
| } |
| void RtcEventLogHelperThread::StartLogFile() { |
| @@ -162,9 +169,10 @@ void RtcEventLogHelperThread::StartLogFile() { |
| } |
| } |
| -void RtcEventLogHelperThread::LogToFile() { |
| +int RtcEventLogHelperThread::LogToFile() { |
| RTC_DCHECK(file_->Open()); |
| output_string_.clear(); |
| + int message_received = 0; |
| // Append each event older than both the current time and the stop time |
| // to the output_string_. |
| @@ -183,6 +191,7 @@ void RtcEventLogHelperThread::LogToFile() { |
| } |
| has_recent_event_ = event_queue_->Remove(&most_recent_event_); |
| } |
| + message_received++; |
|
stefan-webrtc
2016/06/03 08:55:44
++...;
terelius
2016/06/08 11:47:29
Done.
|
| } |
| // Write string to file. |
| @@ -190,7 +199,7 @@ void RtcEventLogHelperThread::LogToFile() { |
| LOG(LS_ERROR) << "FileWrapper failed to write WebRtcEventLog file."; |
| // The current FileWrapper implementation closes the file on error. |
| RTC_DCHECK(!file_->Open()); |
| - return; |
| + return message_received; |
| } |
| written_bytes_ += output_string_.size(); |
| @@ -203,6 +212,7 @@ void RtcEventLogHelperThread::LogToFile() { |
| RTC_DCHECK(file_->Open()); |
| StopLogFile(); |
| } |
| + return message_received; |
| } |
| void RtcEventLogHelperThread::StopLogFile() { |
| @@ -233,10 +243,12 @@ void RtcEventLogHelperThread::StopLogFile() { |
| RTC_DCHECK(!file_->Open()); |
| } |
| -void RtcEventLogHelperThread::WriteLog() { |
| +void RtcEventLogHelperThread::ProcessEvents() { |
| ControlMessage message; |
| + int message_received; // Non-zero if we find new events in the queues. |
| while (true) { |
| + message_received = 0; |
| // Process control messages. |
| while (message_queue_->Remove(&message)) { |
| switch (message.message_type) { |
| @@ -251,6 +263,7 @@ void RtcEventLogHelperThread::WriteLog() { |
| // Already started. Ignore message and close file handle. |
| message.file->CloseFile(); |
| } |
| + message_received = 1; |
| break; |
| case ControlMessage::STOP_FILE: |
| if (file_->Open()) { |
| @@ -262,6 +275,7 @@ void RtcEventLogHelperThread::WriteLog() { |
| StopLogFile(); |
| } |
| stopped_->Set(); |
| + message_received = 1; |
| break; |
| case ControlMessage::TERMINATE_THREAD: |
| if (file_->Open()) { |
| @@ -273,20 +287,24 @@ void RtcEventLogHelperThread::WriteLog() { |
| // Write events to file or memory |
| if (file_->Open()) { |
| - LogToFile(); |
| + message_received += LogToFile(); |
| } else { |
| - LogToMemory(); |
| + message_received += LogToMemory(); |
| } |
| // Accumulate a new batch of events instead of processing them one at a |
| // time. |
| - wake_up_->Wait(50); |
| + if (message_received > 0) { |
| + wake_up_->Wait(100); |
| + } else { |
| + end_hibernation_->Wait(rtc::Event::kForever); |
| + } |
| } |
| } |
| bool RtcEventLogHelperThread::ThreadOutputFunction(void* obj) { |
| RtcEventLogHelperThread* helper = static_cast<RtcEventLogHelperThread*>(obj); |
| - helper->WriteLog(); |
| + helper->ProcessEvents(); |
| return false; |
| } |