trace_processor: import android memory metric protos into metrics folder

This just imports the protos for the memory metrics. The code which
actually generates these protos will be added in the near future.

Context: go/perfetto-metrics
Bug: 129747127
Change-Id: Ib546523a65cbffe1dd67efbdd7317fb57534aecf
diff --git a/BUILD b/BUILD
index d35b0f1..7a3bcf3 100644
--- a/BUILD
+++ b/BUILD
@@ -461,6 +461,7 @@
         "//third_party/perfetto/google:jsoncpp",
         "//third_party/perfetto/google:linenoise",
         "//third_party/perfetto/google:perfetto_version",
+        "//third_party/perfetto/protos:android_cc_proto",
         "//third_party/perfetto/protos:android_zero_cc_proto",
         "//third_party/perfetto/protos:chrome_zero_cc_proto",
         "//third_party/perfetto/protos:common_cc_proto",
diff --git a/protos/BUILD b/protos/BUILD
index ca05a37..5c2acf4 100644
--- a/protos/BUILD
+++ b/protos/BUILD
@@ -452,6 +452,9 @@
     visibility = [
         "//visibility:public",
     ],
+    deps = [
+        "//third_party/perfetto/protos:android",
+    ],
 )
 
 # GN target: //protos/perfetto/metrics:lite_gen
diff --git a/protos/perfetto/metrics/BUILD.gn b/protos/perfetto/metrics/BUILD.gn
index 334f763..7b8e505 100644
--- a/protos/perfetto/metrics/BUILD.gn
+++ b/protos/perfetto/metrics/BUILD.gn
@@ -19,6 +19,9 @@
 common_sources = [ "metrics.proto" ]
 
 proto_library("lite") {
+  deps = [
+    "android:lite",
+  ]
   generate_python = false
   proto_in_dir = "$perfetto_root_path/protos"
   proto_out_dir = "$perfetto_root_path/protos"
@@ -26,6 +29,9 @@
 }
 
 protozero_library("zero") {
+  deps = [
+    "android:zero",
+  ]
   proto_in_dir = "$perfetto_root_path/protos"
   proto_out_dir = "$perfetto_root_path/protos"
   sources = common_sources
diff --git a/protos/perfetto/metrics/android/BUILD.gn b/protos/perfetto/metrics/android/BUILD.gn
new file mode 100644
index 0000000..e47c896
--- /dev/null
+++ b/protos/perfetto/metrics/android/BUILD.gn
@@ -0,0 +1,33 @@
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("../../../../gn/perfetto.gni")
+import("../../../../gn/proto_library.gni")
+import("../../../../gn/protozero_library.gni")
+
+common_sources = [ "mem_metric.proto" ]
+
+proto_library("lite") {
+  generate_python = false
+  proto_in_dir = "$perfetto_root_path/protos"
+  proto_out_dir = "$perfetto_root_path/protos"
+  sources = common_sources
+}
+
+protozero_library("zero") {
+  proto_in_dir = "$perfetto_root_path/protos"
+  proto_out_dir = "$perfetto_root_path/protos"
+  sources = common_sources
+  generator_plugin_options = "wrapper_namespace=pbzero"
+}
diff --git a/protos/perfetto/metrics/android/mem_metric.proto b/protos/perfetto/metrics/android/mem_metric.proto
new file mode 100644
index 0000000..c6c0466
--- /dev/null
+++ b/protos/perfetto/metrics/android/mem_metric.proto
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto2";
+option optimize_for = LITE_RUNTIME;
+
+package perfetto.protos;
+
+// Memory metrics on Android.
+message AndroidMemoryMetric {
+  // Next id: 6
+  message SystemMetrics {
+    reserved 3;
+
+    optional Counter anon_pages = 1;
+    optional Counter mmaped_pages = 2;
+    repeated NamedCounter ion_buffers = 4;
+    optional LowMemoryKills lmks = 5;
+  }
+
+  message LowMemoryKills {
+    message LowMemoryKillBreakdown {
+      optional int32 oom_score_adj = 1;
+      optional int32 count = 2;
+    }
+
+    optional int32 total_count = 1;
+    repeated LowMemoryKillBreakdown breakdown = 2;
+  }
+
+  // Next id: 14
+  message ProcessMetrics {
+    reserved 2 to 9;
+
+    optional string process_name = 1;
+    optional ProcessMemoryCounters overall_counters = 10;
+
+    message ProcessMetricsBreakdown {
+      reserved 1;
+      optional string process_priority = 3;
+      optional ProcessMemoryCounters counters = 2;
+    }
+    repeated ProcessMetricsBreakdown breakdown = 11;
+
+    // Reserved for internal use.
+    extensions 12;
+
+    // A single process might have started one or more times in the duration of
+    // a trace. For each of these instances, measure the starting and ending
+    // anon+swap memory values.
+    repeated SpanGrowth anon_growth = 13;
+  }
+
+  message ProcessMemoryCounters {
+    optional Counter anon_rss = 1;
+    optional Counter file_rss = 2;
+    optional Counter swap = 3;
+    optional Counter anon_and_swap = 4;
+  }
+
+  message NamedCounter {
+    optional string name = 1;
+    optional Counter counter = 2;
+  }
+
+  message Counter {
+    optional double min = 1;
+    optional double max = 2;
+    optional double avg = 3;
+  }
+
+  message SpanGrowth {
+    // Initial value (at the beginning of the trace or process start)
+    optional double start_val = 1;
+
+    // End value (last sample for the pid).
+    optional double end_val = 2;
+
+    // Process duration (might or might not match the trace duration).
+    optional int64 duration = 3;
+
+    // (end_val - start_val) / start_val
+    optional double growth = 4;
+  }
+
+  optional SystemMetrics system_metrics = 4;
+
+  // Process-level metrics
+  repeated ProcessMetrics process_metrics = 3;
+}
diff --git a/protos/perfetto/metrics/metrics.proto b/protos/perfetto/metrics/metrics.proto
index 383f9bc..234c899 100644
--- a/protos/perfetto/metrics/metrics.proto
+++ b/protos/perfetto/metrics/metrics.proto
@@ -19,7 +19,10 @@
 
 package perfetto.protos;
 
+import "perfetto/metrics/android/mem_metric.proto";
+
 // Root message for all Perfetto-based metrics.
 message TraceMetrics {
-  // TODO(lalitm): add sub-messages for each team using Perfetto metrics.
+  // Memory metrics on Android (owned by the Android Telemetry team).
+  optional AndroidMemoryMetric android_mem = 1;
 }