Simplify error and data loss stats

Bug: b/133324726
Change-Id: I9fd657025f3f1ece3c46c02eeaf4ef559edcbf43
diff --git a/src/trace_processor/metrics/BUILD.gn b/src/trace_processor/metrics/BUILD.gn
index b4f88c0..ff282bc 100644
--- a/src/trace_processor/metrics/BUILD.gn
+++ b/src/trace_processor/metrics/BUILD.gn
@@ -15,7 +15,7 @@
 import("../../../gn/perfetto.gni")
 
 sql_files = [
-  "trace_statistics.sql",
+  "error_statistics.sql",
   "android/android_mem.sql",
   "android/android_mem_lmk.sql",
   "android/android_mem_proc_counters.sql",
diff --git a/src/trace_processor/metrics/trace_statistics.sql b/src/trace_processor/metrics/error_statistics.sql
similarity index 87%
rename from src/trace_processor/metrics/trace_statistics.sql
rename to src/trace_processor/metrics/error_statistics.sql
index 8f080d5..4313692 100644
--- a/src/trace_processor/metrics/trace_statistics.sql
+++ b/src/trace_processor/metrics/error_statistics.sql
@@ -20,9 +20,10 @@
   'idx', idx,
   'value', value) as entry
 FROM stats
-WHERE name NOT IN ('guess_trace_type_duration_ns', 'parse_trace_duration_ns');
+WHERE severity IN ('data_loss', 'error')
+AND value > 0;
 
-CREATE VIEW trace_statistics_output AS
+CREATE VIEW error_statistics_output AS
 SELECT TraceStatistics(
   'entry', (
     select RepeatedField(entry) from stats_view
diff --git a/src/trace_processor/metrics/metrics.descriptor.h b/src/trace_processor/metrics/metrics.descriptor.h
index 31a9e39..9b1e938 100644
--- a/src/trace_processor/metrics/metrics.descriptor.h
+++ b/src/trace_processor/metrics/metrics.descriptor.h
@@ -12,7 +12,7 @@
 // SHA1(tools/gen_binary_descriptors)
 // 750d7d8f95621b45d4b6430d6f8808087a8702e6
 // SHA1(protos/perfetto/metrics/metrics.proto)
-// 9fe94ca3168315a7a86cd521a3b34c25746b20c4
+// 6226cb6e0c62e7ead6368303c21b6cfce6c5b97b
 
 // This is the proto Metrics encoded as a ProtoFileDescriptor to allow
 // for reflection without libprotobuf full/non-lite protos.
@@ -301,12 +301,12 @@
      0x64, 0x72, 0x6f, 0x69, 0x64, 0x53, 0x74, 0x61, 0x72, 0x74, 0x75, 0x70,
      0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x52, 0x0e, 0x61, 0x6e, 0x64, 0x72,
      0x6f, 0x69, 0x64, 0x53, 0x74, 0x61, 0x72, 0x74, 0x75, 0x70, 0x12, 0x4b,
-     0x0a, 0x10, 0x74, 0x72, 0x61, 0x63, 0x65, 0x5f, 0x73, 0x74, 0x61, 0x74,
+     0x0a, 0x10, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x73, 0x74, 0x61, 0x74,
      0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b,
      0x32, 0x20, 0x2e, 0x70, 0x65, 0x72, 0x66, 0x65, 0x74, 0x74, 0x6f, 0x2e,
      0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x54, 0x72, 0x61, 0x63, 0x65,
      0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x52, 0x0f,
-     0x74, 0x72, 0x61, 0x63, 0x65, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74,
+     0x65, 0x72, 0x72, 0x6f, 0x72, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74,
      0x69, 0x63, 0x73, 0x42, 0x02, 0x48, 0x03}};
 
 }  // namespace perfetto
diff --git a/src/trace_processor/stats.h b/src/trace_processor/stats.h
index ad8914b..038981e 100644
--- a/src/trace_processor/stats.h
+++ b/src/trace_processor/stats.h
@@ -25,84 +25,84 @@
 
 // Compile time list of parsing and processing stats.
 // clang-format off
