// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "media/base/scoped_async_trace.h" #include "base/memory/ptr_util.h" #include "base/trace_event/trace_event.h" namespace media { namespace { template struct Category {}; template <> struct Category { static constexpr const char* Name() { return "media"; } }; template <> struct Category { static constexpr const char* Name() { return TRACE_DISABLED_BY_DEFAULT("mediastream"); } }; template <> struct Category { static constexpr const char* Name() { return TRACE_DISABLED_BY_DEFAULT("video_and_image_capture"); } }; } // namespace template std::unique_ptr> TypedScopedAsyncTrace::CreateIfEnabled(const char* name) { bool enabled = false; TRACE_EVENT_CATEGORY_GROUP_ENABLED(Category::Name(), &enabled); return enabled ? base::WrapUnique(new TypedScopedAsyncTrace(name)) : nullptr; } template TypedScopedAsyncTrace::~TypedScopedAsyncTrace() { TRACE_EVENT_NESTABLE_ASYNC_END0(Category::Name(), name_, TRACE_ID_LOCAL(id_)); } template void TypedScopedAsyncTrace::AddStep(const char* step_name) { step_.reset(); // Ensure previous trace step closes first. step_ = base::WrapUnique(new TypedScopedAsyncTrace(step_name, this)); } template TypedScopedAsyncTrace::TypedScopedAsyncTrace(const char* name) : TypedScopedAsyncTrace(name, this) {} template TypedScopedAsyncTrace::TypedScopedAsyncTrace(const char* name, const void* id) : name_(name), id_(id) { TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(Category::Name(), name_, TRACE_ID_LOCAL(id_)); } template class MEDIA_EXPORT TypedScopedAsyncTrace; template class MEDIA_EXPORT TypedScopedAsyncTrace; template class MEDIA_EXPORT TypedScopedAsyncTrace; } // namespace media