Added process tree config.

Process tree config contains an enum that allows the initial process dump or the on demand process dumps to be disabled.

Also contains a fix for the autogenerator code that makes it work for repeated enums.

Change-Id: I0666a890db87d2f857b2bcf9500d935b3a77c869
diff --git a/Android.bp b/Android.bp
index 4c6044c..4fd984e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -82,6 +82,7 @@
     "src/tracing/core/inode_file_config.cc",
     "src/tracing/core/null_trace_writer.cc",
     "src/tracing/core/packet_stream_validator.cc",
+    "src/tracing/core/process_stats_config.cc",
     "src/tracing/core/service_impl.cc",
     "src/tracing/core/shared_memory_abi.cc",
     "src/tracing/core/shared_memory_arbiter_impl.cc",
@@ -177,6 +178,7 @@
     "src/tracing/core/inode_file_config.cc",
     "src/tracing/core/null_trace_writer.cc",
     "src/tracing/core/packet_stream_validator.cc",
+    "src/tracing/core/process_stats_config.cc",
     "src/tracing/core/service_impl.cc",
     "src/tracing/core/shared_memory_abi.cc",
     "src/tracing/core/shared_memory_arbiter_impl.cc",
@@ -321,6 +323,7 @@
     "src/tracing/core/inode_file_config.cc",
     "src/tracing/core/null_trace_writer.cc",
     "src/tracing/core/packet_stream_validator.cc",
+    "src/tracing/core/process_stats_config.cc",
     "src/tracing/core/service_impl.cc",
     "src/tracing/core/shared_memory_abi.cc",
     "src/tracing/core/shared_memory_arbiter_impl.cc",
@@ -419,6 +422,7 @@
     "protos/perfetto/config/data_source_descriptor.proto",
     "protos/perfetto/config/ftrace/ftrace_config.proto",
     "protos/perfetto/config/inode_file/inode_file_config.proto",
+    "protos/perfetto/config/process_stats/process_stats_config.proto",
     "protos/perfetto/config/test_config.proto",
     "protos/perfetto/config/trace_config.proto",
   ],
@@ -432,6 +436,7 @@
     "external/perfetto/protos/perfetto/config/data_source_descriptor.pb.cc",
     "external/perfetto/protos/perfetto/config/ftrace/ftrace_config.pb.cc",
     "external/perfetto/protos/perfetto/config/inode_file/inode_file_config.pb.cc",
+    "external/perfetto/protos/perfetto/config/process_stats/process_stats_config.pb.cc",
     "external/perfetto/protos/perfetto/config/test_config.pb.cc",
     "external/perfetto/protos/perfetto/config/trace_config.pb.cc",
   ],
@@ -446,6 +451,7 @@
     "protos/perfetto/config/data_source_descriptor.proto",
     "protos/perfetto/config/ftrace/ftrace_config.proto",
     "protos/perfetto/config/inode_file/inode_file_config.proto",
+    "protos/perfetto/config/process_stats/process_stats_config.proto",
     "protos/perfetto/config/test_config.proto",
     "protos/perfetto/config/trace_config.proto",
   ],
@@ -459,6 +465,7 @@
     "external/perfetto/protos/perfetto/config/data_source_descriptor.pb.h",
     "external/perfetto/protos/perfetto/config/ftrace/ftrace_config.pb.h",
     "external/perfetto/protos/perfetto/config/inode_file/inode_file_config.pb.h",
+    "external/perfetto/protos/perfetto/config/process_stats/process_stats_config.pb.h",
     "external/perfetto/protos/perfetto/config/test_config.pb.h",
     "external/perfetto/protos/perfetto/config/trace_config.pb.h",
   ],
@@ -476,6 +483,7 @@
     "protos/perfetto/config/data_source_descriptor.proto",
     "protos/perfetto/config/ftrace/ftrace_config.proto",
     "protos/perfetto/config/inode_file/inode_file_config.proto",
+    "protos/perfetto/config/process_stats/process_stats_config.proto",
     "protos/perfetto/config/test_config.proto",
     "protos/perfetto/config/trace_config.proto",
   ],
@@ -490,6 +498,7 @@
     "external/perfetto/protos/perfetto/config/data_source_descriptor.pbzero.cc",
     "external/perfetto/protos/perfetto/config/ftrace/ftrace_config.pbzero.cc",
     "external/perfetto/protos/perfetto/config/inode_file/inode_file_config.pbzero.cc",
