• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_bytes_read_delta,        kIndexed, kInfo,     kTrace,    ""),   \
39   F(ftrace_cpu_commit_overrun_begin,    kIndexed, kInfo,     kTrace,    ""),   \
40   F(ftrace_cpu_commit_overrun_end,      kIndexed, kInfo,     kTrace,    ""),   \
41   F(ftrace_cpu_commit_overrun_delta,    kIndexed, kError,    kTrace,    ""),   \
42   F(ftrace_cpu_dropped_events_begin,    kIndexed, kInfo,     kTrace,    ""),   \
43   F(ftrace_cpu_dropped_events_end,      kIndexed, kInfo,     kTrace,    ""),   \
44   F(ftrace_cpu_dropped_events_delta,    kIndexed, kError,    kTrace,    ""),   \
45   F(ftrace_cpu_entries_begin,           kIndexed, kInfo,     kTrace,    ""),   \
46   F(ftrace_cpu_entries_end,             kIndexed, kInfo,     kTrace,    ""),   \
47   F(ftrace_cpu_entries_delta,           kIndexed, kInfo,     kTrace,    ""),   \
48   F(ftrace_cpu_now_ts_begin,            kIndexed, kInfo,     kTrace,    ""),   \
49   F(ftrace_cpu_now_ts_end,              kIndexed, kInfo,     kTrace,    ""),   \
50   F(ftrace_cpu_oldest_event_ts_begin,   kIndexed, kInfo,     kTrace,    ""),   \
51   F(ftrace_cpu_oldest_event_ts_end,     kIndexed, kInfo,     kTrace,    ""),   \
52   F(ftrace_cpu_overrun_begin,           kIndexed, kInfo,     kTrace,    ""),   \
53   F(ftrace_cpu_overrun_end,             kIndexed, kInfo,     kTrace,    ""),   \
54   F(ftrace_cpu_overrun_delta,           kIndexed, kDataLoss, kTrace,           \
55       "The kernel ftrace buffer cannot keep up with the rate of events "       \
56       "produced. Indexed by CPU. This is likely a misconfiguration."),         \
57   F(ftrace_cpu_read_events_begin,       kIndexed, kInfo,     kTrace,    ""),   \
58   F(ftrace_cpu_read_events_end,         kIndexed, kInfo,     kTrace,    ""),   \
59   F(ftrace_cpu_read_events_delta,       kIndexed, kInfo,     kTrace,    ""),   \
60   F(ftrace_setup_errors,                kSingle,  kError,    kTrace,           \
61   "One or more atrace/ftrace categories were not found or failed to enable. "  \
62   "See ftrace_setup_errors in the metadata table for more details."),          \
63   F(fuchsia_non_numeric_counters,       kSingle,  kError,    kAnalysis, ""),   \
64   F(fuchsia_timestamp_overflow,         kSingle,  kError,    kAnalysis, ""),   \
65   F(fuchsia_invalid_event,              kSingle,  kError,    kAnalysis, ""),   \
66   F(gpu_counters_invalid_spec,          kSingle,  kError,    kAnalysis, ""),   \
67   F(gpu_counters_missing_spec,          kSingle,  kError,    kAnalysis, ""),   \
68   F(gpu_render_stage_parser_errors,     kSingle,  kError,    kAnalysis, ""),   \
69   F(graphics_frame_event_parser_errors, kSingle,  kInfo,     kAnalysis, ""),   \
70   F(guess_trace_type_duration_ns,       kSingle,  kInfo,     kAnalysis, ""),   \
71   F(interned_data_tokenizer_errors,     kSingle,  kInfo,     kAnalysis, ""),   \
72   F(invalid_clock_snapshots,            kSingle,  kError,    kAnalysis, ""),   \
73   F(invalid_cpu_times,                  kSingle,  kError,    kAnalysis, ""),   \
74   F(meminfo_unknown_keys,               kSingle,  kError,    kAnalysis, ""),   \
75   F(mismatched_sched_switch_tids,       kSingle,  kError,    kAnalysis, ""),   \
76   F(mm_unknown_type,                    kSingle,  kError,    kAnalysis, ""),   \
77   F(parse_trace_duration_ns,            kSingle,  kInfo,     kAnalysis, ""),   \
78   F(power_rail_unknown_index,           kSingle,  kError,    kTrace,    ""),   \
79   F(proc_stat_unknown_counters,         kSingle,  kError,    kAnalysis, ""),   \
80   F(rss_stat_unknown_keys,              kSingle,  kError,    kAnalysis, ""),   \
81   F(rss_stat_negative_size,             kSingle,  kInfo,     kAnalysis, ""),   \
82   F(rss_stat_unknown_thread_for_mm_id,  kSingle,  kInfo,     kAnalysis, ""),   \
83   F(sched_switch_out_of_order,          kSingle,  kError,    kAnalysis, ""),   \
84   F(slice_out_of_order,                 kSingle,  kError,    kAnalysis, ""),   \
85   F(flow_duplicate_id,                  kSingle,  kError,    kTrace,    ""),   \
86   F(flow_no_enclosing_slice,            kSingle,  kError,    kTrace,    ""),   \
87   F(flow_step_without_start,            kSingle,  kInfo,     kTrace,    ""),   \
88   F(flow_end_without_start,             kSingle,  kInfo,     kTrace,    ""),   \
89   F(flow_invalid_id,                    kSingle,  kError,    kTrace,    ""),   \
90   F(flow_without_direction,             kSingle,  kError,    kTrace,    ""),   \
91   F(stackprofile_invalid_string_id,     kSingle,  kError,    kTrace,    ""),   \
92   F(stackprofile_invalid_mapping_id,    kSingle,  kError,    kTrace,    ""),   \
93   F(stackprofile_invalid_frame_id,      kSingle,  kError,    kTrace,    ""),   \
94   F(stackprofile_invalid_callstack_id,  kSingle,  kError,    kTrace,    ""),   \
95   F(stackprofile_parser_error,          kSingle,  kError,    kTrace,    ""),   \
96   F(systrace_parse_failure,             kSingle,  kError,    kAnalysis, ""),   \
97   F(task_state_invalid,                 kSingle,  kError,    kAnalysis, ""),   \
98   F(traced_buf_abi_violations,          kIndexed, kDataLoss, kTrace,    ""),   \
99   F(traced_buf_buffer_size,             kIndexed, kInfo,     kTrace,    ""),   \
100   F(traced_buf_bytes_overwritten,       kIndexed, kInfo,     kTrace,    ""),   \
101   F(traced_buf_bytes_read,              kIndexed, kInfo,     kTrace,    ""),   \
102   F(traced_buf_bytes_written,           kIndexed, kInfo,     kTrace,    ""),   \
103   F(traced_buf_chunks_discarded,        kIndexed, kInfo,     kTrace,    ""),   \
104   F(traced_buf_chunks_overwritten,      kIndexed, kInfo,     kTrace,    ""),   \
105   F(traced_buf_chunks_read,             kIndexed, kInfo,     kTrace,    ""),   \
106   F(traced_buf_chunks_rewritten,        kIndexed, kInfo,     kTrace,    ""),   \
107   F(traced_buf_chunks_written,          kIndexed, kInfo,     kTrace,    ""),   \
108   F(traced_buf_chunks_committed_out_of_order,                                  \
109                                         kIndexed, kInfo,     kTrace,    ""),   \
110   F(traced_buf_padding_bytes_cleared,   kIndexed, kInfo,     kTrace,    ""),   \
111   F(traced_buf_padding_bytes_written,   kIndexed, kInfo,     kTrace,    ""),   \
112   F(traced_buf_patches_failed,          kIndexed, kDataLoss, kTrace,    ""),   \
113   F(traced_buf_patches_succeeded,       kIndexed, kInfo,     kTrace,    ""),   \
114   F(traced_buf_readaheads_failed,       kIndexed, kInfo,     kTrace,    ""),   \
115   F(traced_buf_readaheads_succeeded,    kIndexed, kInfo,     kTrace,    ""),   \
116   F(traced_buf_trace_writer_packet_loss,kIndexed, kDataLoss, kTrace,    ""),   \
117   F(traced_buf_write_wrap_count,        kIndexed, kInfo,     kTrace,    ""),   \
118   F(traced_chunks_discarded,            kSingle,  kInfo,     kTrace,    ""),   \
119   F(traced_data_sources_registered,     kSingle,  kInfo,     kTrace,    ""),   \
120   F(traced_data_sources_seen,           kSingle,  kInfo,     kTrace,    ""),   \
121   F(traced_final_flush_failed,          kSingle,  kDataLoss, kTrace,    ""),   \
122   F(traced_final_flush_succeeded,       kSingle,  kInfo,     kTrace,    ""),   \
123   F(traced_flushes_failed,              kSingle,  kDataLoss, kTrace,    ""),   \
124   F(traced_flushes_requested,           kSingle,  kInfo,     kTrace,    ""),   \
125   F(traced_flushes_succeeded,           kSingle,  kInfo,     kTrace,    ""),   \
126   F(traced_patches_discarded,           kSingle,  kInfo,     kTrace,    ""),   \
127   F(traced_producers_connected,         kSingle,  kInfo,     kTrace,    ""),   \
128   F(traced_producers_seen,              kSingle,  kInfo,     kTrace,    ""),   \
129   F(traced_total_buffers,               kSingle,  kInfo,     kTrace,    ""),   \
130   F(traced_tracing_sessions,            kSingle,  kInfo,     kTrace,    ""),   \
131   F(track_event_parser_errors,          kSingle,  kInfo,     kAnalysis, ""),   \
132   F(track_event_tokenizer_errors,       kSingle,  kInfo,     kAnalysis, ""),   \
133   F(tokenizer_skipped_packets,          kSingle,  kInfo,     kAnalysis, ""),   \
134   F(vmstat_unknown_keys,                kSingle,  kError,    kAnalysis, ""),   \
135   F(vulkan_allocations_invalid_string_id,                                      \
136                                         kSingle,  kError,    kTrace,    ""),   \
137   F(clock_sync_failure,                 kSingle,  kError,    kAnalysis, ""),   \
138   F(clock_sync_cache_miss,              kSingle,  kInfo,     kAnalysis, ""),   \
139   F(process_tracker_errors,             kSingle,  kError,    kAnalysis, ""),   \
140   F(json_tokenizer_failure,             kSingle,  kError,    kTrace,    ""),   \
141   F(json_parser_failure,                kSingle,  kError,    kTrace,    ""),   \
142   F(json_display_time_unit,             kSingle,  kInfo,     kTrace,           \
143       "The displayTimeUnit key was set in the JSON trace. In some prior "      \
144       "versions of trace processor this key could effect how the trace "       \
145       "processor parsed timestamps and durations. In this version the key is " \
146       "ignored which more closely matches the bavahiour of catapult."),        \
147   F(heap_graph_invalid_string_id,       kIndexed, kError,    kTrace,    ""),   \
148   F(heap_graph_non_finalized_graph,     kSingle,  kError,    kTrace,    ""),   \
149   F(heap_graph_malformed_packet,        kIndexed, kError,    kTrace,    ""),   \
150   F(heap_graph_missing_packet,          kIndexed, kError,    kTrace,    ""),   \
151   F(heapprofd_buffer_corrupted,         kIndexed, kError,    kTrace,           \
152       "Shared memory buffer corrupted. This is a bug or memory corruption "    \
153       "in the target. Indexed by target upid."),                               \
154   F(heapprofd_hit_guardrail,            kIndexed, kError,    kTrace,           \
155       "HeapprofdConfig specified a CPU or Memory Guardrail that was hit. "     \
156       "Indexed by target upid."),                                              \
157   F(heapprofd_buffer_overran,           kIndexed, kDataLoss, kTrace,           \
158       "The shared memory buffer between the target and heapprofd overran. "    \
159       "The profile was truncated early. Indexed by target upid."),             \
160   F(heapprofd_client_error,             kIndexed, kError,    kTrace,           \
161       "The heapprofd client ran into a problem and disconnected. "             \
162       "See profile_packet.proto  for error codes."),                           \
163   F(heapprofd_client_disconnected,      kIndexed, kInfo,     kTrace,    ""),   \
164   F(heapprofd_malformed_packet,         kIndexed, kError,    kTrace,    ""),   \
165   F(heapprofd_missing_packet,           kSingle,  kError,    kTrace,    ""),   \
166   F(heapprofd_rejected_concurrent,      kIndexed, kError,    kTrace,           \
167       "The target was already profiled by another tracing session, so the "    \
168       "profile was not taken. Indexed by target upid."),                       \
169   F(heapprofd_non_finalized_profile,    kSingle,  kError,    kTrace,    ""),   \
170   F(heapprofd_sampling_interval_adjusted,                                      \
171       kIndexed, kInfo,    kTrace,                                              \
172       "By how many byes the interval for PID was increased "                   \
173       "by adaptive sampling."),                                                \
174   F(heapprofd_unwind_time_us,           kIndexed, kInfo,     kTrace,           \
175       "Time spent unwinding callstacks."),                                     \
176   F(heapprofd_unwind_samples,           kIndexed, kInfo,     kTrace,           \
177       "Number of samples unwound."),                                           \
178   F(heapprofd_client_spinlock_blocked,  kIndexed, kInfo,     kTrace,           \
179        "Time (us) the heapprofd client was blocked on the spinlock."),         \
180   F(heapprofd_last_profile_timestamp,   kIndexed, kInfo,     kTrace,           \
181        "The timestamp (in trace time) for the last dump for a process"),       \
182   F(metatrace_overruns,                 kSingle,  kError,    kTrace,    ""),   \
183   F(packages_list_has_parse_errors,     kSingle,  kError,    kTrace,    ""),   \
184   F(packages_list_has_read_errors,      kSingle,  kError,    kTrace,    ""),   \
185   F(compact_sched_has_parse_errors,     kSingle,  kError,    kTrace,    ""),   \
186   F(misplaced_end_event,                kSingle,  kDataLoss, kAnalysis, ""),   \
187   F(sched_waking_out_of_order,          kSingle,  kError,    kAnalysis, ""),   \
188   F(compact_sched_switch_skipped,       kSingle,  kInfo,     kAnalysis, ""),   \
189   F(compact_sched_waking_skipped,       kSingle,  kInfo,     kAnalysis, ""),   \
190   F(empty_chrome_metadata,              kSingle,  kError,    kTrace,    ""),   \
191   F(perf_cpu_lost_records,              kIndexed, kDataLoss, kTrace,    ""),   \
192   F(ninja_parse_errors,                 kSingle,  kError,    kTrace,    ""),   \
193   F(perf_samples_skipped,               kSingle,  kInfo,     kTrace,    ""),   \
194   F(perf_samples_skipped_dataloss,      kSingle,  kDataLoss, kTrace,    ""),   \
195   F(memory_snapshot_parser_failure,     kSingle,  kError,    kAnalysis, ""),   \
196   F(thread_time_in_state_out_of_order,  kSingle,  kError,    kAnalysis, ""),   \
197   F(thread_time_in_state_unknown_cpu_freq,                                     \
198                                         kSingle,  kError,    kAnalysis, ""),   \
199   F(ftrace_packet_before_tracing_start, kSingle,  kInfo,     kAnalysis,        \
200       "An ftrace packet was seen before the tracing start timestamp from "     \
201       "the tracing service. This happens if the ftrace buffers were not "      \
202       "cleared properly. These packets are silently dropped by trace "         \
203       "processor."),                                                           \
204   F(perf_guardrail_stop_ts,             kIndexed, kDataLoss, kTrace,    ""),   \
205   F(sorter_push_event_out_of_order,     kSingle, kError,     kTrace,           \
206       "Trace events are out of order event after sorting. This can happen "    \
207       "due to many factors including clock sync drift, producers emitting "    \
208       "events out of order or a bug in trace processor's logic of sorting."),  \
209   F(unknown_extension_fields,           kSingle,  kError,    kTrace,           \
210       "TraceEvent had unknown extension fields, which might result in "        \
211       "missing some arguments. You may need a newer version of trace "         \
212       "processor to parse them.")
213 // clang-format on
214 
215 enum Type {
216   kSingle,  // Single-value property, one value per key.
217   kIndexed  // Indexed property, multiple value per key (e.g. cpu_stats[1]).
218 };
219 
220 enum Severity {
221   kInfo,      // Diagnostic counters
222   kDataLoss,  // Correct operation that still resulted in data loss
223   kError      // If any kError counter is > 0 trace_processor_shell will
224               // raise an error. This is also surfaced in the web UI.
225 };
226 
227 enum Source {
228   // The counter is collected when recording the trace on-device and is just
229   // being reflected in the stats table.
230   kTrace,
231 
232   // The counter is genrated when importing / processing the trace in the trace
233   // processor.
234   kAnalysis
235 };
236 
237 // Ignore GCC warning about a missing argument for a variadic macro parameter.
238 #if defined(__GNUC__) || defined(__clang__)
239 #pragma GCC system_header
240 #endif
241 
242 // Declares an enum of literals (one for each stat). The enum values of each
243 // literal corresponds to the string index in the arrays below.
244 #define PERFETTO_TP_STATS_ENUM(name, ...) name
245 enum KeyIDs : size_t { PERFETTO_TP_STATS(PERFETTO_TP_STATS_ENUM), kNumKeys };
246 
247 // The code below declares an array for each property (name, type, ...).
248 
249 #define PERFETTO_TP_STATS_NAME(name, ...) #name
250 constexpr char const* kNames[] = {PERFETTO_TP_STATS(PERFETTO_TP_STATS_NAME)};
251 
252 #define PERFETTO_TP_STATS_TYPE(_, type, ...) type
253 constexpr Type kTypes[] = {PERFETTO_TP_STATS(PERFETTO_TP_STATS_TYPE)};
254 
255 #define PERFETTO_TP_STATS_SEVERITY(_, __, severity, ...) severity
256 constexpr Severity kSeverities[] = {
257     PERFETTO_TP_STATS(PERFETTO_TP_STATS_SEVERITY)};
258 
259 #define PERFETTO_TP_STATS_SOURCE(_, __, ___, source, ...) source
260 constexpr Source kSources[] = {PERFETTO_TP_STATS(PERFETTO_TP_STATS_SOURCE)};
261 
262 #define PERFETTO_TP_STATS_DESCRIPTION(_, __, ___, ____, descr, ...) descr
263 constexpr char const* kDescriptions[] = {
264     PERFETTO_TP_STATS(PERFETTO_TP_STATS_DESCRIPTION)};
265 
266 }  // namespace stats
267 }  // namespace trace_processor
268 }  // namespace perfetto
269 
270 #endif  // SRC_TRACE_PROCESSOR_STORAGE_STATS_H_
271