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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/trace_event/auto_open_close_event.h"
6
7 #include "base/macros.h"
8 #include "base/time/time.h"
9 #include "base/trace_event/trace_event.h"
10
11 namespace base {
12 namespace trace_event {
13
14 AutoOpenCloseEvent::AutoOpenCloseEvent(AutoOpenCloseEvent::Type type,
15 const char* category, const char* event_name):
16 category_(category),
17 event_name_(event_name),
18 weak_factory_(this) {
19 base::trace_event::TraceLog::GetInstance()->AddAsyncEnabledStateObserver(
20 weak_factory_.GetWeakPtr());
21 }
22
23 AutoOpenCloseEvent::~AutoOpenCloseEvent() {
24 DCHECK(thread_checker_.CalledOnValidThread());
25 base::trace_event::TraceLog::GetInstance()->RemoveAsyncEnabledStateObserver(
26 this);
27 }
28
29 void AutoOpenCloseEvent::Begin() {
30 DCHECK(thread_checker_.CalledOnValidThread());
31 start_time_ = base::TimeTicks::Now();
32 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP0(
33 category_, event_name_, static_cast<void*>(this), start_time_);
34 }
35
36 void AutoOpenCloseEvent::End() {
37 DCHECK(thread_checker_.CalledOnValidThread());
38 TRACE_EVENT_ASYNC_END0(category_, event_name_, static_cast<void*>(this));
39 start_time_ = base::TimeTicks();
40 }
41
42 void AutoOpenCloseEvent::OnTraceLogEnabled() {
43 DCHECK(thread_checker_.CalledOnValidThread());
44 if (start_time_.ToInternalValue() != 0)
45 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP0(
46 category_, event_name_, static_cast<void*>(this), start_time_);
47 }
48
49 void AutoOpenCloseEvent::OnTraceLogDisabled() {}
50
51 } // namespace trace_event
52 } // namespace base
OLDNEW
« 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