+    "external/perfetto/protos/perfetto/config/process_stats/process_stats_config.pbzero.cc",
     "external/perfetto/protos/perfetto/config/test_config.pbzero.cc",
     "external/perfetto/protos/perfetto/config/trace_config.pbzero.cc",
   ],
@@ -504,6 +513,7 @@
     "protos/perfetto/config/data_source_descriptor.proto",
     "protos/perfetto/config/ftrace/ftrace_config.proto",
     "protos/perfetto/config/inode_file/inode_file_config.proto",
+    "protos/perfetto/config/process_stats/process_stats_config.proto",
     "protos/perfetto/config/test_config.proto",
     "protos/perfetto/config/trace_config.proto",
   ],
@@ -518,6 +528,7 @@
     "external/perfetto/protos/perfetto/config/data_source_descriptor.pbzero.h",
     "external/perfetto/protos/perfetto/config/ftrace/ftrace_config.pbzero.h",
     "external/perfetto/protos/perfetto/config/inode_file/inode_file_config.pbzero.h",
+    "external/perfetto/protos/perfetto/config/process_stats/process_stats_config.pbzero.h",
     "external/perfetto/protos/perfetto/config/test_config.pbzero.h",
     "external/perfetto/protos/perfetto/config/trace_config.pbzero.h",
   ],
@@ -3148,6 +3159,7 @@
     "src/tracing/core/inode_file_config.cc",
     "src/tracing/core/null_trace_writer.cc",
     "src/tracing/core/packet_stream_validator.cc",
+    "src/tracing/core/process_stats_config.cc",
     "src/tracing/core/service_impl.cc",
     "src/tracing/core/shared_memory_abi.cc",
     "src/tracing/core/shared_memory_arbiter_impl.cc",
@@ -3380,6 +3392,7 @@
     "src/tracing/core/packet_stream_validator.cc",
     "src/tracing/core/packet_stream_validator_unittest.cc",
     "src/tracing/core/patch_list_unittest.cc",
+    "src/tracing/core/process_stats_config.cc",
     "src/tracing/core/service_impl.cc",
     "src/tracing/core/service_impl_unittest.cc",
     "src/tracing/core/shared_memory_abi.cc",
diff --git a/include/perfetto/tracing/core/data_source_config.h b/include/perfetto/tracing/core/data_source_config.h
index 34527ae..619168b 100644
--- a/include/perfetto/tracing/core/data_source_config.h
+++ b/include/perfetto/tracing/core/data_source_config.h
@@ -38,6 +38,7 @@
 #include "perfetto/tracing/core/chrome_config.h"
 #include "perfetto/tracing/core/ftrace_config.h"
 #include "perfetto/tracing/core/inode_file_config.h"
+#include "perfetto/tracing/core/process_stats_config.h"
 #include "perfetto/tracing/core/test_config.h"
 
 // Forward declarations for protobuf types.
@@ -48,6 +49,7 @@
 class ChromeConfig;
 class InodeFileConfig;
 class InodeFileConfig_MountPointMappingEntry;
+class ProcessStatsConfig;
 class TestConfig;
 }  // namespace protos
 }  // namespace perfetto
@@ -87,6 +89,13 @@
   }
   InodeFileConfig* mutable_inode_file_config() { return &inode_file_config_; }
 
+  const ProcessStatsConfig& process_stats_config() const {
+    return process_stats_config_;
+  }
+  ProcessStatsConfig* mutable_process_stats_config() {
+    return &process_stats_config_;
+  }
+
   const std::string& legacy_config() const { return legacy_config_; }
   void set_legacy_config(const std::string& value) { legacy_config_ = value; }
 
@@ -100,6 +109,7 @@
   FtraceConfig ftrace_config_ = {};
   ChromeConfig chrome_config_ = {};
   InodeFileConfig inode_file_config_ = {};
+  ProcessStatsConfig process_stats_config_ = {};
   std::string legacy_config_ = {};
   TestConfig for_testing_ = {};
 