-#define PERFETTO_TP_STATS(F)                                                  \
-  F(android_log_num_failed,                     kSingle,  kError, kTrace),    \
-  F(android_log_num_skipped,                    kSingle,  kError, kTrace),    \
-  F(android_log_num_total,                      kSingle,  kInfo,  kTrace),    \
-  F(atrace_tgid_mismatch,                       kSingle,  kError, kTrace),    \
-  F(clock_snapshot_not_monotonic,               kSingle,  kError, kTrace),    \
-  F(counter_events_out_of_order,                kSingle,  kError, kAnalysis), \
-  F(ftrace_bundle_tokenizer_errors,             kSingle,  kError, kAnalysis), \
-  F(ftrace_cpu_bytes_read_begin,                kIndexed, kInfo,  kTrace),    \
-  F(ftrace_cpu_bytes_read_end,                  kIndexed, kInfo,  kTrace),    \
-  F(ftrace_cpu_commit_overrun_begin,            kIndexed, kError, kTrace),    \
-  F(ftrace_cpu_commit_overrun_end,              kIndexed, kError, kTrace),    \
-  F(ftrace_cpu_dropped_events_begin,            kIndexed, kError, kTrace),    \
-  F(ftrace_cpu_dropped_events_end,              kIndexed, kError, kTrace),    \
-  F(ftrace_cpu_entries_begin,                   kIndexed, kInfo,  kTrace),    \
-  F(ftrace_cpu_entries_end,                     kIndexed, kInfo,  kTrace),    \
-  F(ftrace_cpu_now_ts_begin,                    kIndexed, kInfo,  kTrace),    \
-  F(ftrace_cpu_now_ts_end,                      kIndexed, kInfo,  kTrace),    \
-  F(ftrace_cpu_oldest_event_ts_begin,           kIndexed, kInfo,  kTrace),    \
-  F(ftrace_cpu_oldest_event_ts_end,             kIndexed, kInfo,  kTrace),    \
-  F(ftrace_cpu_overrun_begin,                   kIndexed, kError, kTrace),    \
-  F(ftrace_cpu_overrun_end,                     kIndexed, kError, kTrace),    \
-  F(ftrace_cpu_read_events_begin,               kIndexed, kInfo,  kTrace),    \
-  F(ftrace_cpu_read_events_end,                 kIndexed, kInfo,  kTrace),    \
-  F(guess_trace_type_duration_ns,               kSingle,  kInfo,  kAnalysis), \
-  F(interned_data_tokenizer_errors,             kSingle,  kInfo,  kAnalysis), \
-  F(invalid_clock_snapshots,                    kSingle,  kError, kAnalysis), \
-  F(invalid_cpu_times,                          kSingle,  kError, kAnalysis), \
-  F(meminfo_unknown_keys,                       kSingle,  kError, kAnalysis), \
-  F(mismatched_sched_switch_tids,               kSingle,  kError, kAnalysis), \
-  F(mm_unknown_type,                            kSingle,  kError, kAnalysis), \
-  F(parse_trace_duration_ns,                    kSingle,  kInfo,  kAnalysis), \
-  F(power_rail_unknown_index,                   kSingle,  kError, kTrace), \
-  F(proc_stat_unknown_counters,                 kSingle,  kError, kAnalysis), \
-  F(rss_stat_unknown_keys,                      kSingle,  kError, kAnalysis), \
-  F(rss_stat_negative_size,                     kSingle,  kInfo,  kAnalysis), \
-  F(sched_switch_out_of_order,                  kSingle,  kError, kAnalysis), \
-  F(slice_out_of_order,                         kSingle,  kError, kAnalysis), \
-  F(systrace_parse_failure,                     kSingle,  kError, kAnalysis), \
-  F(task_state_invalid,                         kSingle,  kError, kAnalysis), \
-  F(traced_buf_buffer_size,                     kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_bytes_overwritten,               kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_bytes_read,                      kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_bytes_written,                   kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_chunks_discarded,                kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_chunks_overwritten,              kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_chunks_read,                     kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_chunks_rewritten,                kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_chunks_written,                  kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_chunks_committed_out_of_order,   kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_padding_bytes_cleared,           kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_padding_bytes_written,           kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_patches_failed,                  kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_patches_succeeded,               kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_readaheads_failed,               kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_readaheads_succeeded,            kIndexed, kInfo,  kTrace),    \
-  F(traced_buf_write_wrap_count,                kIndexed, kInfo,  kTrace),    \
-  F(traced_chunks_discarded,                    kSingle,  kInfo,  kTrace),    \
-  F(traced_data_sources_registered,             kSingle,  kInfo,  kTrace),    \
-  F(traced_data_sources_seen,                   kSingle,  kInfo,  kTrace),    \
-  F(traced_patches_discarded,                   kSingle,  kInfo,  kTrace),    \
-  F(traced_producers_connected,                 kSingle,  kInfo,  kTrace),    \
-  F(traced_producers_seen,                      kSingle,  kInfo,  kTrace),    \
-  F(traced_total_buffers,                       kSingle,  kInfo,  kTrace),    \
-  F(traced_tracing_sessions,                    kSingle,  kInfo,  kTrace),    \
-  F(track_event_tokenizer_errors,               kSingle,  kInfo,  kAnalysis), \
-  F(track_event_tokenizer_skipped_packets,      kSingle,  kInfo,  kAnalysis), \
-  F(vmstat_unknown_keys,                        kSingle,  kError, kAnalysis), \
-  F(clock_sync_failure,                         kSingle,  kError, kAnalysis), \
-  F(process_tracker_errors,                     kSingle,  kError, kAnalysis), \
-  F(json_tokenizer_failure,                     kSingle,  kError, kTrace),    \
-  F(heapprofd_buffer_corrupted,                 kIndexed, kError, kTrace),    \
-  F(heapprofd_buffer_overran,                   kIndexed, kError, kTrace),    \
-  F(heapprofd_rejected_concurrent,              kIndexed, kError, kTrace),    \
-  F(heapprofd_invalid_string_id,                kSingle,  kError, kTrace),    \
-  F(heapprofd_invalid_mapping_id,               kSingle,  kError, kTrace),    \
-  F(heapprofd_invalid_frame_id,                 kSingle,  kError, kTrace),    \
-  F(heapprofd_invalid_callstack_id,             kSingle,  kError, kTrace)
+#define PERFETTO_TP_STATS(F)                                                     \
+  F(android_log_num_failed,                   kSingle,  kError,    kTrace),    \
+  F(android_log_num_skipped,                  kSingle,  kError,    kTrace),    \
+  F(android_log_num_total,                    kSingle,  kInfo,     kTrace),    \
+  F(atrace_tgid_mismatch,                     kSingle,  kError,    kTrace),    \
+  F(clock_snapshot_not_monotonic,             kSingle,  kError,    kTrace),    \
+  F(counter_events_out_of_order,              kSingle,  kError,    kAnalysis), \
+  F(ftrace_bundle_tokenizer_errors,           kSingle,  kError,    kAnalysis), \
+  F(ftrace_cpu_bytes_read_begin,              kIndexed, kInfo,     kTrace),    \
+  F(ftrace_cpu_bytes_read_end,                kIndexed, kInfo,     kTrace),    \
+  F(ftrace_cpu_commit_overrun_begin,          kIndexed, kError,    kTrace),    \
+  F(ftrace_cpu_commit_overrun_end,            kIndexed, kError,    kTrace),    \
+  F(ftrace_cpu_dropped_events_begin,          kIndexed, kError,    kTrace),    \
+  F(ftrace_cpu_dropped_events_end,            kIndexed, kError,    kTrace),    \
+  F(ftrace_cpu_entries_begin,                 kIndexed, kInfo,     kTrace),    \
+  F(ftrace_cpu_entries_end,                   kIndexed, kInfo,     kTrace),    \
+  F(ftrace_cpu_now_ts_begin,                  kIndexed, kInfo,     kTrace),    \
+  F(ftrace_cpu_now_ts_end,                    kIndexed, kInfo,     kTrace),    \
+  F(ftrace_cpu_oldest_event_ts_begin,         kIndexed, kInfo,     kTrace),    \
+  F(ftrace_cpu_oldest_event_ts_end,           kIndexed, kInfo,     kTrace),    \
+  F(ftrace_cpu_overrun_begin,                 kIndexed, kInfo,     kTrace),    \
+  F(ftrace_cpu_overrun_end,                   kIndexed, kDataLoss, kTrace),    \
+  F(ftrace_cpu_read_events_begin,             kIndexed, kInfo,     kTrace),    \
+  F(ftrace_cpu_read_events_end,               kIndexed, kInfo,     kTrace),    \
+  F(guess_trace_type_duration_ns,             kSingle,  kInfo,     kAnalysis), \
+  F(interned_data_tokenizer_errors,           kSingle,  kInfo,     kAnalysis), \
+  F(invalid_clock_snapshots,                  kSingle,  kError,    kAnalysis), \
+  F(invalid_cpu_times,                        kSingle,  kError,    kAnalysis), \
+  F(meminfo_unknown_keys,                     kSingle,  kError,    kAnalysis), \
+  F(mismatched_sched_switch_tids,             kSingle,  kError,    kAnalysis), \
+  F(mm_unknown_type,                          kSingle,  kError,    kAnalysis), \
+  F(parse_trace_duration_ns,                  kSingle,  kInfo,     kAnalysis), \
+  F(power_rail_unknown_index,                 kSingle,  kError,    kTrace),    \
+  F(proc_stat_unknown_counters,               kSingle,  kError,    kAnalysis), \
+  F(rss_stat_unknown_keys,                    kSingle,  kError,    kAnalysis), \
+  F(rss_stat_negative_size,                   kSingle,  kInfo,     kAnalysis), \
+  F(sched_switch_out_of_order,                kSingle,  kError,    kAnalysis), \
+  F(slice_out_of_order,                       kSingle,  kError,    kAnalysis), \
+  F(systrace_parse_failure,                   kSingle,  kError,    kAnalysis), \
+  F(task_state_invalid,                       kSingle,  kError,    kAnalysis), \
+  F(traced_buf_buffer_size,                   kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_bytes_overwritten,             kIndexed, kDataLoss, kTrace),    \
+  F(traced_buf_bytes_read,                    kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_bytes_written,                 kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_chunks_discarded,              kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_chunks_overwritten,            kIndexed, kDataLoss, kTrace),    \
+  F(traced_buf_chunks_read,                   kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_chunks_rewritten,              kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_chunks_written,                kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_chunks_committed_out_of_order, kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_padding_bytes_cleared,         kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_padding_bytes_written,         kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_patches_failed,                kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_patches_succeeded,             kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_readaheads_failed,             kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_readaheads_succeeded,          kIndexed, kInfo,     kTrace),    \
+  F(traced_buf_write_wrap_count,              kIndexed, kInfo,     kTrace),    \
+  F(traced_chunks_discarded,                  kSingle,  kInfo,     kTrace),    \
+  F(traced_data_sources_registered,           kSingle,  kInfo,     kTrace),    \
+  F(traced_data_sources_seen,                 kSingle,  kInfo,     kTrace),    \
+  F(traced_patches_discarded,                 kSingle,  kInfo,     kTrace),    \
+  F(traced_producers_connected,               kSingle,  kInfo,     kTrace),    \
+  F(traced_producers_seen,                    kSingle,  kInfo,     kTrace),    \
+  F(traced_total_buffers,                     kSingle,  kInfo,     kTrace),    \
+  F(traced_tracing_sessions,                  kSingle,  kInfo,     kTrace),    \
+  F(track_event_tokenizer_errors,             kSingle,  kInfo,     kAnalysis), \
+  F(track_event_tokenizer_skipped_packets,    kSingle,  kInfo,     kAnalysis), \
+  F(vmstat_unknown_keys,                      kSingle,  kError,    kAnalysis), \
+  F(clock_sync_failure,                       kSingle,  kError,    kAnalysis), \
+  F(process_tracker_errors,                   kSingle,  kError,    kAnalysis), \
+  F(json_tokenizer_failure,                   kSingle,  kError,    kTrace),    \
+  F(heapprofd_buffer_corrupted,               kIndexed, kError,    kTrace),    \
+  F(heapprofd_buffer_overran,                 kIndexed, kDataLoss, kTrace),    \
+  F(heapprofd_rejected_concurrent,            kIndexed, kError,    kTrace),    \
+  F(heapprofd_invalid_string_id,              kSingle,  kError,    kTrace),    \
+  F(heapprofd_invalid_mapping_id,             kSingle,  kError,    kTrace),    \
+  F(heapprofd_invalid_frame_id,               kSingle,  kError,    kTrace),    \
+  F(heapprofd_invalid_callstack_id,           kSingle,  kError,    kTrace)
 // clang-format on
 
 enum Type {
@@ -111,8 +111,9 @@
 };
 
 enum Severity {
-  kInfo,  // Diagnostic counters
-  kError  // If any kError counter is > 0 the UI will raise an error.
+  kInfo,      // Diagnostic counters
+  kDataLoss,  // Correct operation that still resulted in data loss
+  kError      // If any kError counter is > 0 the UI will raise an error
 };
 
 enum Source {
diff --git a/src/trace_processor/stats_table.cc b/src/trace_processor/stats_table.cc
index 3397d91..7b5cb79 100644
--- a/src/trace_processor/stats_table.cc
+++ b/src/trace_processor/stats_table.cc
@@ -76,6 +76,9 @@
         case stats::kInfo:
           sqlite3_result_text(ctx, "info", -1, kSqliteStatic);
           break;
+        case stats::kDataLoss:
+          sqlite3_result_text(ctx, "data_loss", -1, kSqliteStatic);
+          break;
         case stats::kError:
           sqlite3_result_text(ctx, "error", -1, kSqliteStatic);
           break;
diff --git a/src/trace_processor/trace_processor_shell.cc b/src/trace_processor/trace_processor_shell.cc
index 98ce901..8edba60 100644
--- a/src/trace_processor/trace_processor_shell.cc
+++ b/src/trace_processor/trace_processor_shell.cc
@@ -144,7 +144,7 @@
 bool PrintStats() {
   auto it = g_tp->ExecuteQuery(
       "SELECT name, idx, source, value from stats "
-      "where severity = 'error' and value > 0");
+      "where severity IN ('error', 'data_loss') and value > 0");
 
   bool first = true;
   for (uint32_t rows = 0; it.Next(); rows++) {