xref: /aosp_15_r20/external/perfetto/src/trace_processor/importers/common/tracks_internal.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2024 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 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_TRACKS_INTERNAL_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_TRACKS_INTERNAL_H_
19 
20 #include <array>
21 #include <cstddef>
22 #include <string_view>
23 #include <tuple>
24 
25 #include "perfetto/ext/base/hash.h"
26 #include "src/trace_processor/containers/string_pool.h"
27 
28 namespace perfetto::trace_processor::tracks {
29 
30 template <typename... T>
31 using DimensionsT = std::tuple<T...>;
32 
33 struct DimensionBlueprintBase {
34   std::string_view name;
35   bool is_cpu;
36 };
37 
38 template <typename T>
39 struct DimensionBlueprintT : DimensionBlueprintBase {
40   using type = T;
41 };
42 
43 struct NameBlueprintT {
44   struct Auto {
45     using name_t = nullptr_t;
46   };
47   struct Static {
48     using name_t = nullptr_t;
49     const char* name;
50   };
51   struct Dynamic {
52     using name_t = StringPool::Id;
53   };
54   struct FnBase {
55     using name_t = nullptr_t;
56   };
57   template <typename F>
58   struct Fn : FnBase {
59     F fn;
60   };
61 };
62 
63 struct BlueprintBase {
64   std::string_view event_type;
65   std::string_view classification;
66   base::Hasher hasher;
67   std::array<DimensionBlueprintBase, 8> dimension_blueprints;
68 };
69 
70 template <typename NB, typename UB, typename... DB>
71 struct BlueprintT : BlueprintBase {
72   using name_blueprint_t = NB;
73   using unit_blueprint_t = UB;
74   using name_t = typename NB::name_t;
75   using unit_t = typename UB::unit_t;
76   using dimensions_t = DimensionsT<typename DB::type...>;
77   name_blueprint_t name_blueprint;
78   unit_blueprint_t unit_blueprint;
79 };
80 
81 template <typename... T>
82 using DimensionBlueprintsT = std::tuple<T...>;
83 
84 struct UnitBlueprintT {
85   struct Unknown {
86     using unit_t = nullptr_t;
87   };
88   struct Static {
89     using unit_t = const char*;
90     const char* name;
91   };
92   struct Dynamic {
93     using unit_t = StringPool::Id;
94   };
95 };
96 
97 #define PERFETTO_TP_TRACKS(F)                    \
98   F(android_energy_estimation_breakdown_per_uid) \
99   F(android_energy_estimation_breakdown)         \
100   F(android_gpu_work_period)                     \
101   F(android_lmk)                                 \
102   F(block_io)                                    \
103   F(chrome_process_instant)                      \
104   F(cpu_capacity)                                \
105   F(cpu_frequency_throttle)                      \
106   F(cpu_frequency)                               \
107   F(cpu_funcgraph)                               \
108   F(cpu_idle_state)                              \
109   F(cpu_idle)                                    \
110   F(cpu_irq)                                     \
111   F(cpu_nr_running)                              \
112   F(cpu_mali_irq)                                \
113   F(cpu_max_frequency_limit)                     \
114   F(cpu_min_frequency_limit)                     \
115   F(cpu_napi_gro)                                \
116   F(cpu_softirq)                                 \
117   F(cpu_stat)                                    \
118   F(cpu_utilization)                             \
119   F(gpu_frequency)                               \
120   F(interconnect_events)                         \
121   F(irq_counter)                                 \
122   F(legacy_chrome_global_instants)               \
123   F(linux_device_frequency)                      \
124   F(linux_rpm)                                   \
125   F(pixel_cpm_trace)                             \
126   F(pkvm_hypervisor)                             \
127   F(softirq_counter)                             \
128   F(thread)                                      \
129   F(track_event)                                 \
130   F(triggers)                                    \
131   F(unknown)
132 
133 #define PERFETTO_TP_TRACKS_CLASSIFICATION_ENUM(name) name,
134 enum TrackClassification : size_t {
135   PERFETTO_TP_TRACKS(PERFETTO_TP_TRACKS_CLASSIFICATION_ENUM)
136 };
137 
138 namespace internal {
139 
140 #define PERFETTO_TP_TRACKS_CLASSIFICATION_STR(name) #name,
141 constexpr std::array kTrackClassificationStr{
142     PERFETTO_TP_TRACKS(PERFETTO_TP_TRACKS_CLASSIFICATION_STR)};
143 
144 }  // namespace internal
145 
ToString(TrackClassification c)146 constexpr const char* ToString(TrackClassification c) {
147   return internal::kTrackClassificationStr[c];
148 }
149 
150 }  // namespace perfetto::trace_processor::tracks
151 
152 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_COMMON_TRACKS_INTERNAL_H_
153