Add Perfetto protos for Chrome log messages

This will allow Chrome logs to be collected in traces
similar to how Android logcat can currently be collected.
There will be a Chrome side change to make use of the proto.

The SourceLocation proto has been extracted into its own
file so that both task_execution.proto and log_message.proto
can depend on it.

Bug: chrome:983534
Change-Id: Id7c815c1b282b17d1d86472a03f80ed63538aa71
diff --git a/Android.bp b/Android.bp
index 15e84a4..653eff6 100644
--- a/Android.bp
+++ b/Android.bp
@@ -2589,7 +2589,9 @@
   name: "perfetto_protos_perfetto_trace_track_event_lite_gen",
   srcs: [
     "protos/perfetto/trace/track_event/debug_annotation.proto",
+    "protos/perfetto/trace/track_event/log_message.proto",
     "protos/perfetto/trace/track_event/process_descriptor.proto",
+    "protos/perfetto/trace/track_event/source_location.proto",
     "protos/perfetto/trace/track_event/task_execution.proto",
     "protos/perfetto/trace/track_event/thread_descriptor.proto",
     "protos/perfetto/trace/track_event/track_event.proto",
@@ -2600,7 +2602,9 @@
   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/track_event/debug_annotation.pb.cc",
+    "external/perfetto/protos/perfetto/trace/track_event/log_message.pb.cc",
     "external/perfetto/protos/perfetto/trace/track_event/process_descriptor.pb.cc",
+    "external/perfetto/protos/perfetto/trace/track_event/source_location.pb.cc",
     "external/perfetto/protos/perfetto/trace/track_event/task_execution.pb.cc",
     "external/perfetto/protos/perfetto/trace/track_event/thread_descriptor.pb.cc",
     "external/perfetto/protos/perfetto/trace/track_event/track_event.pb.cc",
@@ -2612,7 +2616,9 @@
   name: "perfetto_protos_perfetto_trace_track_event_lite_gen_headers",
   srcs: [
     "protos/perfetto/trace/track_event/debug_annotation.proto",
+    "protos/perfetto/trace/track_event/log_message.proto",
     "protos/perfetto/trace/track_event/process_descriptor.proto",
+    "protos/perfetto/trace/track_event/source_location.proto",
     "protos/perfetto/trace/track_event/task_execution.proto",
     "protos/perfetto/trace/track_event/thread_descriptor.proto",
     "protos/perfetto/trace/track_event/track_event.proto",
@@ -2623,7 +2629,9 @@
   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/track_event/debug_annotation.pb.h",
+    "external/perfetto/protos/perfetto/trace/track_event/log_message.pb.h",
     "external/perfetto/protos/perfetto/trace/track_event/process_descriptor.pb.h",
+    "external/perfetto/protos/perfetto/trace/track_event/source_location.pb.h",
     "external/perfetto/protos/perfetto/trace/track_event/task_execution.pb.h",
     "external/perfetto/protos/perfetto/trace/track_event/thread_descriptor.pb.h",
     "external/perfetto/protos/perfetto/trace/track_event/track_event.pb.h",
@@ -2638,7 +2646,9 @@
   name: "perfetto_protos_perfetto_trace_track_event_zero_gen",
   srcs: [
     "protos/perfetto/trace/track_event/debug_annotation.proto",
+    "protos/perfetto/trace/track_event/log_message.proto",
     "protos/perfetto/trace/track_event/process_descriptor.proto",
+    "protos/perfetto/trace/track_event/source_location.proto",
     "protos/perfetto/trace/track_event/task_execution.proto",
     "protos/perfetto/trace/track_event/thread_descriptor.proto",
     "protos/perfetto/trace/track_event/track_event.proto",
@@ -2650,7 +2660,9 @@
   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_protozero_plugin___gn_standalone_toolchain_gcc_like_host_) --plugin_out=wrapper_namespace=pbzero:$(genDir)/external/perfetto/protos $(in)",
   out: [
     "external/perfetto/protos/perfetto/trace/track_event/debug_annotation.pbzero.cc",
+    "external/perfetto/protos/perfetto/trace/track_event/log_message.pbzero.cc",
     "external/perfetto/protos/perfetto/trace/track_event/process_descriptor.pbzero.cc",
+    "external/perfetto/protos/perfetto/trace/track_event/source_location.pbzero.cc",
     "external/perfetto/protos/perfetto/trace/track_event/task_execution.pbzero.cc",
     "external/perfetto/protos/perfetto/trace/track_event/thread_descriptor.pbzero.cc",
     "external/perfetto/protos/perfetto/trace/track_event/track_event.pbzero.cc",
@@ -2662,7 +2674,9 @@
   name: "perfetto_protos_perfetto_trace_track_event_zero_gen_headers",
   srcs: [
     "protos/perfetto/trace/track_event/debug_annotation.proto",
+    "protos/perfetto/trace/track_event/log_message.proto",
     "protos/perfetto/trace/track_event/process_descriptor.proto",
+    "protos/perfetto/trace/track_event/source_location.proto",
     "protos/perfetto/trace/track_event/task_execution.proto",
     "protos/perfetto/trace/track_event/thread_descriptor.proto",
     "protos/perfetto/trace/track_event/track_event.proto",
@@ -2674,7 +2688,9 @@
   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_protozero_plugin___gn_standalone_toolchain_gcc_like_host_) --plugin_out=wrapper_namespace=pbzero:$(genDir)/external/perfetto/protos $(in)",
   out: [
     "external/perfetto/protos/perfetto/trace/track_event/debug_annotation.pbzero.h",
+    "external/perfetto/protos/perfetto/trace/track_event/log_message.pbzero.h",
     "external/perfetto/protos/perfetto/trace/track_event/process_descriptor.pbzero.h",
+    "external/perfetto/protos/perfetto/trace/track_event/source_location.pbzero.h",
     "external/perfetto/protos/perfetto/trace/track_event/task_execution.pbzero.h",
     "external/perfetto/protos/perfetto/trace/track_event/thread_descriptor.pbzero.h",
     "external/perfetto/protos/perfetto/trace/track_event/track_event.pbzero.h",
diff --git a/protos/BUILD b/protos/BUILD
index 6685775..5e28c72 100644
--- a/protos/BUILD
+++ b/protos/BUILD
@@ -1265,7 +1265,9 @@
     name = "trace_track_event",
     srcs = [
         "perfetto/trace/track_event/debug_annotation.proto",
+        "perfetto/trace/track_event/log_message.proto",
         "perfetto/trace/track_event/process_descriptor.proto",
+        "perfetto/trace/track_event/source_location.proto",
         "perfetto/trace/track_event/task_execution.proto",
         "perfetto/trace/track_event/thread_descriptor.proto",
         "perfetto/trace/track_event/track_event.proto",
@@ -1305,7 +1307,9 @@
     name = "trace_track_event_zero",
     srcs = [
         "perfetto/trace/track_event/debug_annotation.proto",
+        "perfetto/trace/track_event/log_message.proto",
         "perfetto/trace/track_event/process_descriptor.proto",
+        "perfetto/trace/track_event/source_location.proto",
         "perfetto/trace/track_event/task_execution.proto",
         "perfetto/trace/track_event/thread_descriptor.proto",
         "perfetto/trace/track_event/track_event.proto",
diff --git a/protos/perfetto/trace/interned_data/interned_data.proto b/protos/perfetto/trace/interned_data/interned_data.proto
index cfad464..2fbc87c 100644
--- a/protos/perfetto/trace/interned_data/interned_data.proto
+++ b/protos/perfetto/trace/interned_data/interned_data.proto
@@ -18,9 +18,9 @@
 option optimize_for = LITE_RUNTIME;
 
 import "perfetto/trace/track_event/debug_annotation.proto";
-import "perfetto/trace/track_event/task_execution.proto";
+import "perfetto/trace/track_event/log_message.proto";
 import "perfetto/trace/track_event/track_event.proto";
-
+import "perfetto/trace/track_event/source_location.proto";
 import "perfetto/trace/profiling/profile_common.proto";
 
 package perfetto.protos;
@@ -52,7 +52,7 @@
 // emitted proactively in advance of referring to them in later packets.
 //
 // Next reserved id: 8 (up to 15).
-// Next id: 20.
+// Next id: 21.
 message InternedData {
   // Each field's message type needs to specify an |iid| field, which is the ID
   // of the entry in the field's interning index. Each field constructs its own
@@ -65,6 +65,7 @@
   repeated LegacyEventName legacy_event_names = 2;
   repeated DebugAnnotationName debug_annotation_names = 3;
   repeated SourceLocation source_locations = 4;
+  repeated LogMessageBody log_message_body = 20;
 
   // Note: field IDs up to 15 should be used for frequent data only.
 
diff --git a/protos/perfetto/trace/perfetto_trace.proto b/protos/perfetto/trace/perfetto_trace.proto
index 6c186b0..0ce1bbd 100644
--- a/protos/perfetto/trace/perfetto_trace.proto
+++ b/protos/perfetto/trace/perfetto_trace.proto
@@ -2603,7 +2603,7 @@
 // emitted proactively in advance of referring to them in later packets.
 //
 // Next reserved id: 8 (up to 15).
-// Next id: 20.
+// Next id: 21.
 message InternedData {
   // Each field's message type needs to specify an |iid| field, which is the ID
   // of the entry in the field's interning index. Each field constructs its own
@@ -2616,6 +2616,7 @@
   repeated LegacyEventName legacy_event_names = 2;
   repeated DebugAnnotationName debug_annotation_names = 3;
   repeated SourceLocation source_locations = 4;
+  repeated LogMessageBody log_message_body = 20;
 
   // Note: field IDs up to 15 should be used for frequent data only.
 
@@ -3244,6 +3245,23 @@
 
 // End of protos/perfetto/trace/track_event/debug_annotation.proto
 
+// Begin of protos/perfetto/trace/track_event/log_message.proto
+
+message LogMessage {
+  optional uint64 source_location_iid = 1;  // interned SourceLocation.
+  optional uint64 body_iid = 2;             // interned LogMessageBody.
+}
+
+// --------------------
+// Interned data types:
+// --------------------
+
+message LogMessageBody {
+  optional uint64 iid = 1;
+  optional string body = 2;
+}
+// End of protos/perfetto/trace/track_event/log_message.proto
+
 // Begin of protos/perfetto/trace/track_event/process_descriptor.proto
 
 // Process-wide data that is periodically emitted by one thread per process.
@@ -3275,13 +3293,7 @@
 
 // End of protos/perfetto/trace/track_event/process_descriptor.proto
 
-// Begin of protos/perfetto/trace/track_event/task_execution.proto
-
-// TrackEvent arguments describing the execution of a task.
-message TaskExecution {
-  // Source location that the task was posted from.
-  optional uint64 posted_from_iid = 1;  // interned SourceLocation.
-}
+// Begin of protos/perfetto/trace/track_event/source_location.proto
 
 // --------------------
 // Interned data types:
@@ -3293,8 +3305,18 @@
   // We intend to add a binary symbol version of this in the future.
   optional string file_name = 2;
   optional string function_name = 3;
+  optional uint32 line_number = 4;
 }
 
+// End of protos/perfetto/trace/track_event/source_location.proto
+
+// Begin of protos/perfetto/trace/track_event/task_execution.proto
+
+// TrackEvent arguments describing the execution of a task.
+message TaskExecution {
+  // Source location that the task was posted from.
+  optional uint64 posted_from_iid = 1;  // interned SourceLocation.
+}
 // End of protos/perfetto/trace/track_event/task_execution.proto
 
 // Begin of protos/perfetto/trace/track_event/thread_descriptor.proto
@@ -3371,7 +3393,7 @@
 // messages in separate TracePackets instead.
 //
 // Next reserved id: 8 (up to 15).
-// Next id: 21.
+// Next id: 22.
 message TrackEvent {
   // Timestamp in microseconds (usually CLOCK_MONOTONIC).
   oneof timestamp {
@@ -3420,6 +3442,8 @@
 
   // Typed event arguments:
   optional TaskExecution task_execution = 5;
+  optional LogMessage log_message = 21;
+
   // TODO(eseckler): New argument types go here :)
 
   // Apart from {category, time, thread time, tid, pid}, other legacy trace
diff --git a/protos/perfetto/trace/track_event/BUILD.gn b/protos/perfetto/trace/track_event/BUILD.gn
index 2646a09..3df8f18 100644
--- a/protos/perfetto/trace/track_event/BUILD.gn
+++ b/protos/perfetto/trace/track_event/BUILD.gn
@@ -19,6 +19,8 @@
 event_proto_names = [
   "debug_annotation.proto",
   "process_descriptor.proto",
+  "source_location.proto",
+  "log_message.proto",
   "task_execution.proto",
   "thread_descriptor.proto",
   "track_event.proto",
diff --git a/protos/perfetto/trace/track_event/log_message.proto b/protos/perfetto/trace/track_event/log_message.proto
new file mode 100644
index 0000000..a2fde6d
--- /dev/null
+++ b/protos/perfetto/trace/track_event/log_message.proto
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+message LogMessage {
+  optional uint64 source_location_iid = 1;  // interned SourceLocation.
+  optional uint64 body_iid = 2;             // interned LogMessageBody.
+}
+
+// --------------------
+// Interned data types:
+// --------------------
+
+message LogMessageBody {
+  optional uint64 iid = 1;
+  optional string body = 2;
+}
\ No newline at end of file
diff --git a/protos/perfetto/trace/track_event/source_location.proto b/protos/perfetto/trace/track_event/source_location.proto
new file mode 100644
index 0000000..39d6bb1
--- /dev/null
+++ b/protos/perfetto/trace/track_event/source_location.proto
@@ -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.
+ */
+
+syntax = "proto2";
+option optimize_for = LITE_RUNTIME;
+
+package perfetto.protos;
+
+// --------------------
+// Interned data types:
+// --------------------
+
+message SourceLocation {
+  optional uint64 iid = 1;
+
+  // We intend to add a binary symbol version of this in the future.
+  optional string file_name = 2;
+  optional string function_name = 3;
+  optional uint32 line_number = 4;
+}
diff --git a/protos/perfetto/trace/track_event/task_execution.proto b/protos/perfetto/trace/track_event/task_execution.proto
index 2df96bb..6eebad9 100644
--- a/protos/perfetto/trace/track_event/task_execution.proto
+++ b/protos/perfetto/trace/track_event/task_execution.proto
@@ -23,16 +23,4 @@
 message TaskExecution {
   // Source location that the task was posted from.
   optional uint64 posted_from_iid = 1;  // interned SourceLocation.
-}
-
-// --------------------
-// Interned data types:
-// --------------------
-
-message SourceLocation {
-  optional uint64 iid = 1;
-
-  // We intend to add a binary symbol version of this in the future.
-  optional string file_name = 2;
-  optional string function_name = 3;
-}
+}
\ No newline at end of file
diff --git a/protos/perfetto/trace/track_event/track_event.proto b/protos/perfetto/trace/track_event/track_event.proto
index 876e038..414bb8b 100644
--- a/protos/perfetto/trace/track_event/track_event.proto
+++ b/protos/perfetto/trace/track_event/track_event.proto
@@ -18,6 +18,7 @@
 option optimize_for = LITE_RUNTIME;
 
 import "perfetto/trace/track_event/debug_annotation.proto";
+import "perfetto/trace/track_event/log_message.proto";
 import "perfetto/trace/track_event/task_execution.proto";
 
 package perfetto.protos;
@@ -40,7 +41,7 @@
 // messages in separate TracePackets instead.
 //
 // Next reserved id: 8 (up to 15).
-// Next id: 21.
+// Next id: 22.
 message TrackEvent {
   // Timestamp in microseconds (usually CLOCK_MONOTONIC).
   oneof timestamp {
@@ -89,6 +90,8 @@
 
   // Typed event arguments:
   optional TaskExecution task_execution = 5;
+  optional LogMessage log_message = 21;
+
   // TODO(eseckler): New argument types go here :)
 
   // Apart from {category, time, thread time, tid, pid}, other legacy trace
diff --git a/src/trace_processor/proto_incremental_state.h b/src/trace_processor/proto_incremental_state.h
index e902641..65bab83 100644
--- a/src/trace_processor/proto_incremental_state.h
+++ b/src/trace_processor/proto_incremental_state.h
@@ -29,6 +29,7 @@
 
 #include "perfetto/trace/profiling/profile_common.pbzero.h"
 #include "perfetto/trace/track_event/debug_annotation.pbzero.h"
+#include "perfetto/trace/track_event/source_location.pbzero.h"
 #include "perfetto/trace/track_event/task_execution.pbzero.h"
 #include "perfetto/trace/track_event/track_event.pbzero.h"
 
diff --git a/src/trace_processor/proto_trace_parser.cc b/src/trace_processor/proto_trace_parser.cc
index 7cfaa6b..2302210 100644
--- a/src/trace_processor/proto_trace_parser.cc
+++ b/src/trace_processor/proto_trace_parser.cc
@@ -78,6 +78,7 @@
 #include "perfetto/trace/trace.pbzero.h"
 #include "perfetto/trace/trace_packet.pbzero.h"
 #include "perfetto/trace/track_event/debug_annotation.pbzero.h"
+#include "perfetto/trace/track_event/source_location.pbzero.h"
 #include "perfetto/trace/track_event/task_execution.pbzero.h"
 #include "perfetto/trace/track_event/track_event.pbzero.h"
 
diff --git a/src/trace_processor/proto_trace_tokenizer.cc b/src/trace_processor/proto_trace_tokenizer.cc
index 3b42613..b522788 100644
--- a/src/trace_processor/proto_trace_tokenizer.cc
+++ b/src/trace_processor/proto_trace_tokenizer.cc
@@ -35,6 +35,7 @@
 #include "perfetto/trace/interned_data/interned_data.pbzero.h"
 #include "perfetto/trace/profiling/profile_common.pbzero.h"
 #include "perfetto/trace/trace.pbzero.h"
+#include "perfetto/trace/track_event/source_location.pbzero.h"
 #include "perfetto/trace/track_event/task_execution.pbzero.h"
 #include "perfetto/trace/track_event/thread_descriptor.pbzero.h"
 #include "perfetto/trace/track_event/track_event.pbzero.h"
diff --git a/tools/gen_merged_protos b/tools/gen_merged_protos
index 5f68999..ff56fe1 100755
--- a/tools/gen_merged_protos
+++ b/tools/gen_merged_protos
@@ -85,7 +85,9 @@
   'protos/perfetto/trace/trace.proto',
   'protos/perfetto/trace/trace_packet.proto',
   'protos/perfetto/trace/track_event/debug_annotation.proto',
+  'protos/perfetto/trace/track_event/log_message.proto',
   'protos/perfetto/trace/track_event/process_descriptor.proto',
+  'protos/perfetto/trace/track_event/source_location.proto',
   'protos/perfetto/trace/track_event/task_execution.proto',
   'protos/perfetto/trace/track_event/thread_descriptor.proto',
   'protos/perfetto/trace/track_event/track_event.proto',