diff --git a/include/perfetto/tracing/core/process_stats_config.h b/include/perfetto/tracing/core/process_stats_config.h
new file mode 100644
index 0000000..2601ca0
--- /dev/null
+++ b/include/perfetto/tracing/core/process_stats_config.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+/*******************************************************************************
+ * AUTOGENERATED - DO NOT EDIT
+ *******************************************************************************
+ * This file has been generated from the protobuf message
+ * perfetto/config/process_stats/process_stats_config.proto
+ * by
+ * ../../tools/proto_to_cpp/proto_to_cpp.cc.
+ * If you need to make changes here, change the .proto file and then run
+ * ./tools/gen_tracing_cpp_headers_from_protos.py
+ */
+
+#ifndef INCLUDE_PERFETTO_TRACING_CORE_PROCESS_STATS_CONFIG_H_
+#define INCLUDE_PERFETTO_TRACING_CORE_PROCESS_STATS_CONFIG_H_
+
+#include <stdint.h>
+#include <string>
+#include <type_traits>
+#include <vector>
+
+#include "perfetto/base/export.h"
+
+// Forward declarations for protobuf types.
+namespace perfetto {
+namespace protos {
+class ProcessStatsConfig;
+}
+}  // namespace perfetto
+
+namespace perfetto {
+
+class PERFETTO_EXPORT ProcessStatsConfig {
+ public:
+  enum Quirks {
+    QUIRKS_UNSPECIFIED = 0,
+    DISABLE_INITIAL_DUMP = 1,
+    DISABLE_ON_DEMAND = 2,
+  };
+  ProcessStatsConfig();
+  ~ProcessStatsConfig();
+  ProcessStatsConfig(ProcessStatsConfig&&) noexcept;
+  ProcessStatsConfig& operator=(ProcessStatsConfig&&);
+  ProcessStatsConfig(const ProcessStatsConfig&);
+  ProcessStatsConfig& operator=(const ProcessStatsConfig&);
+
+  // Conversion methods from/to the corresponding protobuf types.
+  void FromProto(const perfetto::protos::ProcessStatsConfig&);
+  void ToProto(perfetto::protos::ProcessStatsConfig*) const;
+
+  int quirks_size() const { return static_cast<int>(quirks_.size()); }
+  const std::vector<Quirks>& quirks() const { return quirks_; }
+  Quirks* add_quirks() {
+    quirks_.emplace_back();
+    return &quirks_.back();
+  }
+
+ private:
+  std::vector<Quirks> quirks_;
+
+  // Allows to preserve unknown protobuf fields for compatibility
+  // with future versions of .proto files.
+  std::string unknown_fields_;
+};
+
+}  // namespace perfetto
+#endif  // INCLUDE_PERFETTO_TRACING_CORE_PROCESS_STATS_CONFIG_H_
diff --git a/include/perfetto/tracing/core/trace_config.h b/include/perfetto/tracing/core/trace_config.h
index 8436340..2097906 100644
--- a/include/perfetto/tracing/core/trace_config.h
+++ b/include/perfetto/tracing/core/trace_config.h
@@ -48,6 +48,7 @@
 class ChromeConfig;
 class InodeFileConfig;
 class InodeFileConfig_MountPointMappingEntry;
+class ProcessStatsConfig;
 class TestConfig;
 class TraceConfig_ProducerConfig;
 class TraceConfig_StatsdMetadata;
diff --git a/protos/perfetto/config/BUILD.gn b/protos/perfetto/config/BUILD.gn
index 4fb1011..74fa6c1 100644
--- a/protos/perfetto/config/BUILD.gn
+++ b/protos/perfetto/config/BUILD.gn
@@ -26,6 +26,7 @@
     "data_source_descriptor.proto",
     "ftrace/ftrace_config.proto",
     "inode_file/inode_file_config.proto",
+    "process_stats/process_stats_config.proto",
     "test_config.proto",
     "trace_config.proto",
   ]
@@ -40,6 +41,7 @@
     "data_source_descriptor.proto",
     "ftrace/ftrace_config.proto",
     "inode_file/inode_file_config.proto",
+    "process_stats/process_stats_config.proto",
     "test_config.proto",
     "trace_config.proto",
   ]
diff --git a/protos/perfetto/config/data_source_config.proto b/protos/perfetto/config/data_source_config.proto
index 4c4d747..c7b2f21 100644
--- a/protos/perfetto/config/data_source_config.proto
+++ b/protos/perfetto/config/data_source_config.proto
@@ -22,6 +22,7 @@
 import "perfetto/config/chrome/chrome_config.proto";
 import "perfetto/config/ftrace/ftrace_config.proto";
 import "perfetto/config/inode_file/inode_file_config.proto";
+import "perfetto/config/process_stats/process_stats_config.proto";
 import "perfetto/config/test_config.proto";
 // When editing this file run ./tools/gen_tracing_cpp_headers_from_protos.py
 // to reflect changes in the corresponding C++ headers.
