1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
media / base / scoped_async_trace.cc [blame]
// 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 <TraceCategory category>
struct Category {};
template <>
struct Category<TraceCategory::kMedia> {
static constexpr const char* Name() { return "media"; }
};
template <>
struct Category<TraceCategory::kMediaStream> {
static constexpr const char* Name() {
return TRACE_DISABLED_BY_DEFAULT("mediastream");
}
};
template <>
struct Category<TraceCategory::kVideoAndImageCapture> {
static constexpr const char* Name() {
return TRACE_DISABLED_BY_DEFAULT("video_and_image_capture");
}
};
} // namespace
template <TraceCategory category>
std::unique_ptr<TypedScopedAsyncTrace<category>>
TypedScopedAsyncTrace<category>::CreateIfEnabled(const char* name) {
bool enabled = false;
TRACE_EVENT_CATEGORY_GROUP_ENABLED(Category<category>::Name(), &enabled);
return enabled ? base::WrapUnique(new TypedScopedAsyncTrace<category>(name))
: nullptr;
}
template <TraceCategory category>
TypedScopedAsyncTrace<category>::~TypedScopedAsyncTrace() {
TRACE_EVENT_NESTABLE_ASYNC_END0(Category<category>::Name(), name_,
TRACE_ID_LOCAL(id_));
}
template <TraceCategory category>
void TypedScopedAsyncTrace<category>::AddStep(const char* step_name) {
step_.reset(); // Ensure previous trace step closes first.
step_ = base::WrapUnique(new TypedScopedAsyncTrace(step_name, this));
}
template <TraceCategory category>
TypedScopedAsyncTrace<category>::TypedScopedAsyncTrace(const char* name)
: TypedScopedAsyncTrace<category>(name, this) {}
template <TraceCategory category>
TypedScopedAsyncTrace<category>::TypedScopedAsyncTrace(const char* name,
const void* id)
: name_(name), id_(id) {
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0(Category<category>::Name(), name_,
TRACE_ID_LOCAL(id_));
}
template class MEDIA_EXPORT TypedScopedAsyncTrace<TraceCategory::kMedia>;
template class MEDIA_EXPORT TypedScopedAsyncTrace<TraceCategory::kMediaStream>;
template class MEDIA_EXPORT
TypedScopedAsyncTrace<TraceCategory::kVideoAndImageCapture>;
} // namespace media