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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/logging/rtc_event_log/rtc_event_log.cc
diff --git a/webrtc/logging/rtc_event_log/rtc_event_log.cc b/webrtc/logging/rtc_event_log/rtc_event_log.cc
index 0c2b15d13c0407c78a25a2fc3ac8a5e409025a64..95c085d39b3df518c4dc79a956244101d454d7c4 100644
--- a/webrtc/logging/rtc_event_log/rtc_event_log.cc
+++ b/webrtc/logging/rtc_event_log/rtc_event_log.cc
@@ -91,12 +91,17 @@ class RtcEventLogImpl final : public RtcEventLog {
void LogProbeResultFailure(int id,
ProbeFailureReason failure_reason) override;
+ static bool AllowNewEventLog();
+
private:
void StoreEvent(std::unique_ptr<rtclog::Event>* event);
void LogProbeResult(int id,
rtclog::BweProbeResult::ResultType result,
int bitrate_bps);
+ static rtc::CriticalSection crit_;
tommi 2017/06/27 17:35:19 this is a complex global == cl will get reverted r
+ static int log_count GUARDED_BY(crit_);
+
// Message queue for passing control messages to the logging thread.
SwapQueue<RtcEventLogHelperThread::ControlMessage> message_queue_;
@@ -162,6 +167,9 @@ static const int kEventsPerSecond = 1000;
static const int kControlMessagesPerSecond = 10;
} // namespace
+rtc::CriticalSection RtcEventLogImpl::crit_;
+int RtcEventLogImpl::log_count = 0;
tommi 2017/06/27 17:35:19 log_count is missing the postfix _ actually... sin
+
// RtcEventLogImpl member functions.
RtcEventLogImpl::RtcEventLogImpl()
// Allocate buffers for roughly one second of history.
@@ -170,11 +178,17 @@ RtcEventLogImpl::RtcEventLogImpl()
helper_thread_(&message_queue_, &event_queue_),
thread_checker_() {
thread_checker_.DetachFromThread();
+ rtc::CritScope lock(&crit_);
+ log_count++;
+ RTC_DCHECK_GE(log_count, 1);
}
RtcEventLogImpl::~RtcEventLogImpl() {
// The RtcEventLogHelperThread destructor closes the file
// and waits for the thread to terminate.
+ rtc::CritScope lock(&crit_);
+ log_count--;
+ RTC_DCHECK_GE(log_count, 0);
}
bool RtcEventLogImpl::StartLogging(const std::string& file_name,
@@ -562,6 +576,16 @@ void RtcEventLogImpl::StoreEvent(std::unique_ptr<rtclog::Event>* event) {
helper_thread_.SignalNewEvent();
}
+bool RtcEventLogImpl::AllowNewEventLog() {
+ constexpr int kMaxLogCount = 5;
+ rtc::CritScope lock(&crit_);
+ if (log_count < kMaxLogCount)
+ return true;
+ 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
+ << log_count << " logs open already.";
+ return false;
+}
+
bool RtcEventLog::ParseRtcEventLog(const std::string& file_name,
rtclog::EventStream* result) {
char tmp_buffer[1024];
@@ -583,7 +607,17 @@ bool RtcEventLog::ParseRtcEventLog(const std::string& file_name,
// RtcEventLog member functions.
std::unique_ptr<RtcEventLog> RtcEventLog::Create() {
#ifdef ENABLE_RTC_EVENT_LOG
- return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl());
+ if (RtcEventLogImpl::AllowNewEventLog()) {
tommi 2017/06/27 17:35:19 instead of this approach, what about something lik
+ // Note that there is a gap between checking the log count and creating a
+ // new log. Hence it is theoretically possible to create more than
+ // kMaxLogCount logs if multiple thread check the log count simultaneously,
+ // This is unlikely to happen in practice, and not harmful if it does since
+ // we don't care about the exact value of kMaxLogCount. The purpose is just
+ // to avoid creating too many logging threads.
+ return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl());
+ } else {
tommi 2017/06/27 17:35:19 no need for 'else' since the previous conditional
+ return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl());
+ }
#else
return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl());
#endif // ENABLE_RTC_EVENT_LOG
« 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