@@ -51,6 +52,7 @@
   optional FtraceConfig ftrace_config = 100;
   optional ChromeConfig chrome_config = 101;
   optional InodeFileConfig inode_file_config = 102;
+  optional ProcessStatsConfig process_stats_config = 103;
 
   // This is a fallback mechanism to send a free-form text config to the
   // producer. In theory this should never be needed. All the code that
diff --git a/protos/perfetto/config/perfetto_config.proto b/protos/perfetto/config/perfetto_config.proto
index 01a3785..4efae27 100644
--- a/protos/perfetto/config/perfetto_config.proto
+++ b/protos/perfetto/config/perfetto_config.proto
@@ -56,6 +56,24 @@
 
 // End of protos/perfetto/config/inode_file/inode_file_config.proto
 
+// Begin of protos/perfetto/config/process_stats/process_stats_config.proto
+
+// When editing this file run ./tools/gen_tracing_cpp_headers_from_protos.py
+// to reflect changes in the corresponding C++ headers.
+
+message ProcessStatsConfig {
+  enum Quirks {
+    QUIRKS_UNSPECIFIED = 0;
+    DISABLE_INITIAL_DUMP = 1;
+    // TODO(taylori) Not implemented.
+    DISABLE_ON_DEMAND = 2;
+  }
+
+  repeated Quirks quirks = 1;
+}
+
+// End of protos/perfetto/config/process_stats/process_stats_config.proto
+
 // Begin of protos/perfetto/config/data_source_config.proto
 
 // When editing this file run ./tools/gen_tracing_cpp_headers_from_protos.py
@@ -86,6 +104,7 @@
   optional FtraceConfig ftrace_config = 100;
   optional ChromeConfig chrome_config = 101;
   optional InodeFileConfig inode_file_config = 102;
+  optional ProcessStatsConfig process_stats_config = 103;
 
   // This is a fallback mechanism to send a free-form text config to the
   // producer. In theory this should never be needed. All the code that
diff --git a/protos/perfetto/config/process_stats/process_stats_config.proto b/protos/perfetto/config/process_stats/process_stats_config.proto
new file mode 100644
index 0000000..bce97e7
--- /dev/null
+++ b/protos/perfetto/config/process_stats/process_stats_config.proto
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2018 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;
+
+// When editing this file run ./tools/gen_tracing_cpp_headers_from_protos.py
+// to reflect changes in the corresponding C++ headers.
+
+message ProcessStatsConfig {
+  enum Quirks {
+    QUIRKS_UNSPECIFIED = 0;
+    DISABLE_INITIAL_DUMP = 1;
+    // TODO(taylori) Not implemented.
+    DISABLE_ON_DEMAND = 2;
+  }
+
+  repeated Quirks quirks = 1;
+}
diff --git a/src/traced/probes/probes_producer.cc b/src/traced/probes/probes_producer.cc
index 6d5cf78..c6ea68a 100644
--- a/src/traced/probes/probes_producer.cc
+++ b/src/traced/probes/probes_producer.cc
@@ -206,6 +206,13 @@
       new ProcessStatsDataSource(session_id, std::move(trace_writer)));
   auto it_and_inserted = process_stats_sources_.emplace(id, std::move(source));
   PERFETTO_DCHECK(it_and_inserted.second);
+  if (std::find(config.process_stats_config().quirks().begin(),
+                config.process_stats_config().quirks().end(),
+                ProcessStatsConfig::DISABLE_INITIAL_DUMP) !=
+      config.process_stats_config().quirks().end()) {
+    PERFETTO_DLOG("Initial process tree dump is disabled.");
+    return;
+  }
   it_and_inserted.first->second->WriteAllProcesses();
 }
 
diff --git a/src/tracing/BUILD.gn b/src/tracing/BUILD.gn
index fa39c0a..68eee89 100644
--- a/src/tracing/BUILD.gn
+++ b/src/tracing/BUILD.gn
@@ -43,6 +43,7 @@
     "core/packet_stream_validator.cc",
     "core/packet_stream_validator.h",
     "core/patch_list.h",
+    "core/process_stats_config.cc",
     "core/service_impl.cc",
     "core/service_impl.h",
     "core/shared_memory_abi.cc",
diff --git a/src/tracing/core/data_source_config.cc b/src/tracing/core/data_source_config.cc
index fcc497a..56192e8 100644
--- a/src/tracing/core/data_source_config.cc
+++ b/src/tracing/core/data_source_config.cc
@@ -31,6 +31,7 @@
 #include "perfetto/config/data_source_config.pb.h"
 #include "perfetto/config/ftrace/ftrace_config.pb.h"
 #include "perfetto/config/inode_file/inode_file_config.pb.h"
