OLD | NEW |
---|---|
(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 // We need to use the COPY version of the macro because the category and | |
oystein (OOO til 10th of July)
2016/09/16 22:22:16
Outdated comment.
alexandermont
2016/09/19 20:28:50
Removed
| |
32 // event names aren't string literals; they're passed in through | |
33 // the constructor. | |
34 TRACE_EVENT_ASYNC_BEGIN0(category_, event_name_, | |
oystein (OOO til 10th of July)
2016/09/16 22:22:16
Maybe use TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP0
alexandermont
2016/09/19 20:28:50
Done
| |
35 static_cast<void*>(this)); | |
36 start_time_ = base::TimeTicks::Now(); | |
37 } | |
38 | |
39 void AutoOpenCloseEvent::End() { | |
40 DCHECK(thread_checker_.CalledOnValidThread()); | |
41 TRACE_EVENT_ASYNC_END0(category_, event_name_, static_cast<void*>(this)); | |
42 start_time_ = base::TimeTicks(); | |
43 } | |
44 | |
45 void AutoOpenCloseEvent::OnTraceLogEnabled() { | |
46 DCHECK(thread_checker_.CalledOnValidThread()); | |
47 if (start_time_.ToInternalValue() != 0) | |
48 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP0( | |
49 category_, event_name_, static_cast<void*>(this), | |
50 start_time_.ToInternalValue()); | |
51 } | |
52 | |
53 void AutoOpenCloseEvent::OnTraceLogDisabled() {} | |
54 | |
55 } // namespace trace_event | |
56 } // namespace base | |
OLD | NEW |