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 #ifndef SRC_TRACE_PROCESSOR_STORAGE_STATS_H_
18 #define SRC_TRACE_PROCESSOR_STORAGE_STATS_H_
19 
20 #include <stddef.h>
21 
22 namespace perfetto {
23 namespace trace_processor {
24 namespace stats {
25 
26 // Compile time list of parsing and processing stats.
27 // clang-format off
28 #define PERFETTO_TP_STATS(F)                                                   \
29   F(android_log_num_failed,             kSingle,  kError,    kTrace,    ""),   \
30   F(android_log_num_skipped,            kSingle,  kInfo,     kTrace,    ""),   \
31   F(android_log_num_total,              kSingle,  kInfo,     kTrace,    ""),   \
32   F(counter_events_out_of_order,        kSingle,  kError,    kAnalysis, ""),   \
33   F(deobfuscate_location_parse_error,   kSingle,  kError,    kTrace,    ""),   \
34   F(frame_timeline_event_parser_errors, kSingle,  kInfo,     kAnalysis, ""),   \
35   F(ftrace_bundle_tokenizer_errors,     kSingle,  kError,    kAnalysis, ""),   \
36   F(ftrace_cpu_bytes_read_begin,        kIndexed, kInfo,     kTrace,    ""),   \
37   F(ftrace_cpu_bytes_read_end,          kIndexed, kInfo,     kTrace,    ""),   \
38   F(ftrace_cpu_commit_overrun_begin,    kIndexed, kError,    kTrace,    ""),   \
39   F(ftrace_cpu_commit_overrun_end,      kIndexed, kError,    kTrace,    ""),   \
40   F(ftrace_cpu_dropped_events_begin,    kIndexed, kError,    kTrace,    ""),   \
41   F(ftrace_cpu_dropped_events_end,      kIndexed, kError,    kTrace,    ""),   \
42   F(ftrace_cpu_entries_begin,           kIndexed, kInfo,     kTrace,    ""),   \
43   F(ftrace_cpu_entries_end,             kIndexed, kInfo,     kTrace,    ""),   \
44   F(ftrace_cpu_now_ts_begin,            kIndexed, kInfo,     kTrace,    ""),   \
45   F(ftrace_cpu_now_ts_end,              kIndexed, kInfo,     kTrace,    ""),   \
46   F(ftrace_cpu_oldest_event_ts_begin,   kIndexed, kInfo,     kTrace,    ""),   \
47   F(ftrace_cpu_oldest_event_ts_end,     kIndexed, kInfo,     kTrace,    ""),   \
48   F(ftrace_cpu_overrun_begin,           kIndexed, kInfo,     kTrace,    ""),   \
49   F(ftrace_cpu_overrun_end,             kIndexed, kDataLoss, kTrace,           \
50       "The kernel ftrace buffer cannot keep up with the rate of events "       \
51       "produced. Indexed by CPU. This is likely a misconfiguration."),         \
52   F(ftrace_cpu_read_events_begin,       kIndexed, kInfo,     kTrace,    ""),   \
53   F(ftrace_cpu_read_events_end,         kIndexed, kInfo,     kTrace,    ""),   \
54   F(fuchsia_non_numeric_counters,       kSingle,  kError,    kAnalysis, ""),   \
55   F(fuchsia_timestamp_overflow,         kSingle,  kError,    kAnalysis, ""),   \
56   F(fuchsia_invalid_event,              kSingle,  kError,    kAnalysis, ""),   \
57   F(gpu_counters_invalid_spec,          kSingle,  kError,    kAnalysis, ""),   \
58   F(gpu_counters_missing_spec,          kSingle,  kError,    kAnalysis, ""),   \
59   F(gpu_render_stage_parser_errors,     kSingle,  kError,    kAnalysis, ""),   \
60   F(graphics_frame_event_parser_errors, kSingle,  kInfo,     kAnalysis, ""),   \
61   F(guess_trace_type_duration_ns,       kSingle,  kInfo,     kAnalysis, ""),   \
62   F(interned_data_tokenizer_errors,     kSingle,  kInfo,     kAnalysis, ""),   \
63   F(invalid_clock_snapshots,            kSingle,  kError,    kAnalysis, ""),   \
64   F(invalid_cpu_times,                  kSingle,  kError,    kAnalysis, ""),   \
65   F(meminfo_unknown_keys,               kSingle,  kError,    kAnalysis, ""),   \
66   F(mismatched_sched_switch_tids,       kSingle,  kError,    kAnalysis, ""),   \
67   F(mm_unknown_type,                    kSingle,  kError,    kAnalysis, ""),   \
68   F(parse_trace_duration_ns,            kSingle,  kInfo,     kAnalysis, ""),   \
69   F(power_rail_unknown_index,           kSingle,  kError,    kTrace,    ""),   \
70   F(proc_stat_unknown_counters,         kSingle,  kError,    kAnalysis, ""),   \
71   F(rss_stat_unknown_keys,              kSingle,  kError,    kAnalysis, ""),   \
72   F(rss_stat_negative_size,             kSingle,  kInfo,     kAnalysis, ""),   \
73   F(rss_stat_unknown_thread_for_mm_id,  kSingle,  kInfo,     kAnalysis, ""),   \
74   F(sched_switch_out_of_order,          kSingle,  kError,    kAnalysis, ""),   \
75   F(slice_out_of_order,                 kSingle,  kError,    kAnalysis, ""),   \
76   F(flow_duplicate_id,                  kSingle,  kError,    kTrace,    ""),   \
77   F(flow_no_enclosing_slice,            kSingle,  kError,    kTrace,    ""),   \
78   F(flow_step_without_start,            kSingle,  kInfo,     kTrace,    ""),   \
79   F(flow_end_without_start,             kSingle,  kInfo,     kTrace,    ""),   \
80   F(flow_invalid_id,                    kSingle,  kError,    kTrace,    ""),   \
81   F(flow_without_direction,             kSingle,  kError,    kTrace,    ""),   \
82   F(stackprofile_invalid_string_id,     kSingle,  kError,    kTrace,    ""),   \
83   F(stackprofile_invalid_mapping_id,    kSingle,  kError,    kTrace,    ""),   \
84   F(stackprofile_invalid_frame_id,      kSingle,  kError,    kTrace,    ""),   \
85   F(stackprofile_invalid_callstack_id,  kSingle,  kError,    kTrace,    ""),   \
86   F(stackprofile_parser_error,          kSingle,  kError,    kTrace,    ""),   \
87   F(systrace_parse_failure,             kSingle,  kError,    kAnalysis, ""),   \
88   F(task_state_invalid,                 kSingle,  kError,    kAnalysis, ""),   \
89   F(traced_buf_buffer_size,             kIndexed, kInfo,     kTrace,    ""),   \
90   F(traced_buf_bytes_overwritten,       kIndexed, kInfo,     kTrace,    ""),   \
91   F(traced_buf_bytes_read,              kIndexed, kInfo,     kTrace,    ""),   \
92   F(traced_buf_bytes_written,           kIndexed, kInfo,     kTrace,    ""),   \
93   F(traced_buf_chunks_discarded,        kIndexed, kInfo,     kTrace,    ""),   \
94   F(traced_buf_chunks_overwritten,      kIndexed, kInfo,     kTrace,    ""),   \
95   F(traced_buf_chunks_read,             kIndexed, kInfo,     kTrace,    ""),   \
96   F(traced_buf_chunks_rewritten,        kIndexed, kInfo,     kTrace,    ""),   \
97   F(traced_buf_chunks_written,          kIndexed, kInfo,     kTrace,    ""),   \
98   F(traced_buf_chunks_committed_out_of_order,                                  \
99                                         kIndexed, kInfo,     kTrace,    ""),   \
100   F(traced_buf_padding_bytes_cleared,   kIndexed, kInfo,     kTrace,    ""),   \
101   F(traced_buf_padding_bytes_written,   kIndexed, kInfo,     kTrace,    ""),   \
102   F(traced_buf_patches_failed,          kIndexed, kDataLoss, kTrace,    ""),   \
103   F(traced_buf_patches_succeeded,       kIndexed, kInfo,     kTrace,    ""),   \
104   F(traced_buf_readaheads_failed,       kIndexed, kInfo,     kTrace,    ""),   \
105   F(traced_buf_readaheads_succeeded,    kIndexed, kInfo,     kTrace,    ""),   \
106   F(traced_buf_trace_writer_packet_loss,kIndexed, kDataLoss, kTrace,    ""),   \
107   F(traced_buf_write_wrap_count,        kIndexed, kInfo,     kTrace,    ""),   \
108   F(traced_chunks_discarded,            kSingle,  kInfo,     kTrace,    ""),   \
109   F(traced_data_sources_registered,     kSingle,  kInfo,     kTrace,    ""),   \
110   F(traced_data_sources_seen,           kSingle,  kInfo,     kTrace,    ""),   \
111   F(traced_patches_discarded,           kSingle,  kInfo,     kTrace,    ""),   \
112   F(traced_producers_connected,         kSingle,  kInfo,     kTrace,    ""),   \
113   F(traced_producers_seen,              kSingle,  kInfo,     kTrace,    ""),   \
114   F(traced_total_buffers,               kSingle,  kInfo,     kTrace,    ""),   \
115   F(traced_tracing_sessions,            kSingle,  kInfo,     kTrace,    ""),   \
116   F(track_event_parser_errors,          kSingle,  kInfo,     kAnalysis, ""),   \
117   F(track_event_tokenizer_errors,       kSingle,  kInfo,     kAnalysis, ""),   \
118   F(tokenizer_skipped_packets,          kSingle,  kInfo,     kAnalysis, ""),   \
119   F(vmstat_unknown_keys,                kSingle,  kError,    kAnalysis, ""),   \
120   F(vulkan_allocations_invalid_string_id,                                      \
121                                         kSingle,  kError,    kTrace,    ""),   \
122   F(clock_sync_failure,                 kSingle,  kError,    kAnalysis, ""),   \
123   F(clock_sync_cache_miss,              kSingle,  kInfo,     kAnalysis, ""),   \
124   F(process_tracker_errors,             kSingle,  kError,    kAnalysis, ""),   \
125   F(json_tokenizer_failure,             kSingle,  kError,    kTrace,    ""),   \
126   F(json_parser_failure,                kSingle,  kError,    kTrace,    ""),   \
127   F(heap_graph_invalid_string_id,       kIndexed, kError,    kTrace,    ""),   \
128   F(heap_graph_non_finalized_graph,     kSingle,  kError,    kTrace,    ""),   \
129   F(heap_graph_malformed_packet,        kIndexed, kError,    kTrace,    ""),   \
130   F(heap_graph_missing_packet,          kIndexed, kError,    kTrace,    ""),   \
131   F(heapprofd_buffer_corrupted,         kIndexed, kError,    kTrace,           \
132       "Shared memory buffer corrupted. This is a bug or memory corruption "    \
133       "in the target. Indexed by target upid."),                               \
134   F(heapprofd_hit_guardrail,            kIndexed, kError,    kTrace,           \
135       "HeapprofdConfig specified a CPU or Memory Guardrail that was hit. "     \
136       "Indexed by target upid."),                                              \
137   F(heapprofd_buffer_overran,           kIndexed, kDataLoss, kTrace,           \
138       "The shared memory buffer between the target and heapprofd overran. "    \
139       "The profile was truncated early. Indexed by target upid."),             \
140   F(heapprofd_client_error,             kIndexed, kError,    kTrace,           \
141       "The heapprofd client ran into a problem and disconnected. "             \
142       "See profile_packet.proto  for error codes."),                           \
143   F(heapprofd_client_disconnected,      kIndexed, kInfo,     kTrace,    ""),   \
144   F(heapprofd_malformed_packet,         kIndexed, kError,    kTrace,    ""),   \
145   F(heapprofd_missing_packet,           kSingle,  kError,    kTrace,    ""),   \
146   F(heapprofd_rejected_concurrent,      kIndexed, kError,    kTrace,           \
147       "The target was already profiled by another tracing session, so the "    \
148       "profile was not taken. Indexed by target upid."),                       \
149   F(heapprofd_non_finalized_profile,    kSingle,  kError,    kTrace,    ""),   \
150   F(heapprofd_sampling_interval_adjusted,                                      \
151       kIndexed, kInfo,    kTrace,                                              \
152       "By how many byes the interval for PID was increased "                   \
153       "by adaptive sampling."),                                                \
154   F(heapprofd_unwind_time_us,           kIndexed, kInfo,     kTrace,           \
155       "Time spent unwinding callstacks."),                                     \
156   F(heapprofd_unwind_samples,           kIndexed, kInfo,     kTrace,           \
157       "Number of samples unwound."),                                           \
158   F(heapprofd_client_spinlock_blocked,  kIndexed, kInfo,     kTrace,           \
159        "Time (us) the heapprofd client was blocked on the spinlock."),         \
160   F(heapprofd_last_profile_timestamp,   kIndexed, kInfo,     kTrace,           \
161        "The timestamp (in trace time) for the last dump for a process"),       \
162   F(metatrace_overruns,                 kSingle,  kError,    kTrace,    ""),   \
163   F(packages_list_has_parse_errors,     kSingle,  kError,    kTrace,    ""),   \
164   F(packages_list_has_read_errors,      kSingle,  kError,    kTrace,    ""),   \
165   F(compact_sched_has_parse_errors,     kSingle,  kError,    kTrace,    ""),   \
166   F(misplaced_end_event,                kSingle,  kDataLoss, kAnalysis, ""),   \
167   F(sched_waking_out_of_order,          kSingle,  kError,    kAnalysis, ""),   \
168   F(compact_sched_switch_skipped,       kSingle,  kInfo,     kAnalysis, ""),   \
169   F(compact_sched_waking_skipped,       kSingle,  kInfo,     kAnalysis, ""),   \
170   F(empty_chrome_metadata,              kSingle,  kError,    kTrace,    ""),   \
171   F(perf_cpu_lost_records,              kIndexed, kDataLoss, kTrace,    ""),   \
172   F(ninja_parse_errors,                 kSingle,  kError,    kTrace,    ""),   \
173   F(perf_samples_skipped,               kSingle,  kInfo,     kTrace,    ""),   \
174   F(perf_samples_skipped_dataloss,      kSingle,  kDataLoss, kTrace,    ""),   \
175   F(memory_snapshot_parser_failure,     kSingle,  kError,    kAnalysis, ""),   \
176   F(thread_time_in_state_out_of_order,  kSingle,  kError,    kAnalysis, ""),   \
177   F(thread_time_in_state_unknown_cpu_freq,                                     \
178                                         kSingle,  kError,    kAnalysis, ""),   \
179   F(ftrace_packet_before_tracing_start, kSingle,  kInfo,     kAnalysis,        \
180       "An ftrace packet was seen before the tracing start timestamp from "     \
181       "the tracing service. This happens if the ftrace buffers were not "      \
182       "cleared properly. These packets are silently dropped by trace "         \
183       "processor."),                                                           \
184   F(perf_guardrail_stop_ts,             kIndexed, kDataLoss, kTrace,    "")
185 // clang-format on
186 
187 enum Type {
188   kSingle,  // Single-value property, one value per key.
189   kIndexed  // Indexed property, multiple value per key (e.g. cpu_stats[1]).
190 };
191 
192 enum Severity {
193   kInfo,      // Diagnostic counters
194   kDataLoss,  // Correct operation that still resulted in data loss
195   kError      // If any kError counter is > 0 trace_processor_shell will
196               // raise an error. This is *not* surfaced in the web UI.
197               // TODO(b/148587181): Surface these errors in the UI.
198 };
199 
200 enum Source {
201   // The counter is collected when recording the trace on-device and is just
202   // being reflected in the stats table.
203   kTrace,
204 
205   // The counter is genrated when importing / processing the trace in the trace
206   // processor.
207   kAnalysis
208 };
209 
210 // Ignore GCC warning about a missing argument for a variadic macro parameter.
211 #if defined(__GNUC__) || defined(__clang__)
212 #pragma GCC system_header
213 #endif
214 
215 // Declares an enum of literals (one for each stat). The enum values of each
216 // literal corresponds to the string index in the arrays below.
217 #define PERFETTO_TP_STATS_ENUM(name, ...) name
218 enum KeyIDs : size_t { PERFETTO_TP_STATS(PERFETTO_TP_STATS_ENUM), kNumKeys };
219 
220 // The code below declares an array for each property (name, type, ...).
221 
222 #define PERFETTO_TP_STATS_NAME(name, ...) #name
223 constexpr char const* kNames[] = {PERFETTO_TP_STATS(PERFETTO_TP_STATS_NAME)};
224 
225 #define PERFETTO_TP_STATS_TYPE(_, type, ...) type
226 constexpr Type kTypes[] = {PERFETTO_TP_STATS(PERFETTO_TP_STATS_TYPE)};
227 
228 #define PERFETTO_TP_STATS_SEVERITY(_, __, severity, ...) severity
229 constexpr Severity kSeverities[] = {
230     PERFETTO_TP_STATS(PERFETTO_TP_STATS_SEVERITY)};
231 
232 #define PERFETTO_TP_STATS_SOURCE(_, __, ___, source, ...) source
233 constexpr Source kSources[] = {PERFETTO_TP_STATS(PERFETTO_TP_STATS_SOURCE)};
234 
235 #define PERFETTO_TP_STATS_DESCRIPTION(_, __, ___, ____, descr, ...) descr
236 constexpr char const* kDescriptions[] = {
237     PERFETTO_TP_STATS(PERFETTO_TP_STATS_DESCRIPTION)};
238 
239 }  // namespace stats
240 }  // namespace trace_processor
241 }  // namespace perfetto
242 
243 #endif  // SRC_TRACE_PROCESSOR_STORAGE_STATS_H_
244