OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 #include "webrtc/base/event_tracer.h" | 10 #include "webrtc/base/event_tracer.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 flags); | 73 flags); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 } // namespace webrtc | 77 } // namespace webrtc |
78 | 78 |
79 namespace rtc { | 79 namespace rtc { |
80 namespace tracing { | 80 namespace tracing { |
81 namespace { | 81 namespace { |
82 | 82 |
83 static bool EventTracingThreadFunc(void* params); | 83 static void EventTracingThreadFunc(void* params); |
84 | 84 |
85 // Atomic-int fast path for avoiding logging when disabled. | 85 // Atomic-int fast path for avoiding logging when disabled. |
86 static volatile int g_event_logging_active = 0; | 86 static volatile int g_event_logging_active = 0; |
87 | 87 |
88 // TODO(pbos): Log metadata for all threads, etc. | 88 // TODO(pbos): Log metadata for all threads, etc. |
89 class EventLogger final { | 89 class EventLogger final { |
90 public: | 90 public: |
91 EventLogger() | 91 EventLogger() |
92 : logging_thread_(EventTracingThreadFunc, this, "EventTracingThread"), | 92 : logging_thread_(EventTracingThreadFunc, |
| 93 this, |
| 94 "EventTracingThread", |
| 95 kLowPriority), |
93 shutdown_event_(false, false) {} | 96 shutdown_event_(false, false) {} |
94 ~EventLogger() { RTC_DCHECK(thread_checker_.CalledOnValidThread()); } | 97 ~EventLogger() { RTC_DCHECK(thread_checker_.CalledOnValidThread()); } |
95 | 98 |
96 void AddTraceEvent(const char* name, | 99 void AddTraceEvent(const char* name, |
97 const unsigned char* category_enabled, | 100 const unsigned char* category_enabled, |
98 char phase, | 101 char phase, |
99 int num_args, | 102 int num_args, |
100 const char** arg_names, | 103 const char** arg_names, |
101 const unsigned char* arg_types, | 104 const unsigned char* arg_types, |
102 const unsigned long long* arg_values, | 105 const unsigned long long* arg_values, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 trace_events_.clear(); | 206 trace_events_.clear(); |
204 } | 207 } |
205 // Enable event logging (fast-path). This should be disabled since starting | 208 // Enable event logging (fast-path). This should be disabled since starting |
206 // shouldn't be done twice. | 209 // shouldn't be done twice. |
207 RTC_CHECK_EQ(0, | 210 RTC_CHECK_EQ(0, |
208 rtc::AtomicOps::CompareAndSwap(&g_event_logging_active, 0, 1)); | 211 rtc::AtomicOps::CompareAndSwap(&g_event_logging_active, 0, 1)); |
209 | 212 |
210 // Finally start, everything should be set up now. | 213 // Finally start, everything should be set up now. |
211 logging_thread_.Start(); | 214 logging_thread_.Start(); |
212 TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Start"); | 215 TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Start"); |
213 logging_thread_.SetPriority(kLowPriority); | |
214 } | 216 } |
215 | 217 |
216 void Stop() { | 218 void Stop() { |
217 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 219 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
218 TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Stop"); | 220 TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Stop"); |
219 // Try to stop. Abort if we're not currently logging. | 221 // Try to stop. Abort if we're not currently logging. |
220 if (rtc::AtomicOps::CompareAndSwap(&g_event_logging_active, 1, 0) == 0) | 222 if (rtc::AtomicOps::CompareAndSwap(&g_event_logging_active, 1, 0) == 0) |
221 return; | 223 return; |
222 | 224 |
223 // Wake up logging thread to finish writing. | 225 // Wake up logging thread to finish writing. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 321 |
320 rtc::CriticalSection crit_; | 322 rtc::CriticalSection crit_; |
321 std::vector<TraceEvent> trace_events_ GUARDED_BY(crit_); | 323 std::vector<TraceEvent> trace_events_ GUARDED_BY(crit_); |
322 rtc::PlatformThread logging_thread_; | 324 rtc::PlatformThread logging_thread_; |
323 rtc::Event shutdown_event_; | 325 rtc::Event shutdown_event_; |
324 rtc::ThreadChecker thread_checker_; | 326 rtc::ThreadChecker thread_checker_; |
325 FILE* output_file_ = nullptr; | 327 FILE* output_file_ = nullptr; |
326 bool output_file_owned_ = false; | 328 bool output_file_owned_ = false; |
327 }; | 329 }; |
328 | 330 |
329 static bool EventTracingThreadFunc(void* params) { | 331 static void EventTracingThreadFunc(void* params) { |
330 static_cast<EventLogger*>(params)->Log(); | 332 static_cast<EventLogger*>(params)->Log(); |
331 // False indicates that the thread function has done its job and doesn't need | |
332 // to be restarted again. Log() runs its own internal loop. | |
333 return false; | |
334 } | 333 } |
335 | 334 |
336 static EventLogger* volatile g_event_logger = nullptr; | 335 static EventLogger* volatile g_event_logger = nullptr; |
337 static const char* const kDisabledTracePrefix = TRACE_DISABLED_BY_DEFAULT(""); | 336 static const char* const kDisabledTracePrefix = TRACE_DISABLED_BY_DEFAULT(""); |
338 const unsigned char* InternalGetCategoryEnabled(const char* name) { | 337 const unsigned char* InternalGetCategoryEnabled(const char* name) { |
339 const char* prefix_ptr = &kDisabledTracePrefix[0]; | 338 const char* prefix_ptr = &kDisabledTracePrefix[0]; |
340 const char* name_ptr = name; | 339 const char* name_ptr = name; |
341 // Check whether name contains the default-disabled prefix. | 340 // Check whether name contains the default-disabled prefix. |
342 while (*prefix_ptr == *name_ptr && *prefix_ptr != '\0') { | 341 while (*prefix_ptr == *name_ptr && *prefix_ptr != '\0') { |
343 ++prefix_ptr; | 342 ++prefix_ptr; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 RTC_DCHECK(old_logger); | 398 RTC_DCHECK(old_logger); |
400 RTC_CHECK(rtc::AtomicOps::CompareAndSwapPtr( | 399 RTC_CHECK(rtc::AtomicOps::CompareAndSwapPtr( |
401 &g_event_logger, old_logger, | 400 &g_event_logger, old_logger, |
402 static_cast<EventLogger*>(nullptr)) == old_logger); | 401 static_cast<EventLogger*>(nullptr)) == old_logger); |
403 delete old_logger; | 402 delete old_logger; |
404 webrtc::SetupEventTracer(nullptr, nullptr); | 403 webrtc::SetupEventTracer(nullptr, nullptr); |
405 } | 404 } |
406 | 405 |
407 } // namespace tracing | 406 } // namespace tracing |
408 } // namespace rtc | 407 } // namespace rtc |
OLD | NEW |