+#include "perfetto/config/process_stats/process_stats_config.pb.h"
 #include "perfetto/config/test_config.pb.h"
 
 namespace perfetto {
@@ -63,6 +64,8 @@
 
   inode_file_config_.FromProto(proto.inode_file_config());
 
+  process_stats_config_.FromProto(proto.process_stats_config());
+
   static_assert(sizeof(legacy_config_) == sizeof(proto.legacy_config()),
                 "size mismatch");
   legacy_config_ = static_cast<decltype(legacy_config_)>(proto.legacy_config());
@@ -95,6 +98,8 @@
 
   inode_file_config_.ToProto(proto->mutable_inode_file_config());
 
+  process_stats_config_.ToProto(proto->mutable_process_stats_config());
+
   static_assert(sizeof(legacy_config_) == sizeof(proto->legacy_config()),
                 "size mismatch");
   proto->set_legacy_config(
diff --git a/src/tracing/core/ftrace_config.cc b/src/tracing/core/ftrace_config.cc
index 34d8ef4..cf0891f 100644
--- a/src/tracing/core/ftrace_config.cc
+++ b/src/tracing/core/ftrace_config.cc
@@ -84,19 +84,21 @@
   proto->Clear();
 
   for (const auto& it : ftrace_events_) {
-    proto->add_ftrace_events(it);
+    proto->add_ftrace_events(
+        static_cast<decltype(proto->ftrace_events(0))>(it));
     static_assert(sizeof(it) == sizeof(proto->ftrace_events(0)),
                   "size mismatch");
   }
 
   for (const auto& it : atrace_categories_) {
-    proto->add_atrace_categories(it);
+    proto->add_atrace_categories(
+        static_cast<decltype(proto->atrace_categories(0))>(it));
     static_assert(sizeof(it) == sizeof(proto->atrace_categories(0)),
                   "size mismatch");
   }
 
   for (const auto& it : atrace_apps_) {
-    proto->add_atrace_apps(it);
+    proto->add_atrace_apps(static_cast<decltype(proto->atrace_apps(0))>(it));
     static_assert(sizeof(it) == sizeof(proto->atrace_apps(0)), "size mismatch");
   }
 
diff --git a/src/tracing/core/inode_file_config.cc b/src/tracing/core/inode_file_config.cc
index a535d0a..bd831bc 100644
--- a/src/tracing/core/inode_file_config.cc
+++ b/src/tracing/core/inode_file_config.cc
@@ -100,7 +100,8 @@
       static_cast<decltype(proto->do_not_scan())>(do_not_scan_));
 
   for (const auto& it : scan_mount_points_) {
-    proto->add_scan_mount_points(it);
+    proto->add_scan_mount_points(
+        static_cast<decltype(proto->scan_mount_points(0))>(it));
     static_assert(sizeof(it) == sizeof(proto->scan_mount_points(0)),
                   "size mismatch");
   }
@@ -151,7 +152,7 @@
       static_cast<decltype(proto->mountpoint())>(mountpoint_));
 
   for (const auto& it : scan_roots_) {
-    proto->add_scan_roots(it);
+    proto->add_scan_roots(static_cast<decltype(proto->scan_roots(0))>(it));
     static_assert(sizeof(it) == sizeof(proto->scan_roots(0)), "size mismatch");
   }
   *(proto->mutable_unknown_fields()) = unknown_fields_;
