| OLD | NEW |
| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 const int kEventsInHistory = 10000; | 65 const int kEventsInHistory = 10000; |
| 66 | 66 |
| 67 bool IsConfigEvent(const rtclog::Event& event) { | 67 bool IsConfigEvent(const rtclog::Event& event) { |
| 68 rtclog::Event_EventType event_type = event.type(); | 68 rtclog::Event_EventType event_type = event.type(); |
| 69 return event_type == rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT || | 69 return event_type == rtclog::Event::VIDEO_RECEIVER_CONFIG_EVENT || |
| 70 event_type == rtclog::Event::VIDEO_SENDER_CONFIG_EVENT || | 70 event_type == rtclog::Event::VIDEO_SENDER_CONFIG_EVENT || |
| 71 event_type == rtclog::Event::AUDIO_RECEIVER_CONFIG_EVENT || | 71 event_type == rtclog::Event::AUDIO_RECEIVER_CONFIG_EVENT || |
| 72 event_type == rtclog::Event::AUDIO_SENDER_CONFIG_EVENT; | 72 event_type == rtclog::Event::AUDIO_SENDER_CONFIG_EVENT; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Observe a limit on the number of concurrent logs, so as not to run into |
| 76 // OS-imposed limits on open files and/or threads/task-queues. |
| 77 // TODO(eladalon): Known issue - there's a race over |rtc_event_log_count|. |
| 78 std::atomic<int> rtc_event_log_count(0); |
| 79 |
| 75 // TODO(eladalon): This class exists because C++11 doesn't allow transferring a | 80 // TODO(eladalon): This class exists because C++11 doesn't allow transferring a |
| 76 // unique_ptr to a lambda (a copy constructor is required). We should get | 81 // unique_ptr to a lambda (a copy constructor is required). We should get |
| 77 // rid of this when we move to C++14. | 82 // rid of this when we move to C++14. |
| 78 template <typename T> | 83 template <typename T> |
| 79 class ResourceOwningTask final : public rtc::QueuedTask { | 84 class ResourceOwningTask final : public rtc::QueuedTask { |
| 80 public: | 85 public: |
| 81 ResourceOwningTask(std::unique_ptr<T> resource, | 86 ResourceOwningTask(std::unique_ptr<T> resource, |
| 82 std::function<void(std::unique_ptr<T>)> handler) | 87 std::function<void(std::unique_ptr<T>)> handler) |
| 83 : resource_(std::move(resource)), handler_(handler) {} | 88 : resource_(std::move(resource)), handler_(handler) {} |
| 84 | 89 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // event from being added; in this case, the output string is left unchanged. | 155 // event from being added; in this case, the output string is left unchanged. |
| 151 bool AppendEventToString(rtclog::Event* event, | 156 bool AppendEventToString(rtclog::Event* event, |
| 152 ProtoString* output_string) RTC_WARN_UNUSED_RESULT; | 157 ProtoString* output_string) RTC_WARN_UNUSED_RESULT; |
| 153 | 158 |
| 154 void LogToMemory(std::unique_ptr<rtclog::Event> event); | 159 void LogToMemory(std::unique_ptr<rtclog::Event> event); |
| 155 | 160 |
| 156 void StartLogFile(); | 161 void StartLogFile(); |
| 157 void LogToFile(std::unique_ptr<rtclog::Event> event); | 162 void LogToFile(std::unique_ptr<rtclog::Event> event); |
| 158 void StopLogFile(int64_t stop_time); | 163 void StopLogFile(int64_t stop_time); |
| 159 | 164 |
| 160 // Observe a limit on the number of concurrent logs, so as not to run into | |
| 161 // OS-imposed limits on open files and/or threads/task-queues. | |
| 162 // TODO(eladalon): Known issue - there's a race over |log_count_|. | |
| 163 static std::atomic<int> log_count_; | |
| 164 | |
| 165 // Make sure that the event log is "managed" - created/destroyed, as well | 165 // Make sure that the event log is "managed" - created/destroyed, as well |
| 166 // as started/stopped - from the same thread/task-queue. | 166 // as started/stopped - from the same thread/task-queue. |
| 167 rtc::SequencedTaskChecker owner_sequence_checker_; | 167 rtc::SequencedTaskChecker owner_sequence_checker_; |
| 168 | 168 |
| 169 // History containing all past configuration events. | 169 // History containing all past configuration events. |
| 170 std::vector<std::unique_ptr<rtclog::Event>> config_history_ | 170 std::vector<std::unique_ptr<rtclog::Event>> config_history_ |
| 171 RTC_ACCESS_ON(task_queue_); | 171 RTC_ACCESS_ON(task_queue_); |
| 172 | 172 |
| 173 // History containing the most recent (non-configuration) events (~10s). | 173 // History containing the most recent (non-configuration) events (~10s). |
| 174 std::deque<std::unique_ptr<rtclog::Event>> history_ | 174 std::deque<std::unique_ptr<rtclog::Event>> history_ |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 return rtclog::BweProbeResult::INVALID_SEND_RECEIVE_RATIO; | 228 return rtclog::BweProbeResult::INVALID_SEND_RECEIVE_RATIO; |
| 229 case kTimeout: | 229 case kTimeout: |
| 230 return rtclog::BweProbeResult::TIMEOUT; | 230 return rtclog::BweProbeResult::TIMEOUT; |
| 231 } | 231 } |
| 232 RTC_NOTREACHED(); | 232 RTC_NOTREACHED(); |
| 233 return rtclog::BweProbeResult::SUCCESS; | 233 return rtclog::BweProbeResult::SUCCESS; |
| 234 } | 234 } |
| 235 | 235 |
| 236 } // namespace | 236 } // namespace |
| 237 | 237 |
| 238 std::atomic<int> RtcEventLogImpl::log_count_(0); | |
| 239 | |
| 240 RtcEventLogImpl::RtcEventLogImpl() | 238 RtcEventLogImpl::RtcEventLogImpl() |
| 241 : file_(FileWrapper::Create()), | 239 : file_(FileWrapper::Create()), |
| 242 max_size_bytes_(std::numeric_limits<decltype(max_size_bytes_)>::max()), | 240 max_size_bytes_(std::numeric_limits<decltype(max_size_bytes_)>::max()), |
| 243 written_bytes_(0), | 241 written_bytes_(0), |
| 244 task_queue_("rtc_event_log") {} | 242 task_queue_("rtc_event_log") {} |
| 245 | 243 |
| 246 RtcEventLogImpl::~RtcEventLogImpl() { | 244 RtcEventLogImpl::~RtcEventLogImpl() { |
| 247 RTC_DCHECK_CALLED_SEQUENTIALLY(&owner_sequence_checker_); | 245 RTC_DCHECK_CALLED_SEQUENTIALLY(&owner_sequence_checker_); |
| 248 | 246 |
| 249 // If we're logging to the file, this will stop that. Blocking function. | 247 // If we're logging to the file, this will stop that. Blocking function. |
| 250 StopLogging(); | 248 StopLogging(); |
| 251 | 249 |
| 252 int count = std::atomic_fetch_sub(&RtcEventLogImpl::log_count_, 1) - 1; | 250 int count = std::atomic_fetch_sub(&rtc_event_log_count, 1) - 1; |
| 253 RTC_DCHECK_GE(count, 0); | 251 RTC_DCHECK_GE(count, 0); |
| 254 } | 252 } |
| 255 | 253 |
| 256 bool RtcEventLogImpl::StartLogging(const std::string& file_name, | 254 bool RtcEventLogImpl::StartLogging(const std::string& file_name, |
| 257 int64_t max_size_bytes) { | 255 int64_t max_size_bytes) { |
| 258 RTC_DCHECK_CALLED_SEQUENTIALLY(&owner_sequence_checker_); | 256 RTC_DCHECK_CALLED_SEQUENTIALLY(&owner_sequence_checker_); |
| 259 | 257 |
| 260 auto file = rtc::WrapUnique<FileWrapper>(FileWrapper::Create()); | 258 auto file = rtc::WrapUnique<FileWrapper>(FileWrapper::Create()); |
| 261 if (!file->OpenFile(file_name.c_str(), false)) { | 259 if (!file->OpenFile(file_name.c_str(), false)) { |
| 262 LOG(LS_ERROR) << "Can't open file. WebRTC event log not started."; | 260 LOG(LS_ERROR) << "Can't open file. WebRTC event log not started."; |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 | 802 |
| 805 file_->CloseFile(); | 803 file_->CloseFile(); |
| 806 RTC_DCHECK(!file_->is_open()); | 804 RTC_DCHECK(!file_->is_open()); |
| 807 } | 805 } |
| 808 | 806 |
| 809 #endif // ENABLE_RTC_EVENT_LOG | 807 #endif // ENABLE_RTC_EVENT_LOG |
| 810 | 808 |
| 811 // RtcEventLog member functions. | 809 // RtcEventLog member functions. |
| 812 std::unique_ptr<RtcEventLog> RtcEventLog::Create() { | 810 std::unique_ptr<RtcEventLog> RtcEventLog::Create() { |
| 813 #ifdef ENABLE_RTC_EVENT_LOG | 811 #ifdef ENABLE_RTC_EVENT_LOG |
| 814 // TODO(eladalon): Known issue - there's a race over |log_count_| here. | 812 // TODO(eladalon): Known issue - there's a race over |rtc_event_log_count|. |
| 815 constexpr int kMaxLogCount = 5; | 813 constexpr int kMaxLogCount = 5; |
| 816 int count = 1 + std::atomic_fetch_add(&RtcEventLogImpl::log_count_, 1); | 814 int count = 1 + std::atomic_fetch_add(&rtc_event_log_count, 1); |
| 817 if (count > kMaxLogCount) { | 815 if (count > kMaxLogCount) { |
| 818 LOG(LS_WARNING) << "Denied creation of additional WebRTC event logs. " | 816 LOG(LS_WARNING) << "Denied creation of additional WebRTC event logs. " |
| 819 << count - 1 << " logs open already."; | 817 << count - 1 << " logs open already."; |
| 820 std::atomic_fetch_sub(&RtcEventLogImpl::log_count_, 1); | 818 std::atomic_fetch_sub(&rtc_event_log_count, 1); |
| 821 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); | 819 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); |
| 822 } | 820 } |
| 823 return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl()); | 821 return std::unique_ptr<RtcEventLog>(new RtcEventLogImpl()); |
| 824 #else | 822 #else |
| 825 return CreateNull(); | 823 return CreateNull(); |
| 826 #endif // ENABLE_RTC_EVENT_LOG | 824 #endif // ENABLE_RTC_EVENT_LOG |
| 827 } | 825 } |
| 828 | 826 |
| 829 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() { | 827 std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() { |
| 830 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); | 828 return std::unique_ptr<RtcEventLog>(new RtcEventLogNullImpl()); |
| 831 } | 829 } |
| 832 | 830 |
| 833 } // namespace webrtc | 831 } // namespace webrtc |
| OLD | NEW |