Chromium Code Reviews| Index: base/trace_event/persistent_async_event.cc |
| diff --git a/base/trace_event/persistent_async_event.cc b/base/trace_event/persistent_async_event.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f6366e316039e5be2c34ac8b3a83b6b3044034e1 |
| --- /dev/null |
| +++ b/base/trace_event/persistent_async_event.cc |
| @@ -0,0 +1,60 @@ |
| +// 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/persistent_async_event.h" |
| + |
| +#include "base/macros.h" |
| +#include "base/time/time.h" |
| +#include "base/trace_event/trace_event.h" |
| + |
| +namespace base { |
| + |
|
Primiano Tucci (use gerrit)
2016/09/15 10:08:29
nit: remove this extra line
alexandermont
2016/09/15 21:05:12
Done
|
| +namespace trace_event { |
| + |
| +PersistentAsyncEvent::PersistentAsyncEvent(PersistentAsyncEvent::Type type, |
| + const char* category, const char* event_name): |
| + active_(false), |
| + category_(category), |
| + event_name_(event_name), |
| + weak_factory_(this) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
|
Primiano Tucci (use gerrit)
2016/09/15 10:08:29
remove this line, as it is tautological.
The threa
alexandermont
2016/09/15 21:05:13
Done
|
| + base::trace_event::TraceLog::GetInstance()->AddAsyncEnabledStateObserver( |
| + weak_factory_.GetWeakPtr()); |
| +} |
| + |
| +PersistentAsyncEvent::~PersistentAsyncEvent() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + base::trace_event::TraceLog::GetInstance()->RemoveAsyncEnabledStateObserver( |
| + this); |
| +} |
| + |
| +void PersistentAsyncEvent::Begin() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
|
Primiano Tucci (use gerrit)
2016/09/15 10:08:29
oh I didn't think about enforce begin/end to be al
alexandermont
2016/09/15 21:05:13
okay
|
| + // We need to use the COPY version of the macro because the category and |
|
Primiano Tucci (use gerrit)
2016/09/15 10:08:29
nit: add a line between comments and the previous
|
| + // event names aren't string literals; they're passed in through |
| + // the constructor. |
| + TRACE_EVENT_COPY_ASYNC_BEGIN0(category_, event_name_, |
|
Primiano Tucci (use gerrit)
2016/09/15 10:08:29
I dupe my previou (unresolved) question:
Why _COPY
alexandermont
2016/09/15 21:05:13
Fixed
|
| + static_cast<void*>(this)); |
| + active_ = true; |
| + start_time_ = base::TimeTicks::Now(); |
| +} |
| + |
| +void PersistentAsyncEvent::End() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + TRACE_EVENT_COPY_ASYNC_END0(category_, event_name_, static_cast<void*>(this)); |
| + active_ = false; |
|
Primiano Tucci (use gerrit)
2016/09/15 10:08:29
just clear start_Time_?
alexandermont
2016/09/15 21:05:13
Done
|
| +} |
| + |
| +void PersistentAsyncEvent::OnTraceLogEnabled() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (active_) |
| + TRACE_EVENT_COPY_ASYNC_BEGIN_WITH_TIMESTAMP0( |
|
Primiano Tucci (use gerrit)
2016/09/15 10:08:29
ditto about s/_COPY_//
|
| + category_, event_name_, static_cast<void*>(this), |
| + start_time_.ToInternalValue()); |
|
Primiano Tucci (use gerrit)
2016/09/15 10:08:29
I think here you want InMicroseconds() not ToInter
alexandermont
2016/09/15 21:05:12
This is a TimeTicks value, not a TimeDelta value.
Primiano Tucci (use gerrit)
2016/09/15 22:06:25
ah right, my bad. do whatever we do for the other
|
| +} |
| + |
| +void PersistentAsyncEvent::OnTraceLogDisabled() {} |
| + |
| +} // namespace trace_event |
| +} // namespace base |