diff --git a/src/tracing/core/process_stats_config.cc b/src/tracing/core/process_stats_config.cc
new file mode 100644
index 0000000..fabf7d6
--- /dev/null
+++ b/src/tracing/core/process_stats_config.cc
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+/*******************************************************************************
+ * AUTOGENERATED - DO NOT EDIT
+ *******************************************************************************
+ * This file has been generated from the protobuf message
+ * perfetto/config/process_stats/process_stats_config.proto
+ * by
+ * ../../tools/proto_to_cpp/proto_to_cpp.cc.
+ * If you need to make changes here, change the .proto file and then run
+ * ./tools/gen_tracing_cpp_headers_from_protos.py
+ */
+
+#include "perfetto/tracing/core/process_stats_config.h"
+
+#include "perfetto/config/process_stats/process_stats_config.pb.h"
+
+namespace perfetto {
+
+ProcessStatsConfig::ProcessStatsConfig() = default;
+ProcessStatsConfig::~ProcessStatsConfig() = default;
+ProcessStatsConfig::ProcessStatsConfig(const ProcessStatsConfig&) = default;
+ProcessStatsConfig& ProcessStatsConfig::operator=(const ProcessStatsConfig&) =
+    default;
+ProcessStatsConfig::ProcessStatsConfig(ProcessStatsConfig&&) noexcept = default;
+ProcessStatsConfig& ProcessStatsConfig::operator=(ProcessStatsConfig&&) =
+    default;
+
+void ProcessStatsConfig::FromProto(
+    const perfetto::protos::ProcessStatsConfig& proto) {
+  quirks_.clear();
+  for (const auto& field : proto.quirks()) {
+    quirks_.emplace_back();
+    static_assert(sizeof(quirks_.back()) == sizeof(proto.quirks(0)),
+                  "size mismatch");
+    quirks_.back() = static_cast<decltype(quirks_)::value_type>(field);
+  }
+  unknown_fields_ = proto.unknown_fields();
+}
+
+void ProcessStatsConfig::ToProto(
+    perfetto::protos::ProcessStatsConfig* proto) const {
+  proto->Clear();
+
+  for (const auto& it : quirks_) {
+    proto->add_quirks(static_cast<decltype(proto->quirks(0))>(it));
+    static_assert(sizeof(it) == sizeof(proto->quirks(0)), "size mismatch");
+  }
+  *(proto->mutable_unknown_fields()) = unknown_fields_;
+}
+
+}  // namespace perfetto
diff --git a/src/tracing/core/trace_config.cc b/src/tracing/core/trace_config.cc
index 68d371b..f3bfca5 100644
--- a/src/tracing/core/trace_config.cc
+++ b/src/tracing/core/trace_config.cc
@@ -220,7 +220,8 @@
   config_.ToProto(proto->mutable_config());
 
   for (const auto& it : producer_name_filter_) {
-    proto->add_producer_name_filter(it);
+    proto->add_producer_name_filter(
+        static_cast<decltype(proto->producer_name_filter(0))>(it));
     static_assert(sizeof(it) == sizeof(proto->producer_name_filter(0)),
                   "size mismatch");
   }
diff --git a/tools/gen_merged_trace_config b/tools/gen_merged_trace_config
index 719c734..135fd02 100755
--- a/tools/gen_merged_trace_config
+++ b/tools/gen_merged_trace_config
@@ -21,6 +21,7 @@
 PROTOS = (
   'protos/perfetto/config/chrome/chrome_config.proto',
   'protos/perfetto/config/inode_file/inode_file_config.proto',
+  'protos/perfetto/config/process_stats/process_stats_config.proto',
   'protos/perfetto/config/data_source_config.proto',
   'protos/perfetto/config/ftrace/ftrace_config.proto',
   'protos/perfetto/config/test_config.proto',
diff --git a/tools/gen_tracing_cpp_headers_from_protos.py b/tools/gen_tracing_cpp_headers_from_protos.py
index c10bac0..ce7fdb6 100755
--- a/tools/gen_tracing_cpp_headers_from_protos.py
+++ b/tools/gen_tracing_cpp_headers_from_protos.py
@@ -21,6 +21,7 @@
   'perfetto/config/chrome/chrome_config.proto',
   'perfetto/config/data_source_config.proto',
   'perfetto/config/inode_file/inode_file_config.proto',
+  'perfetto/config/process_stats/process_stats_config.proto',
   'perfetto/config/data_source_descriptor.proto',
   'perfetto/config/ftrace/ftrace_config.proto',
   'perfetto/config/trace_config.proto',
diff --git a/tools/proto_to_cpp/proto_to_cpp.cc b/tools/proto_to_cpp/proto_to_cpp.cc
index 82fe8c0..6696c57 100644
--- a/tools/proto_to_cpp/proto_to_cpp.cc
+++ b/tools/proto_to_cpp/proto_to_cpp.cc
@@ -451,7 +451,9 @@
         p->Print("  auto* entry = proto->add_$n$();\n", "n", field->name());
         p->Print("  it.ToProto(entry);\n");
       } else {
-        p->Print("  proto->add_$n$(it);\n", "n", field->name());
+        p->Print(
+            "  proto->add_$n$(static_cast<decltype(proto->$n$(0))>(it));\n",
+            "n", field->name());
         p->Print(
             "static_assert(sizeof(it) == sizeof(proto->$n$(0)), \"size "
             "mismatch\");\n",