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

Side by Side Diff: webrtc/base/event_tracer.cc

Issue 1746693002: Trace tracing Start/Stop events. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: add thread checks Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (shutting_down) 132 if (shutting_down)
133 break; 133 break;
134 } 134 }
135 fprintf(output_file_, "]}\n"); 135 fprintf(output_file_, "]}\n");
136 if (output_file_owned_) 136 if (output_file_owned_)
137 fclose(output_file_); 137 fclose(output_file_);
138 output_file_ = nullptr; 138 output_file_ = nullptr;
139 } 139 }
140 140
141 void Start(FILE* file, bool owned) { 141 void Start(FILE* file, bool owned) {
142 RTC_DCHECK(thread_checker_.CalledOnValidThread());
142 RTC_DCHECK(file); 143 RTC_DCHECK(file);
143 RTC_DCHECK(!output_file_); 144 RTC_DCHECK(!output_file_);
144 output_file_ = file; 145 output_file_ = file;
145 output_file_owned_ = owned; 146 output_file_owned_ = owned;
146 { 147 {
147 rtc::CritScope lock(&crit_); 148 rtc::CritScope lock(&crit_);
148 // Since the atomic fast-path for adding events to the queue can be 149 // Since the atomic fast-path for adding events to the queue can be
149 // bypassed while the logging thread is shutting down there may be some 150 // bypassed while the logging thread is shutting down there may be some
150 // stale events in the queue, hence the vector needs to be cleared to not 151 // stale events in the queue, hence the vector needs to be cleared to not
151 // log events from a previous logging session (which may be days old). 152 // log events from a previous logging session (which may be days old).
152 trace_events_.clear(); 153 trace_events_.clear();
153 } 154 }
154 // Enable event logging (fast-path). This should be disabled since starting 155 // Enable event logging (fast-path). This should be disabled since starting
155 // shouldn't be done twice. 156 // shouldn't be done twice.
156 RTC_CHECK_EQ(0, 157 RTC_CHECK_EQ(0,
157 rtc::AtomicOps::CompareAndSwap(&g_event_logging_active, 0, 1)); 158 rtc::AtomicOps::CompareAndSwap(&g_event_logging_active, 0, 1));
158 159
159 // Finally start, everything should be set up now. 160 // Finally start, everything should be set up now.
160 logging_thread_.Start(); 161 logging_thread_.Start();
162 TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Start");
161 } 163 }
162 164
163 void Stop() { 165 void Stop() {
166 RTC_DCHECK(thread_checker_.CalledOnValidThread());
167 TRACE_EVENT_INSTANT0("webrtc", "EventLogger::Stop");
164 // Try to stop. Abort if we're not currently logging. 168 // Try to stop. Abort if we're not currently logging.
165 if (rtc::AtomicOps::CompareAndSwap(&g_event_logging_active, 1, 0) == 0) 169 if (rtc::AtomicOps::CompareAndSwap(&g_event_logging_active, 1, 0) == 0)
166 return; 170 return;
167 171
168 // Wake up logging thread to finish writing. 172 // Wake up logging thread to finish writing.
169 shutdown_event_.Set(); 173 shutdown_event_.Set();
170 // Join the logging thread. 174 // Join the logging thread.
171 logging_thread_.Stop(); 175 logging_thread_.Stop();
172 } 176 }
173 177
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 RTC_DCHECK(old_logger); 265 RTC_DCHECK(old_logger);
262 RTC_CHECK(rtc::AtomicOps::CompareAndSwapPtr( 266 RTC_CHECK(rtc::AtomicOps::CompareAndSwapPtr(
263 &g_event_logger, old_logger, 267 &g_event_logger, old_logger,
264 static_cast<EventLogger*>(nullptr)) == old_logger); 268 static_cast<EventLogger*>(nullptr)) == old_logger);
265 delete old_logger; 269 delete old_logger;
266 webrtc::SetupEventTracer(nullptr, nullptr); 270 webrtc::SetupEventTracer(nullptr, nullptr);
267 } 271 }
268 272
269 } // namespace tracing 273 } // namespace tracing
270 } // namespace rtc 274 } // namespace rtc
OLDNEW
« 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