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/rtc_base/event_tracer.h" |
11 | 11 |
12 #include <inttypes.h> | 12 #include <inttypes.h> |
13 | 13 |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/rtc_base/checks.h" |
18 #include "webrtc/base/criticalsection.h" | 18 #include "webrtc/rtc_base/criticalsection.h" |
19 #include "webrtc/base/event.h" | 19 #include "webrtc/rtc_base/event.h" |
20 #include "webrtc/base/logging.h" | 20 #include "webrtc/rtc_base/logging.h" |
21 #include "webrtc/base/platform_thread.h" | 21 #include "webrtc/rtc_base/platform_thread.h" |
22 #include "webrtc/base/stringutils.h" | 22 #include "webrtc/rtc_base/stringutils.h" |
23 #include "webrtc/base/timeutils.h" | 23 #include "webrtc/rtc_base/timeutils.h" |
24 #include "webrtc/base/trace_event.h" | 24 #include "webrtc/rtc_base/trace_event.h" |
25 | 25 |
26 // This is a guesstimate that should be enough in most cases. | 26 // This is a guesstimate that should be enough in most cases. |
27 static const size_t kEventLoggerArgsStrBufferInitialSize = 256; | 27 static const size_t kEventLoggerArgsStrBufferInitialSize = 256; |
28 static const size_t kTraceArgBufferLength = 32; | 28 static const size_t kTraceArgBufferLength = 32; |
29 | 29 |
30 namespace webrtc { | 30 namespace webrtc { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 GetCategoryEnabledPtr g_get_category_enabled_ptr = nullptr; | 34 GetCategoryEnabledPtr g_get_category_enabled_ptr = nullptr; |
35 AddTraceEventPtr g_add_trace_event_ptr = nullptr; | 35 AddTraceEventPtr g_add_trace_event_ptr = nullptr; |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 void SetupEventTracer(GetCategoryEnabledPtr get_category_enabled_ptr, | 39 void SetupEventTracer(GetCategoryEnabledPtr get_category_enabled_ptr, |
40 AddTraceEventPtr add_trace_event_ptr) { | 40 AddTraceEventPtr add_trace_event_ptr) { |
41 g_get_category_enabled_ptr = get_category_enabled_ptr; | 41 g_get_category_enabled_ptr = get_category_enabled_ptr; |
42 g_add_trace_event_ptr = add_trace_event_ptr; | 42 g_add_trace_event_ptr = add_trace_event_ptr; |
43 } | 43 } |
44 | 44 |
45 const unsigned char* EventTracer::GetCategoryEnabled(const char* name) { | 45 const unsigned char* EventTracer::GetCategoryEnabled(const char* name) { |
46 if (g_get_category_enabled_ptr) | 46 if (g_get_category_enabled_ptr) |
47 return g_get_category_enabled_ptr(name); | 47 return g_get_category_enabled_ptr(name); |
48 | 48 |
49 // A string with null terminator means category is disabled. | 49 // A string with null terminator means category is disabled. |
50 return reinterpret_cast<const unsigned char*>("\0"); | 50 return reinterpret_cast<const unsigned char*>("\0"); |
51 } | 51 } |
52 | 52 |
53 // Arguments to this function (phase, etc.) are as defined in | 53 // Arguments to this function (phase, etc.) are as defined in |
54 // webrtc/base/trace_event.h. | 54 // webrtc/rtc_base/trace_event.h. |
55 void EventTracer::AddTraceEvent(char phase, | 55 void EventTracer::AddTraceEvent(char phase, |
56 const unsigned char* category_enabled, | 56 const unsigned char* category_enabled, |
57 const char* name, | 57 const char* name, |
58 unsigned long long id, | 58 unsigned long long id, |
59 int num_args, | 59 int num_args, |
60 const char** arg_names, | 60 const char** arg_names, |
61 const unsigned char* arg_types, | 61 const unsigned char* arg_types, |
62 const unsigned long long* arg_values, | 62 const unsigned long long* arg_values, |
63 unsigned char flags) { | 63 unsigned char flags) { |
64 if (g_add_trace_event_ptr) { | 64 if (g_add_trace_event_ptr) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 // Wake up logging thread to finish writing. | 225 // Wake up logging thread to finish writing. |
226 shutdown_event_.Set(); | 226 shutdown_event_.Set(); |
227 // Join the logging thread. | 227 // Join the logging thread. |
228 logging_thread_.Stop(); | 228 logging_thread_.Stop(); |
229 } | 229 } |
230 | 230 |
231 private: | 231 private: |
232 struct TraceArg { | 232 struct TraceArg { |
233 const char* name; | 233 const char* name; |
234 unsigned char type; | 234 unsigned char type; |
235 // Copied from webrtc/base/trace_event.h TraceValueUnion. | 235 // Copied from webrtc/rtc_base/trace_event.h TraceValueUnion. |
236 union TraceArgValue { | 236 union TraceArgValue { |
237 bool as_bool; | 237 bool as_bool; |
238 unsigned long long as_uint; | 238 unsigned long long as_uint; |
239 long long as_int; | 239 long long as_int; |
240 double as_double; | 240 double as_double; |
241 const void* as_pointer; | 241 const void* as_pointer; |
242 const char* as_string; | 242 const char* as_string; |
243 } value; | 243 } value; |
244 | 244 |
245 // Assert that the size of the union is equal to the size of the as_uint | 245 // Assert that the size of the union is equal to the size of the as_uint |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 RTC_DCHECK(old_logger); | 398 RTC_DCHECK(old_logger); |
399 RTC_CHECK(rtc::AtomicOps::CompareAndSwapPtr( | 399 RTC_CHECK(rtc::AtomicOps::CompareAndSwapPtr( |
400 &g_event_logger, old_logger, | 400 &g_event_logger, old_logger, |
401 static_cast<EventLogger*>(nullptr)) == old_logger); | 401 static_cast<EventLogger*>(nullptr)) == old_logger); |
402 delete old_logger; | 402 delete old_logger; |
403 webrtc::SetupEventTracer(nullptr, nullptr); | 403 webrtc::SetupEventTracer(nullptr, nullptr); |
404 } | 404 } |
405 | 405 |
406 } // namespace tracing | 406 } // namespace tracing |
407 } // namespace rtc | 407 } // namespace rtc |
OLD | NEW |