1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "perfetto/tracing/track_event_category_registry.h"
18
19 namespace perfetto {
20
21 // static
FromDynamicCategory(const char * name)22 Category Category::FromDynamicCategory(const char* name) {
23 if (GetNthNameSize(1, name, name)) {
24 Category group(Group(name));
25 PERFETTO_DCHECK(group.name);
26 return group;
27 }
28 Category category(name);
29 PERFETTO_DCHECK(category.name);
30 return category;
31 }
32
FromDynamicCategory(const DynamicCategory & dynamic_category)33 Category Category::FromDynamicCategory(
34 const DynamicCategory& dynamic_category) {
35 return FromDynamicCategory(dynamic_category.name.c_str());
36 }
37
38 namespace internal {
39
NullCategory(const perfetto::DynamicCategory &)40 perfetto::DynamicCategory NullCategory(const perfetto::DynamicCategory&) {
41 return perfetto::DynamicCategory{};
42 }
43
EnableCategoryForInstance(size_t category_index,uint32_t instance_index) const44 void TrackEventCategoryRegistry::EnableCategoryForInstance(
45 size_t category_index,
46 uint32_t instance_index) const {
47 PERFETTO_DCHECK(instance_index < kMaxDataSourceInstances);
48 PERFETTO_DCHECK(category_index < category_count_);
49 // Matches the acquire_load in DataSource::Trace().
50 state_storage_[category_index].fetch_or(
51 static_cast<uint8_t>(1u << instance_index), std::memory_order_release);
52 }
53
DisableCategoryForInstance(size_t category_index,uint32_t instance_index) const54 void TrackEventCategoryRegistry::DisableCategoryForInstance(
55 size_t category_index,
56 uint32_t instance_index) const {
57 PERFETTO_DCHECK(instance_index < kMaxDataSourceInstances);
58 PERFETTO_DCHECK(category_index < category_count_);
59 // Matches the acquire_load in DataSource::Trace().
60 state_storage_[category_index].fetch_and(
61 static_cast<uint8_t>(~(1u << instance_index)), std::memory_order_release);
62 }
63
64 } // namespace internal
65 } // namespace perfetto
66