tommi@webrtc.org | 7c64ed2 | 2015-03-17 14:25:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #include "rtc_base/event_tracer.h" |
tommi@webrtc.org | 7c64ed2 | 2015-03-17 14:25:37 +0000 | [diff] [blame] | 11 | |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 12 | #include <inttypes.h> |
| 13 | |
sakal | f4433ef | 2016-08-08 04:10:13 -0700 | [diff] [blame] | 14 | #include <string> |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Tommi | 8d2c5a8 | 2018-03-19 11:12:48 +0100 | [diff] [blame] | 17 | #include "rtc_base/atomicops.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "rtc_base/checks.h" |
| 19 | #include "rtc_base/criticalsection.h" |
| 20 | #include "rtc_base/event.h" |
| 21 | #include "rtc_base/logging.h" |
| 22 | #include "rtc_base/platform_thread.h" |
| 23 | #include "rtc_base/stringutils.h" |
| 24 | #include "rtc_base/timeutils.h" |
| 25 | #include "rtc_base/trace_event.h" |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 26 | |
sakal | f4433ef | 2016-08-08 04:10:13 -0700 | [diff] [blame] | 27 | // This is a guesstimate that should be enough in most cases. |
| 28 | static const size_t kEventLoggerArgsStrBufferInitialSize = 256; |
| 29 | static const size_t kTraceArgBufferLength = 32; |
| 30 | |
tommi@webrtc.org | 7c64ed2 | 2015-03-17 14:25:37 +0000 | [diff] [blame] | 31 | namespace webrtc { |
| 32 | |
| 33 | namespace { |
| 34 | |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 35 | GetCategoryEnabledPtr g_get_category_enabled_ptr = nullptr; |
| 36 | AddTraceEventPtr g_add_trace_event_ptr = nullptr; |
tommi@webrtc.org | 7c64ed2 | 2015-03-17 14:25:37 +0000 | [diff] [blame] | 37 | |
| 38 | } // namespace |
| 39 | |
| 40 | void SetupEventTracer(GetCategoryEnabledPtr get_category_enabled_ptr, |
| 41 | AddTraceEventPtr add_trace_event_ptr) { |
| 42 | g_get_category_enabled_ptr = get_category_enabled_ptr; |
| 43 | g_add_trace_event_ptr = add_trace_event_ptr; |
| 44 | } |
| 45 | |
tommi@webrtc.org | 7c64ed2 | 2015-03-17 14:25:37 +0000 | [diff] [blame] | 46 | const unsigned char* EventTracer::GetCategoryEnabled(const char* name) { |
| 47 | if (g_get_category_enabled_ptr) |
| 48 | return g_get_category_enabled_ptr(name); |
| 49 | |
| 50 | // A string with null terminator means category is disabled. |
| 51 | return reinterpret_cast<const unsigned char*>("\0"); |
| 52 | } |
| 53 | |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 54 | // Arguments to this function (phase, etc.) are as defined in |
kjellander | e96c45b | 2017-06-30 10:45:21 -0700 | [diff] [blame] | 55 | // webrtc/rtc_base/trace_event.h. |
tommi@webrtc.org | 7c64ed2 | 2015-03-17 14:25:37 +0000 | [diff] [blame] | 56 | void EventTracer::AddTraceEvent(char phase, |
| 57 | const unsigned char* category_enabled, |
| 58 | const char* name, |
| 59 | unsigned long long id, |
| 60 | int num_args, |
| 61 | const char** arg_names, |
| 62 | const unsigned char* arg_types, |
| 63 | const unsigned long long* arg_values, |
| 64 | unsigned char flags) { |
| 65 | if (g_add_trace_event_ptr) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 66 | g_add_trace_event_ptr(phase, category_enabled, name, id, num_args, |
| 67 | arg_names, arg_types, arg_values, flags); |
tommi@webrtc.org | 7c64ed2 | 2015-03-17 14:25:37 +0000 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | } // namespace webrtc |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 72 | |
| 73 | namespace rtc { |
| 74 | namespace tracing { |
| 75 | namespace { |
| 76 | |
tommi | 0f8b403 | 2017-02-22 11:22:05 -0800 | [diff] [blame] | 77 | static void EventTracingThreadFunc(void* params); |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 78 | |
| 79 | // Atomic-int fast path for avoiding logging when disabled. |
| 80 | static volatile int g_event_logging_active = 0; |
| 81 | |
| 82 | // TODO(pbos): Log metadata for all threads, etc. |
| 83 | class EventLogger final { |
| 84 | public: |
| 85 | EventLogger() |
tommi | 0f8b403 | 2017-02-22 11:22:05 -0800 | [diff] [blame] | 86 | : logging_thread_(EventTracingThreadFunc, |
| 87 | this, |
| 88 | "EventTracingThread", |
| 89 | kLowPriority), |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 90 | shutdown_event_(false, false) {} |
| 91 | ~EventLogger() { RTC_DCHECK(thread_checker_.CalledOnValidThread()); } |
| 92 | |
| 93 | void AddTraceEvent(const char* name, |
| 94 | const unsigned char* category_enabled, |
| 95 | char phase, |
sakal | f4433ef | 2016-08-08 04:10:13 -0700 | [diff] [blame] | 96 | int num_args, |
| 97 | const char** arg_names, |
| 98 | const unsigned char* arg_types, |
| 99 | const unsigned long long* arg_values, |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 100 | uint64_t timestamp, |
| 101 | int pid, |
| 102 | rtc::PlatformThreadId thread_id) { |
sakal | f4433ef | 2016-08-08 04:10:13 -0700 | [diff] [blame] | 103 | std::vector<TraceArg> args(num_args); |
| 104 | for (int i = 0; i < num_args; ++i) { |
| 105 | TraceArg& arg = args[i]; |
| 106 | arg.name = arg_names[i]; |
| 107 | arg.type = arg_types[i]; |
| 108 | arg.value.as_uint = arg_values[i]; |
| 109 | |
| 110 | // Value is a pointer to a temporary string, so we have to make a copy. |
| 111 | if (arg.type == TRACE_VALUE_TYPE_COPY_STRING) { |
| 112 | // Space for the string and for the terminating null character. |
| 113 | size_t str_length = strlen(arg.value.as_string) + 1; |
| 114 | char* str_copy = new char[str_length]; |
| 115 | memcpy(str_copy, arg.value.as_string, str_length); |
| 116 | arg.value.as_string = str_copy; |
| 117 | } |
| 118 | } |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 119 | rtc::CritScope lock(&crit_); |
| 120 | trace_events_.push_back( |
sakal | f4433ef | 2016-08-08 04:10:13 -0700 | [diff] [blame] | 121 | {name, category_enabled, phase, args, timestamp, 1, thread_id}); |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 122 | } |
| 123 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 124 | // The TraceEvent format is documented here: |
| 125 | // https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 126 | void Log() { |
| 127 | RTC_DCHECK(output_file_); |
| 128 | static const int kLoggingIntervalMs = 100; |
| 129 | fprintf(output_file_, "{ \"traceEvents\": [\n"); |
| 130 | bool has_logged_event = false; |
| 131 | while (true) { |
| 132 | bool shutting_down = shutdown_event_.Wait(kLoggingIntervalMs); |
| 133 | std::vector<TraceEvent> events; |
| 134 | { |
| 135 | rtc::CritScope lock(&crit_); |
| 136 | trace_events_.swap(events); |
| 137 | } |
sakal | f4433ef | 2016-08-08 04:10:13 -0700 | [diff] [blame] | 138 | std::string args_str; |
| 139 | args_str.reserve(kEventLoggerArgsStrBufferInitialSize); |
| 140 | for (TraceEvent& e : events) { |
| 141 | args_str.clear(); |
| 142 | if (!e.args.empty()) { |
| 143 | args_str += ", \"args\": {"; |
| 144 | bool is_first_argument = true; |
| 145 | for (TraceArg& arg : e.args) { |
| 146 | if (!is_first_argument) |
| 147 | args_str += ","; |
| 148 | is_first_argument = false; |
| 149 | args_str += " \""; |
| 150 | args_str += arg.name; |
| 151 | args_str += "\": "; |
| 152 | args_str += TraceArgValueAsString(arg); |
| 153 | |
| 154 | // Delete our copy of the string. |
| 155 | if (arg.type == TRACE_VALUE_TYPE_COPY_STRING) { |
| 156 | delete[] arg.value.as_string; |
| 157 | arg.value.as_string = nullptr; |
| 158 | } |
| 159 | } |
| 160 | args_str += " }"; |
| 161 | } |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 162 | fprintf(output_file_, |
| 163 | "%s{ \"name\": \"%s\"" |
| 164 | ", \"cat\": \"%s\"" |
| 165 | ", \"ph\": \"%c\"" |
| 166 | ", \"ts\": %" PRIu64 |
| 167 | ", \"pid\": %d" |
Peter Boström | 43e4e23 | 2015-12-11 20:29:35 +0100 | [diff] [blame] | 168 | #if defined(WEBRTC_WIN) |
| 169 | ", \"tid\": %lu" |
| 170 | #else |
| 171 | ", \"tid\": %d" |
| 172 | #endif // defined(WEBRTC_WIN) |
sakal | f4433ef | 2016-08-08 04:10:13 -0700 | [diff] [blame] | 173 | "%s" |
Peter Boström | 43e4e23 | 2015-12-11 20:29:35 +0100 | [diff] [blame] | 174 | "}\n", |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 175 | has_logged_event ? "," : " ", e.name, e.category_enabled, |
sakal | f4433ef | 2016-08-08 04:10:13 -0700 | [diff] [blame] | 176 | e.phase, e.timestamp, e.pid, e.tid, args_str.c_str()); |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 177 | has_logged_event = true; |
| 178 | } |
| 179 | if (shutting_down) |
| 180 | break; |
| 181 | } |
| 182 | fprintf(output_file_, "]}\n"); |
| 183 | if (output_file_owned_) |
| 184 | fclose(output_file_); |
| 185 | output_file_ = nullptr; |
| 186 | } |
| 187 | |
| 188 | void Start(FILE* file, bool owned) { |
Peter Boström | dda8a83 | 2016-02-29 14:54:04 +0100 | [diff] [blame] | 189 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 190 | RTC_DCHECK(file); |
| 191 | RTC_DCHECK(!output_file_); |
| 192 | output_file_ = file; |
| 193 | output_file_owned_ = owned; |
| 194 | { |
| 195 | rtc::CritScope lock(&crit_); |
| 196 | // Since the atomic fast-path for adding events to the queue can be |
| 197 | // bypassed while the logging thread is shutting down there may be some |
| 198 | // stale events in the queue, hence the vector needs to be cleared to not |
| 199 | // log events from a previous logging session (which may be days old). |
| 200 | trace_events_.clear(); |
| 201 | } |
| 202 | // Enable event logging (fast-path). This should be disabled since starting |
| 203 | // shouldn't be done twice. |
| 204 | RTC_CHECK_EQ(0, |
| 205 | rtc::AtomicOps::CompareAndSwap(&g_event_logging_active, 0, 1)); |
| 206 | |
| 207 | // Finally start, everything should be set up now. |
| 208 | logging_thread_.Start(); |
Peter Boström | dda8a83 | 2016-02-29 14:54:04 +0100 | [diff] [blame] | 209 | TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Start"); |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void Stop() { |
Peter Boström | dda8a83 | 2016-02-29 14:54:04 +0100 | [diff] [blame] | 213 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 214 | TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Stop"); |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 215 | // Try to stop. Abort if we're not currently logging. |
| 216 | if (rtc::AtomicOps::CompareAndSwap(&g_event_logging_active, 1, 0) == 0) |
| 217 | return; |
| 218 | |
| 219 | // Wake up logging thread to finish writing. |
| 220 | shutdown_event_.Set(); |
| 221 | // Join the logging thread. |
| 222 | logging_thread_.Stop(); |
| 223 | } |
| 224 | |
| 225 | private: |
sakal | f4433ef | 2016-08-08 04:10:13 -0700 | [diff] [blame] | 226 | struct TraceArg { |
| 227 | const char* name; |
| 228 | unsigned char type; |
kjellander | e96c45b | 2017-06-30 10:45:21 -0700 | [diff] [blame] | 229 | // Copied from webrtc/rtc_base/trace_event.h TraceValueUnion. |
sakal | f4433ef | 2016-08-08 04:10:13 -0700 | [diff] [blame] | 230 | union TraceArgValue { |
| 231 | bool as_bool; |
| 232 | unsigned long long as_uint; |
| 233 | long long as_int; |
| 234 | double as_double; |
| 235 | const void* as_pointer; |
| 236 | const char* as_string; |
| 237 | } value; |
| 238 | |
| 239 | // Assert that the size of the union is equal to the size of the as_uint |
| 240 | // field since we are assigning to arbitrary types using it. |
| 241 | static_assert(sizeof(TraceArgValue) == sizeof(unsigned long long), |
| 242 | "Size of TraceArg value union is not equal to the size of " |
| 243 | "the uint field of that union."); |
| 244 | }; |
| 245 | |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 246 | struct TraceEvent { |
| 247 | const char* name; |
| 248 | const unsigned char* category_enabled; |
| 249 | char phase; |
sakal | f4433ef | 2016-08-08 04:10:13 -0700 | [diff] [blame] | 250 | std::vector<TraceArg> args; |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 251 | uint64_t timestamp; |
| 252 | int pid; |
| 253 | rtc::PlatformThreadId tid; |
| 254 | }; |
| 255 | |
sakal | f4433ef | 2016-08-08 04:10:13 -0700 | [diff] [blame] | 256 | static std::string TraceArgValueAsString(TraceArg arg) { |
| 257 | std::string output; |
| 258 | |
| 259 | if (arg.type == TRACE_VALUE_TYPE_STRING || |
| 260 | arg.type == TRACE_VALUE_TYPE_COPY_STRING) { |
| 261 | // Space for every character to be an espaced character + two for |
| 262 | // quatation marks. |
| 263 | output.reserve(strlen(arg.value.as_string) * 2 + 2); |
| 264 | output += '\"'; |
| 265 | const char* c = arg.value.as_string; |
| 266 | do { |
| 267 | if (*c == '"' || *c == '\\') { |
| 268 | output += '\\'; |
| 269 | output += *c; |
| 270 | } else { |
| 271 | output += *c; |
| 272 | } |
| 273 | } while (*++c); |
| 274 | output += '\"'; |
| 275 | } else { |
| 276 | output.resize(kTraceArgBufferLength); |
| 277 | size_t print_length = 0; |
| 278 | switch (arg.type) { |
| 279 | case TRACE_VALUE_TYPE_BOOL: |
| 280 | if (arg.value.as_bool) { |
| 281 | strcpy(&output[0], "true"); |
| 282 | print_length = 4; |
| 283 | } else { |
| 284 | strcpy(&output[0], "false"); |
| 285 | print_length = 5; |
| 286 | } |
| 287 | break; |
| 288 | case TRACE_VALUE_TYPE_UINT: |
| 289 | print_length = sprintfn(&output[0], kTraceArgBufferLength, "%llu", |
| 290 | arg.value.as_uint); |
| 291 | break; |
| 292 | case TRACE_VALUE_TYPE_INT: |
| 293 | print_length = sprintfn(&output[0], kTraceArgBufferLength, "%lld", |
| 294 | arg.value.as_int); |
| 295 | break; |
| 296 | case TRACE_VALUE_TYPE_DOUBLE: |
| 297 | print_length = sprintfn(&output[0], kTraceArgBufferLength, "%f", |
| 298 | arg.value.as_double); |
| 299 | break; |
| 300 | case TRACE_VALUE_TYPE_POINTER: |
| 301 | print_length = sprintfn(&output[0], kTraceArgBufferLength, "\"%p\"", |
| 302 | arg.value.as_pointer); |
| 303 | break; |
| 304 | } |
| 305 | size_t output_length = print_length < kTraceArgBufferLength |
| 306 | ? print_length |
| 307 | : kTraceArgBufferLength - 1; |
| 308 | // This will hopefully be very close to nop. On most implementations, it |
| 309 | // just writes null byte and sets the length field of the string. |
| 310 | output.resize(output_length); |
| 311 | } |
| 312 | |
| 313 | return output; |
| 314 | } |
| 315 | |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 316 | rtc::CriticalSection crit_; |
danilchap | 3c6abd2 | 2017-09-06 05:46:29 -0700 | [diff] [blame] | 317 | std::vector<TraceEvent> trace_events_ RTC_GUARDED_BY(crit_); |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 318 | rtc::PlatformThread logging_thread_; |
| 319 | rtc::Event shutdown_event_; |
| 320 | rtc::ThreadChecker thread_checker_; |
| 321 | FILE* output_file_ = nullptr; |
| 322 | bool output_file_owned_ = false; |
| 323 | }; |
| 324 | |
tommi | 0f8b403 | 2017-02-22 11:22:05 -0800 | [diff] [blame] | 325 | static void EventTracingThreadFunc(void* params) { |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 326 | static_cast<EventLogger*>(params)->Log(); |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | static EventLogger* volatile g_event_logger = nullptr; |
| 330 | static const char* const kDisabledTracePrefix = TRACE_DISABLED_BY_DEFAULT(""); |
| 331 | const unsigned char* InternalGetCategoryEnabled(const char* name) { |
| 332 | const char* prefix_ptr = &kDisabledTracePrefix[0]; |
| 333 | const char* name_ptr = name; |
| 334 | // Check whether name contains the default-disabled prefix. |
| 335 | while (*prefix_ptr == *name_ptr && *prefix_ptr != '\0') { |
| 336 | ++prefix_ptr; |
| 337 | ++name_ptr; |
| 338 | } |
| 339 | return reinterpret_cast<const unsigned char*>(*prefix_ptr == '\0' ? "" |
| 340 | : name); |
| 341 | } |
| 342 | |
| 343 | void InternalAddTraceEvent(char phase, |
| 344 | const unsigned char* category_enabled, |
| 345 | const char* name, |
| 346 | unsigned long long id, |
| 347 | int num_args, |
| 348 | const char** arg_names, |
| 349 | const unsigned char* arg_types, |
| 350 | const unsigned long long* arg_values, |
| 351 | unsigned char flags) { |
| 352 | // Fast path for when event tracing is inactive. |
| 353 | if (rtc::AtomicOps::AcquireLoad(&g_event_logging_active) == 0) |
| 354 | return; |
| 355 | |
sakal | f4433ef | 2016-08-08 04:10:13 -0700 | [diff] [blame] | 356 | g_event_logger->AddTraceEvent(name, category_enabled, phase, num_args, |
| 357 | arg_names, arg_types, arg_values, |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 358 | rtc::TimeMicros(), 1, rtc::CurrentThreadId()); |
| 359 | } |
| 360 | |
| 361 | } // namespace |
| 362 | |
| 363 | void SetupInternalTracer() { |
| 364 | RTC_CHECK(rtc::AtomicOps::CompareAndSwapPtr( |
| 365 | &g_event_logger, static_cast<EventLogger*>(nullptr), |
| 366 | new EventLogger()) == nullptr); |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 367 | webrtc::SetupEventTracer(InternalGetCategoryEnabled, InternalAddTraceEvent); |
| 368 | } |
| 369 | |
| 370 | void StartInternalCaptureToFile(FILE* file) { |
jtteh | 7480da4 | 2017-07-07 11:02:15 -0700 | [diff] [blame] | 371 | if (g_event_logger) { |
| 372 | g_event_logger->Start(file, false); |
| 373 | } |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | bool StartInternalCapture(const char* filename) { |
jtteh | 7480da4 | 2017-07-07 11:02:15 -0700 | [diff] [blame] | 377 | if (!g_event_logger) |
| 378 | return false; |
| 379 | |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 380 | FILE* file = fopen(filename, "w"); |
| 381 | if (!file) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 382 | RTC_LOG(LS_ERROR) << "Failed to open trace file '" << filename |
| 383 | << "' for writing."; |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 384 | return false; |
| 385 | } |
| 386 | g_event_logger->Start(file, true); |
| 387 | return true; |
| 388 | } |
| 389 | |
| 390 | void StopInternalCapture() { |
jtteh | 7480da4 | 2017-07-07 11:02:15 -0700 | [diff] [blame] | 391 | if (g_event_logger) { |
| 392 | g_event_logger->Stop(); |
| 393 | } |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | void ShutdownInternalTracer() { |
| 397 | StopInternalCapture(); |
Peter Boström | 455a252 | 2015-12-18 17:00:25 +0100 | [diff] [blame] | 398 | EventLogger* old_logger = rtc::AtomicOps::AcquireLoadPtr(&g_event_logger); |
Peter Boström | 6f28cf0 | 2015-12-07 23:17:15 +0100 | [diff] [blame] | 399 | RTC_DCHECK(old_logger); |
| 400 | RTC_CHECK(rtc::AtomicOps::CompareAndSwapPtr( |
| 401 | &g_event_logger, old_logger, |
| 402 | static_cast<EventLogger*>(nullptr)) == old_logger); |
| 403 | delete old_logger; |
| 404 | webrtc::SetupEventTracer(nullptr, nullptr); |
| 405 | } |
| 406 | |
| 407 | } // namespace tracing |
| 408 | } // namespace rtc |