Chromium Code Reviews| 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..d011ad884daccabab0cb7bfc8a9e18b750fc17a7 |
| --- /dev/null |
| +++ b/base/trace_event/auto_open_close_event.cc |
| @@ -0,0 +1,56 @@ |
| +// 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()); |
| + // 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
|
| + // event names aren't string literals; they're passed in through |
| + // the constructor. |
| + 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
|
| + static_cast<void*>(this)); |
| + start_time_ = base::TimeTicks::Now(); |
| +} |
| + |
| +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_.ToInternalValue()); |
| +} |
| + |
| +void AutoOpenCloseEvent::OnTraceLogDisabled() {} |
| + |
| +} // namespace trace_event |
| +} // namespace base |