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

Unified Diff: base/trace_event/auto_open_close_event.cc

Issue 2159323002: Add tracing AutoOpenCloseEvent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add forward declaration Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/trace_event/auto_open_close_event.h ('k') | media/blink/video_frame_compositor.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/auto_open_close_event.cc
diff --git a/base/trace_event/auto_open_close_event.cc b/base/trace_event/auto_open_close_event.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f2794f497cba81be5125f9dd2bebbe7f44de983b
--- /dev/null
+++ b/base/trace_event/auto_open_close_event.cc
@@ -0,0 +1,52 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/trace_event/auto_open_close_event.h"
+
+#include "base/macros.h"
+#include "base/time/time.h"
+#include "base/trace_event/trace_event.h"
+
+namespace base {
+namespace trace_event {
+
+AutoOpenCloseEvent::AutoOpenCloseEvent(AutoOpenCloseEvent::Type type,
+ const char* category, const char* event_name):
+ category_(category),
+ event_name_(event_name),
+ weak_factory_(this) {
+ base::trace_event::TraceLog::GetInstance()->AddAsyncEnabledStateObserver(
+ weak_factory_.GetWeakPtr());
+}
+
+AutoOpenCloseEvent::~AutoOpenCloseEvent() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ base::trace_event::TraceLog::GetInstance()->RemoveAsyncEnabledStateObserver(
+ this);
+}
+
+void AutoOpenCloseEvent::Begin() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ start_time_ = base::TimeTicks::Now();
+ TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP0(
+ category_, event_name_, static_cast<void*>(this), start_time_);
+}
+
+void AutoOpenCloseEvent::End() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ TRACE_EVENT_ASYNC_END0(category_, event_name_, static_cast<void*>(this));
+ start_time_ = base::TimeTicks();
+}
+
+void AutoOpenCloseEvent::OnTraceLogEnabled() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (start_time_.ToInternalValue() != 0)
+ TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP0(
+ category_, event_name_, static_cast<void*>(this), start_time_);
+}
+
+void AutoOpenCloseEvent::OnTraceLogDisabled() {}
+
+} // namespace trace_event
+} // namespace base
« no previous file with comments | « base/trace_event/auto_open_close_event.h ('k') | media/blink/video_frame_compositor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698