Protos: A message to store benchmark metadata

Telemetry stores some metadata about the trace (eg. benchmark/story
name, custom labels, etc.) after running a benchmark. This CL adds
a message to store this metadata in proto format.

Bug: 132682848
Change-Id: I351ed7c425e5d1b186bf10a348a04f5d665ab60e
diff --git a/Android.bp b/Android.bp
index 05add93..7cbca62 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1208,6 +1208,7 @@
 genrule {
   name: "perfetto_protos_perfetto_trace_chrome_lite_gen",
   srcs: [
+    "protos/perfetto/trace/chrome/chrome_benchmark_metadata.proto",
     "protos/perfetto/trace/chrome/chrome_trace_event.proto",
   ],
   tools: [
@@ -1215,6 +1216,7 @@
   ],
   cmd: "mkdir -p $(genDir)/external/perfetto/protos && $(location aprotoc) --cpp_out=$(genDir)/external/perfetto/protos --proto_path=external/perfetto/protos $(in)",
   out: [
+    "external/perfetto/protos/perfetto/trace/chrome/chrome_benchmark_metadata.pb.cc",
     "external/perfetto/protos/perfetto/trace/chrome/chrome_trace_event.pb.cc",
   ],
 }
@@ -1223,6 +1225,7 @@
 genrule {
   name: "perfetto_protos_perfetto_trace_chrome_lite_gen_headers",
   srcs: [
+    "protos/perfetto/trace/chrome/chrome_benchmark_metadata.proto",
     "protos/perfetto/trace/chrome/chrome_trace_event.proto",
   ],
   tools: [
@@ -1230,6 +1233,7 @@
   ],
   cmd: "mkdir -p $(genDir)/external/perfetto/protos && $(location aprotoc) --cpp_out=$(genDir)/external/perfetto/protos --proto_path=external/perfetto/protos $(in)",
   out: [
+    "external/perfetto/protos/perfetto/trace/chrome/chrome_benchmark_metadata.pb.h",
     "external/perfetto/protos/perfetto/trace/chrome/chrome_trace_event.pb.h",
   ],
   export_include_dirs: [
@@ -1241,6 +1245,7 @@
 genrule {
   name: "perfetto_protos_perfetto_trace_chrome_zero_gen",
   srcs: [
+    "protos/perfetto/trace/chrome/chrome_benchmark_metadata.proto",
     "protos/perfetto/trace/chrome/chrome_trace_event.proto",
   ],
   tools: [
@@ -1249,6 +1254,7 @@
   ],
   cmd: "mkdir -p $(genDir)/external/perfetto/protos && $(location aprotoc) --cpp_out=$(genDir)/external/perfetto/protos --proto_path=external/perfetto/protos --plugin=protoc-gen-plugin=$(location perfetto_src_protozero_protoc_plugin_protoc_plugin___gn_standalone_toolchain_gcc_like_host_) --plugin_out=wrapper_namespace=pbzero:$(genDir)/external/perfetto/protos $(in)",
   out: [
+    "external/perfetto/protos/perfetto/trace/chrome/chrome_benchmark_metadata.pbzero.cc",
     "external/perfetto/protos/perfetto/trace/chrome/chrome_trace_event.pbzero.cc",
   ],
 }
@@ -1257,6 +1263,7 @@
 genrule {
   name: "perfetto_protos_perfetto_trace_chrome_zero_gen_headers",
   srcs: [
+    "protos/perfetto/trace/chrome/chrome_benchmark_metadata.proto",
     "protos/perfetto/trace/chrome/chrome_trace_event.proto",
   ],
   tools: [
@@ -1265,6 +1272,7 @@
   ],
   cmd: "mkdir -p $(genDir)/external/perfetto/protos && $(location aprotoc) --cpp_out=$(genDir)/external/perfetto/protos --proto_path=external/perfetto/protos --plugin=protoc-gen-plugin=$(location perfetto_src_protozero_protoc_plugin_protoc_plugin___gn_standalone_toolchain_gcc_like_host_) --plugin_out=wrapper_namespace=pbzero:$(genDir)/external/perfetto/protos $(in)",
   out: [
+    "external/perfetto/protos/perfetto/trace/chrome/chrome_benchmark_metadata.pbzero.h",
     "external/perfetto/protos/perfetto/trace/chrome/chrome_trace_event.pbzero.h",
   ],
   export_include_dirs: [
diff --git a/protos/BUILD b/protos/BUILD
index bf721d9..595d699 100644
--- a/protos/BUILD
+++ b/protos/BUILD
@@ -333,6 +333,7 @@
 proto_library(
     name = "trace_chrome",
     srcs = [
+        "perfetto/trace/chrome/chrome_benchmark_metadata.proto",
         "perfetto/trace/chrome/chrome_trace_event.proto",
     ],
     has_services = 1,
@@ -358,6 +359,7 @@
 proto_library(
     name = "trace_chrome_zero",
     srcs = [
+        "perfetto/trace/chrome/chrome_benchmark_metadata.proto",
         "perfetto/trace/chrome/chrome_trace_event.proto",
     ],
     deps = [
diff --git a/protos/perfetto/trace/chrome/BUILD.gn b/protos/perfetto/trace/chrome/BUILD.gn
index f637573..3277787 100644
--- a/protos/perfetto/trace/chrome/BUILD.gn
+++ b/protos/perfetto/trace/chrome/BUILD.gn
@@ -15,7 +15,10 @@
 import("../../../../gn/perfetto.gni")
 import("../../../../gn/protozero_library.gni")
 
-chrome_proto_names = [ "chrome_trace_event.proto" ]
+chrome_proto_names = [
+  "chrome_trace_event.proto",
+  "chrome_benchmark_metadata.proto",
+]
 minimal_chrome_proto_names = [ "chrome_trace_packet.proto" ]
 
 proto_library("lite") {
diff --git a/protos/perfetto/trace/chrome/chrome_benchmark_metadata.proto b/protos/perfetto/trace/chrome/chrome_benchmark_metadata.proto
new file mode 100644
index 0000000..1500660
--- /dev/null
+++ b/protos/perfetto/trace/chrome/chrome_benchmark_metadata.proto
@@ -0,0 +1,51 @@
+/*
+ * 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;
+
+// This message is not intended to be written by the chrome on the device.
+// It's emitted on the host by the telemetry benchmark infrastructure (it's a
+// part of the trace that's written by the telemetry tracing agent).
+message ChromeBenchmarkMetadata {
+  // Time when the benchmark execution started (host unixtime in microseconds).
+  optional int64 benchmark_start_time_us = 1;
+
+  // Time when this particular story was run (host unixtime in microseconds).
+  optional int64 story_run_time_us = 2;
+
+  // Name of benchmark.
+  optional string benchmark_name = 3;
+
+  // Description of benchmark.
+  optional string benchmark_description = 4;
+
+  // Optional label.
+  optional string label = 5;
+
+  // Name of story.
+  optional string story_name = 6;
+
+  // List of story tags.
+  repeated string story_tags = 7;
+
+  // Index of the story run (>0 if the same story was run several times).
+  optional int32 story_run_index = 8;
+
+  // Whether this run failed.
+  optional bool had_failures = 9;
+}
diff --git a/protos/perfetto/trace/perfetto_trace.proto b/protos/perfetto/trace/perfetto_trace.proto
index 96f1816..7b16209 100644
--- a/protos/perfetto/trace/perfetto_trace.proto
+++ b/protos/perfetto/trace/perfetto_trace.proto
@@ -395,6 +395,42 @@
 
 // End of protos/perfetto/trace/android/packages_list.proto
 
+// Begin of protos/perfetto/trace/chrome/chrome_benchmark_metadata.proto
+
+// This message is not intended to be written by the chrome on the device.
+// It's emitted on the host by the telemetry benchmark infrastructure (it's a
+// part of the trace that's written by the telemetry tracing agent).
+message ChromeBenchmarkMetadata {
+  // Time when the benchmark execution started (host unixtime in microseconds).
+  optional int64 benchmark_start_time_us = 1;
+
+  // Time when this particular story was run (host unixtime in microseconds).
+  optional int64 story_run_time_us = 2;
+
+  // Name of benchmark.
+  optional string benchmark_name = 3;
+
+  // Description of benchmark.
+  optional string benchmark_description = 4;
+
+  // Optional label.
+  optional string label = 5;
+
+  // Name of story.
+  optional string story_name = 6;
+
+  // List of story tags.
+  repeated string story_tags = 7;
+
+  // Index of the story run (>0 if the same story was run several times).
+  optional int32 story_run_index = 8;
+
+  // Whether this run failed.
+  optional bool had_failures = 9;
+}
+
+// End of protos/perfetto/trace/chrome/chrome_benchmark_metadata.proto
+
 // Begin of protos/perfetto/trace/clock_snapshot.proto
 
 // A snapshot of clock readings to allow for trace alignment.
@@ -2846,7 +2882,7 @@
 // TracePacket(s).
 //
 // Next reserved id: 13 (up to 15).
-// Next id: 47.
+// Next id: 49.
 message TracePacket {
   // TODO(primiano): in future we should add a timestamp_clock_domain field to
   // allow mixing timestamps from different clock domains.
@@ -2875,6 +2911,7 @@
     SystemInfo system_info = 45;
     Trigger trigger = 46;
     PackagesList packages_list = 47;
+    ChromeBenchmarkMetadata chrome_benchmark_metadata = 48;
 
     // Only used by TrackEvent.
     ProcessDescriptor process_descriptor = 43;
diff --git a/protos/perfetto/trace/trace_packet.proto b/protos/perfetto/trace/trace_packet.proto
index 74fe6a6..4067297 100644
--- a/protos/perfetto/trace/trace_packet.proto
+++ b/protos/perfetto/trace/trace_packet.proto
@@ -21,6 +21,7 @@
 import "perfetto/config/trace_config.proto";
 import "perfetto/trace/android/android_log.proto";
 import "perfetto/trace/android/packages_list.proto";
+import "perfetto/trace/chrome/chrome_benchmark_metadata.proto";
 import "perfetto/trace/chrome/chrome_trace_event.proto";
 import "perfetto/trace/clock_snapshot.proto";
 import "perfetto/trace/filesystem/inode_file_map.proto";
@@ -46,7 +47,7 @@
 // TracePacket(s).
 //
 // Next reserved id: 13 (up to 15).
-// Next id: 47.
+// Next id: 49.
 message TracePacket {
   // TODO(primiano): in future we should add a timestamp_clock_domain field to
   // allow mixing timestamps from different clock domains.
@@ -75,6 +76,7 @@
     SystemInfo system_info = 45;
     Trigger trigger = 46;
     PackagesList packages_list = 47;
+    ChromeBenchmarkMetadata chrome_benchmark_metadata = 48;
 
     // Only used by TrackEvent.
     ProcessDescriptor process_descriptor = 43;
diff --git a/tools/gen_merged_protos b/tools/gen_merged_protos
index 2d49235..15245f7 100755
--- a/tools/gen_merged_protos
+++ b/tools/gen_merged_protos
@@ -45,6 +45,7 @@
   'protos/perfetto/common/trace_stats.proto', # only referenced by trace protos
   'protos/perfetto/trace/android/android_log.proto',
   'protos/perfetto/trace/android/packages_list.proto',
+  'protos/perfetto/trace/chrome/chrome_benchmark_metadata.proto',
   'protos/perfetto/trace/clock_snapshot.proto',
   'protos/perfetto/trace/filesystem/inode_file_map.proto',
   'protos/perfetto/trace/ftrace/binder.proto',