Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: webrtc/logging/rtc_event_log/rtc_event_log.cc

Issue 2956003003: Limit the number of simultaneous event logs. (Closed)
Patch Set: Make private Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 void LogAudioNetworkAdaptation( 84 void LogAudioNetworkAdaptation(
85 const AudioEncoderRuntimeConfig& config) override; 85 const AudioEncoderRuntimeConfig& config) override;
86 void LogProbeClusterCreated(int id, 86 void LogProbeClusterCreated(int id,
87 int bitrate_bps, 87 int bitrate_bps,
88 int min_probes, 88 int min_probes,
89 int min_bytes) override; 89 int min_bytes) override;
90 void LogProbeResultSuccess(int id, int bitrate_bps) override; 90 void LogProbeResultSuccess(int id, int bitrate_bps) override;
91 void LogProbeResultFailure(int id, 91 void LogProbeResultFailure(int id,
92 ProbeFailureReason failure_reason) override; 92 ProbeFailureReason failure_reason) override;
93 93
94 static bool AllowNewEventLog();
95
94 private: 96 private:
95 void StoreEvent(std::unique_ptr<rtclog::Event>* event); 97 void StoreEvent(std::unique_ptr<rtclog::Event>* event);
96 void LogProbeResult(int id, 98 void LogProbeResult(int id,
97 rtclog::BweProbeResult::ResultType result, 99 rtclog::BweProbeResult::ResultType result,
98 int bitrate_bps); 100 int bitrate_bps);
99 101
102 static rtc::CriticalSection crit_;
tommi 2017/06/27 17:35:19 this is a complex global == cl will get reverted r
103 static int log_count GUARDED_BY(crit_);
104
100 // Message queue for passing control messages to the logging thread. 105 // Message queue for passing control messages to the logging thread.
101 SwapQueue<RtcEventLogHelperThread::ControlMessage> message_queue_; 106 SwapQueue<RtcEventLogHelperThread::ControlMessage> message_queue_;
102 107
103 // Message queue for passing events to the logging thread. 108 // Message queue for passing events to the logging thread.
104 SwapQueue<std::unique_ptr<rtclog::Event> > event_queue_; 109 SwapQueue<std::unique_ptr<rtclog::Event> > event_queue_;
105 110
106 RtcEventLogHelperThread helper_thread_; 111 RtcEventLogHelperThread helper_thread_;
107 rtc::ThreadChecker thread_checker_; 112 rtc::ThreadChecker thread_checker_;
108 113
109 RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogImpl); 114 RTC_DISALLOW_COPY_AND_ASSIGN(RtcEventLogImpl);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 RTC_NOTREACHED(); 160 RTC_NOTREACHED();
156 return rtclog::BweProbeResult::SUCCESS; 161 return rtclog::BweProbeResult::SUCCESS;
157 } 162 }
158 163
159 // The RTP and RTCP buffers reserve space for twice the expected number of 164 // The RTP and RTCP buffers reserve space for twice the expected number of
160 // sent packets because they also contain received packets. 165 // sent packets because they also contain received packets.
161 static const int kEventsPerSecond = 1000; 166 static const int kEventsPerSecond = 1000;
162 static const int kControlMessagesPerSecond = 10; 167 static const int kControlMessagesPerSecond = 10;
163 } // namespace 168 } // namespace
164 169
170 rtc::CriticalSection RtcEventLogImpl::crit_;
171 int RtcEventLogImpl::log_count = 0;
tommi 2017/06/27 17:35:19 log_count is missing the postfix _ actually... sin
172
165 // RtcEventLogImpl member functions. 173 // RtcEventLogImpl member functions.
166 RtcEventLogImpl::RtcEventLogImpl() 174 RtcEventLogImpl::RtcEventLogImpl()
167 // Allocate buffers for roughly one second of history. 175 // Allocate buffers for roughly one second of history.
168 : message_queue_(kControlMessagesPerSecond), 176 : message_queue_(kControlMessagesPerSecond),
169 event_queue_(kEventsPerSecond), 177 event_queue_(kEventsPerSecond),
170 helper_thread_(&message_queue_, &event_queue_), 178 helper_thread_(&message_queue_, &event_queue_),
171 thread_checker_() { 179 thread_checker_() {
172 thread_checker_.DetachFromThread(); 180 thread_checker_.DetachFromThread();
181 rtc::CritScope lock(&crit_);
182 log_count++;
183 RTC_DCHECK_GE(log_count, 1);
173 } 184 }
174 185
175 RtcEventLogImpl::~RtcEventLogImpl() { 186 RtcEventLogImpl::~RtcEventLogImpl() {
176 // The RtcEventLogHelperThread destructor closes the file 187 // The RtcEventLogHelperThread destructor closes the file
177 // and waits for the thread to terminate. 188 // and waits for the thread to terminate.
189 rtc::CritScope lock(&crit_);
190 log_count--;
191 RTC_DCHECK_GE(log_count, 0);
178 } 192 }
179 193
180 bool RtcEventLogImpl::StartLogging(const std::string& file_name, 194 bool RtcEventLogImpl::StartLogging(const std::string& file_name,
181 int64_t max_size_bytes) { 195 int64_t max_size_bytes) {
182 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 196 RTC_DCHECK(thread_checker_.CalledOnValidThread());
183 RtcEventLogHelperThread::ControlMessage message; 197 RtcEventLogHelperThread::ControlMessage message;
184 message.message_type = RtcEventLogHelperThread::ControlMessage::START_FILE; 198 message.message_type = RtcEventLogHelperThread::ControlMessage::START_FILE;
185 message.max_size_bytes = max_size_bytes <= 0 199 message.max_size_bytes = max_size_bytes <= 0
186 ? std::numeric_limits<int64_t>::max() 200 ? std::numeric_limits<int64_t>::max()
187 : max_size_bytes; 201 : max_size_bytes;
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 569
556 void RtcEventLogImpl::StoreEvent(std::unique_ptr<rtclog::Event>* event) { 570 void RtcEventLogImpl::StoreEvent(std::unique_ptr<rtclog::Event>* event) {
557 RTC_DCHECK(event != nullptr); 571 RTC_DCHECK(event != nullptr);
558 RTC_DCHECK(event->get() != nullptr); 572 RTC_DCHECK(event->get() != nullptr);
559 if (!event_queue_.Insert(event)) { 573 if (!event_queue_.Insert(event)) {
560 LOG(LS_ERROR) << "WebRTC event log queue full. Dropping event."; 574 LOG(LS_ERROR) << "WebRTC event log queue full. Dropping event.";
561 } 575 }
562 helper_thread_.SignalNewEvent(); 576 helper_thread_.SignalNewEvent();
563 } 577 }
564 578
579 bool RtcEventLogImpl::AllowNewEventLog() {
580 constexpr int kMaxLogCount = 5;
581 rtc::CritScope lock(&crit_);
582 if (log_count < kMaxLogCount)
583 return true;
584 LOG(LS_WARNING) << "Denied creation of additional WebRTC event logs. "
tommi 2017/06/27 17:35:19 there isn't a need to make this call while holding
585 << log_count << " logs open already.";
586 return false;
587 }
588
565 bool RtcEventLog::ParseRtcEventLog(const std::string& file_name, 589 bool RtcEventLog::ParseRtcEventLog(const std::string& file_name,
566 rtclog::EventStream* result) { 590 rtclog::EventStream* result) {
567 char tmp_buffer[1024]; 591 char tmp_buffer[1024];
568 int bytes_read = 0; 592 int bytes_read = 0;
569 std::unique_ptr<FileWrapper> dump_file(FileWrapper::Create()); 593 std::unique_ptr<FileWrapper> dump_file(FileWrapper::Create());
570 if (!dump_file->OpenFile(file_name.c_str(), true)) { 594 if (!dump_file->OpenFile(file_name.c_str(), true)) {
571 return false; 595 return false;
572 } 596 }
573 ProtoString dump_buffer; 597 ProtoString dump_buffer;
574 while ((bytes_read = dump_file->Read(tmp_buffer, sizeof(tmp_buffer))) > 0) { 598 while ((bytes_read = dump_file->Read(tmp_buffer, sizeof(tmp_buffer))) > 0) {
575 dump_buffer.append(tmp_buffer, bytes_read); 599 dump_buffer.append(tmp_buffer, bytes_read);
576 } 600 }
577 dump_file->CloseFile(); 601 dump_file->CloseFile();
578 return result->ParseFromString(dump_buffer); 602 return result->ParseFromString(dump_buffer);
579 } 603 }
580 604
581 #endif // ENABLE_RTC_EVENT_LOG 605 #endif // ENABLE_RTC_EVENT_LOG
582 606
583 // RtcEventLog member functions. 607 // RtcEventLog member functions.
584 std::unique_ptr<RtcEventLog> RtcEventLog::Create() { 608 std::unique_ptr<RtcEventLog> RtcEventLog::Create() {
585 #ifdef ENABLE_RTC_EVENT_LOG 609 #ifdef ENABLE_RTC_EVENT_LOG
586 return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl()); 610 if (RtcEventLogImpl::AllowNewEventLog()) {
tommi 2017/06/27 17:35:19 instead of this approach, what about something lik
611 // Note that there is a gap between checking the log count and creating a
612 // new log. Hence it is theoretically possible to create more than
613 // kMaxLogCount logs if multiple thread check the log count simultaneously,
614 // This is unlikely to happen in practice, and not harmful if it does since
615 // we don't care about the exact value of kMaxLogCount. The purpose is just
616 // to avoid creating too many logging threads.
617 return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl());
618 } else {
tommi 2017/06/27 17:35:19 no need for 'else' since the previous conditional
619 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl());
620 }
587 #else 621 #else
588 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); 622 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl());
589 #endif // ENABLE_RTC_EVENT_LOG 623 #endif // ENABLE_RTC_EVENT_LOG
590 } 624 }
591 625
592 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() { 626 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() {
593 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); 627 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl());
594 } 628 }
595 629
596 } // namespace webrtc 630 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698