| 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..6479908e62c2ce4d8be18a13477d6a96078be7e9 100644
|
| --- a/webrtc/call/rtc_event_log_helper_thread.cc
|
| +++ b/webrtc/call/rtc_event_log_helper_thread.cc
|
| @@ -35,8 +35,6 @@ bool IsConfigEvent(const rtclog::Event& event) {
|
| RtcEventLogHelperThread::RtcEventLogHelperThread(
|
| SwapQueue<ControlMessage>* message_queue,
|
| SwapQueue<std::unique_ptr<rtclog::Event>>* event_queue,
|
| - rtc::Event* wake_up,
|
| - rtc::Event* stopped,
|
| const Clock* const clock)
|
| : message_queue_(message_queue),
|
| event_queue_(event_queue),
|
| @@ -51,13 +49,12 @@ RtcEventLogHelperThread::RtcEventLogHelperThread(
|
| has_recent_event_(false),
|
| most_recent_event_(),
|
| output_string_(),
|
| - wake_up_(wake_up),
|
| - stopped_(stopped),
|
| + wake_periodically_(false, false),
|
| + wake_from_hibernation_(false, false),
|
| + file_finished_(false, false),
|
| clock_(clock) {
|
| RTC_DCHECK(message_queue_);
|
| RTC_DCHECK(event_queue_);
|
| - RTC_DCHECK(wake_up_);
|
| - RTC_DCHECK(stopped_);
|
| RTC_DCHECK(clock_);
|
| thread_.Start();
|
| }
|
| @@ -75,10 +72,21 @@ RtcEventLogHelperThread::~RtcEventLogHelperThread() {
|
| LOG(LS_WARNING) << "Clearing message queue to terminate thread.";
|
| message_queue_->Clear();
|
| }
|
| - wake_up_->Set(); // Wake up the output thread.
|
| + wake_from_hibernation_.Set();
|
| + wake_periodically_.Set(); // Wake up the output thread.
|
| thread_.Stop(); // Wait for the thread to terminate.
|
| }
|
|
|
| +void RtcEventLogHelperThread::WaitForFileFinished() {
|
| + wake_from_hibernation_.Set();
|
| + wake_periodically_.Set();
|
| + file_finished_.Wait(rtc::Event::kForever);
|
| +}
|
| +
|
| +void RtcEventLogHelperThread::SignalNewEvent() {
|
| + wake_from_hibernation_.Set();
|
| +}
|
| +
|
| bool RtcEventLogHelperThread::AppendEventToString(rtclog::Event* event) {
|
| rtclog::EventStream event_stream;
|
| event_stream.add_stream();
|
| @@ -98,8 +106,9 @@ bool RtcEventLogHelperThread::AppendEventToString(rtclog::Event* event) {
|
| return stop;
|
| }
|
|
|
| -void RtcEventLogHelperThread::LogToMemory() {
|
| +bool RtcEventLogHelperThread::LogToMemory() {
|
| RTC_DCHECK(!file_->Open());
|
| + bool message_received = false;
|
|
|
| // Process each event earlier than the current time and append it to the
|
| // appropriate history_.
|
| @@ -115,7 +124,9 @@ void RtcEventLogHelperThread::LogToMemory() {
|
| history_.push_back(std::move(most_recent_event_));
|
| }
|
| has_recent_event_ = event_queue_->Remove(&most_recent_event_);
|
| + message_received = true;
|
| }
|
| + return message_received;
|
| }
|
|
|
| void RtcEventLogHelperThread::StartLogFile() {
|
| @@ -162,9 +173,10 @@ void RtcEventLogHelperThread::StartLogFile() {
|
| }
|
| }
|
|
|
| -void RtcEventLogHelperThread::LogToFile() {
|
| +bool RtcEventLogHelperThread::LogToFile() {
|
| RTC_DCHECK(file_->Open());
|
| output_string_.clear();
|
| + bool message_received = false;
|
|
|
| // Append each event older than both the current time and the stop time
|
| // to the output_string_.
|
| @@ -183,6 +195,7 @@ void RtcEventLogHelperThread::LogToFile() {
|
| }
|
| has_recent_event_ = event_queue_->Remove(&most_recent_event_);
|
| }
|
| + message_received = true;
|
| }
|
|
|
| // Write string to file.
|
| @@ -190,7 +203,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 +216,7 @@ void RtcEventLogHelperThread::LogToFile() {
|
| RTC_DCHECK(file_->Open());
|
| StopLogFile();
|
| }
|
| + return message_received;
|
| }
|
|
|
| void RtcEventLogHelperThread::StopLogFile() {
|
| @@ -233,10 +247,11 @@ void RtcEventLogHelperThread::StopLogFile() {
|
| RTC_DCHECK(!file_->Open());
|
| }
|
|
|
| -void RtcEventLogHelperThread::WriteLog() {
|
| +void RtcEventLogHelperThread::ProcessEvents() {
|
| ControlMessage message;
|
|
|
| while (true) {
|
| + bool message_received = false;
|
| // Process control messages.
|
| while (message_queue_->Remove(&message)) {
|
| switch (message.message_type) {
|
| @@ -251,6 +266,7 @@ void RtcEventLogHelperThread::WriteLog() {
|
| // Already started. Ignore message and close file handle.
|
| message.file->CloseFile();
|
| }
|
| + message_received = true;
|
| break;
|
| case ControlMessage::STOP_FILE:
|
| if (file_->Open()) {
|
| @@ -261,7 +277,8 @@ void RtcEventLogHelperThread::WriteLog() {
|
| if (file_->Open()) {
|
| StopLogFile();
|
| }
|
| - stopped_->Set();
|
| + file_finished_.Set();
|
| + message_received = true;
|
| break;
|
| case ControlMessage::TERMINATE_THREAD:
|
| if (file_->Open()) {
|
| @@ -271,22 +288,26 @@ void RtcEventLogHelperThread::WriteLog() {
|
| }
|
| }
|
|
|
| - // Write events to file or memory
|
| + // 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) {
|
| + wake_periodically_.Wait(100);
|
| + } else {
|
| + wake_from_hibernation_.Wait(rtc::Event::kForever);
|
| + }
|
| }
|
| }
|
|
|
| bool RtcEventLogHelperThread::ThreadOutputFunction(void* obj) {
|
| RtcEventLogHelperThread* helper = static_cast<RtcEventLogHelperThread*>(obj);
|
| - helper->WriteLog();
|
| + helper->ProcessEvents();
|
| return false;
|
| }
|
|
|
|
|