Merge "Infra: fix AOSP->GitHub mirror bot"
diff --git a/BUILD b/BUILD
index 717a6f6..27acaed 100644
--- a/BUILD
+++ b/BUILD
@@ -57,6 +57,7 @@
         "include/perfetto/base/hash.h",
         "include/perfetto/base/logging.h",
         "include/perfetto/base/metatrace.h",
+        "include/perfetto/base/no_destructor.h",
         "include/perfetto/base/optional.h",
         "include/perfetto/base/paged_memory.h",
         "include/perfetto/base/pipe.h",
@@ -240,6 +241,7 @@
         "include/perfetto/base/hash.h",
         "include/perfetto/base/logging.h",
         "include/perfetto/base/metatrace.h",
+        "include/perfetto/base/no_destructor.h",
         "include/perfetto/base/optional.h",
         "include/perfetto/base/paged_memory.h",
         "include/perfetto/base/pipe.h",
@@ -310,6 +312,7 @@
         "include/perfetto/base/hash.h",
         "include/perfetto/base/logging.h",
         "include/perfetto/base/metatrace.h",
+        "include/perfetto/base/no_destructor.h",
         "include/perfetto/base/optional.h",
         "include/perfetto/base/paged_memory.h",
         "include/perfetto/base/pipe.h",
@@ -499,6 +502,7 @@
         "include/perfetto/base/hash.h",
         "include/perfetto/base/logging.h",
         "include/perfetto/base/metatrace.h",
+        "include/perfetto/base/no_destructor.h",
         "include/perfetto/base/optional.h",
         "include/perfetto/base/paged_memory.h",
         "include/perfetto/base/pipe.h",
diff --git a/include/perfetto/base/BUILD.gn b/include/perfetto/base/BUILD.gn
index ebfb9f4..536217e 100644
--- a/include/perfetto/base/BUILD.gn
+++ b/include/perfetto/base/BUILD.gn
@@ -26,6 +26,7 @@
     "hash.h",
     "logging.h",
     "metatrace.h",
+    "no_destructor.h",
     "optional.h",
     "paged_memory.h",
     "pipe.h",
diff --git a/protos/BUILD b/protos/BUILD
index 689b678..b41edf1 100644
--- a/protos/BUILD
+++ b/protos/BUILD
@@ -113,6 +113,31 @@
     ],
 )
 
+# GN target: //protos/perfetto/config:merged_config_gen
+proto_library(
+    name = "config_merged_config_gen",
+    srcs = [
+        "perfetto/config/perfetto_config.proto",
+    ],
+    has_services = 1,
+    cc_api_version = 2,
+    cc_generic_services = 1,
+    visibility = [
+        "//visibility:public",
+    ],
+)
+
+# GN target: //protos/perfetto/config:merged_config_gen
+cc_proto_library(
+    name = "config_merged_config_gen_cc_proto",
+    visibility = [
+        "//visibility:public",
+    ],
+    deps = [
+        "//third_party/perfetto/protos:config_merged_config_gen",
+    ],
+)
+
 # GN target: //protos/perfetto/config:zero_gen
 proto_library(
     name = "config_zero",
@@ -507,6 +532,31 @@
     ],
 )
 
+# GN target: //protos/perfetto/trace:merged_trace_gen
+proto_library(
+    name = "trace_merged_trace_gen",
+    srcs = [
+        "perfetto/trace/perfetto_trace.proto",
+    ],
+    has_services = 1,
+    cc_api_version = 2,
+    cc_generic_services = 1,
+    visibility = [
+        "//visibility:public",
+    ],
+)
+
+# GN target: //protos/perfetto/trace:merged_trace_gen
+cc_proto_library(
+    name = "trace_merged_trace_gen_cc_proto",
+    visibility = [
+        "//visibility:public",
+    ],
+    deps = [
+        "//third_party/perfetto/protos:trace_merged_trace_gen",
+    ],
+)
+
 # GN target: //protos/perfetto/trace:minimal_lite_gen
 proto_library(
     name = "trace_minimal",
diff --git a/src/profiling/memory/client.cc b/src/profiling/memory/client.cc
index e91f720..07dd272 100644
--- a/src/profiling/memory/client.cc
+++ b/src/profiling/memory/client.cc
@@ -202,7 +202,6 @@
   PERFETTO_DCHECK(client_config.interval >= 1);
   Sampler sampler{client_config.interval};
   // note: the shared_ptr will retain a copy of the unhooked_allocator
-  sock.SetBlocking(false);
   return std::allocate_shared<Client>(
       unhooked_allocator, std::move(sock), client_config,
       std::move(shmem.value()), std::move(sampler), FindMainThreadStack());
@@ -218,7 +217,6 @@
       sock_(std::move(sock)),
       main_thread_stack_base_(main_thread_stack_base),
       shmem_(std::move(shmem)) {
-  PERFETTO_DCHECK(!sock_.IsBlocking());
 }
 
 const char* Client::GetStackBase() {
@@ -311,21 +309,8 @@
   return SendControlSocketByte();
 }
 
-bool Client::IsConnected() {
-  PERFETTO_DCHECK(!sock_.IsBlocking());
-  char buf[1];
-  ssize_t recv_bytes = sock_.Receive(buf, sizeof(buf), nullptr, 0);
-  if (recv_bytes == 0)
-    return false;
-  else if (recv_bytes > 0)
-    return true;
-  return errno == EAGAIN || errno == EWOULDBLOCK;
-}
-
 bool Client::SendControlSocketByte() {
-  PERFETTO_DCHECK(!sock_.IsBlocking());
-  if (sock_.Send(kSingleByte, sizeof(kSingleByte)) == -1 && errno != EAGAIN &&
-      errno != EWOULDBLOCK) {
+  if (sock_.Send(kSingleByte, sizeof(kSingleByte)) == -1) {
     PERFETTO_PLOG("Failed to send control socket byte.");
     return false;
   }
diff --git a/src/profiling/memory/client.h b/src/profiling/memory/client.h
index 745fd68..3098d35 100644
--- a/src/profiling/memory/client.h
+++ b/src/profiling/memory/client.h
@@ -90,7 +90,6 @@
          const char* main_thread_stack_base);
 
   ClientConfiguration client_config_for_testing() { return client_config_; }
-  bool IsConnected();
 
  private:
   const char* GetStackBase();
diff --git a/src/profiling/memory/client_unittest.cc b/src/profiling/memory/client_unittest.cc
index 9329057..e5ed201 100644
--- a/src/profiling/memory/client_unittest.cc
+++ b/src/profiling/memory/client_unittest.cc
@@ -50,24 +50,6 @@
   th.join();
 }
 
-TEST(ClientTest, IsConnected) {
-  auto socketpair = base::UnixSocketRaw::CreatePair(base::SockType::kStream);
-  base::UnixSocketRaw& client_sock = socketpair.first;
-  client_sock.SetBlocking(false);
-  Client c(std::move(client_sock), {}, {}, {1}, nullptr);
-  EXPECT_EQ(c.IsConnected(), true);
-}
-
-TEST(ClientTest, IsDisconnected) {
-  auto socketpair = base::UnixSocketRaw::CreatePair(base::SockType::kStream);
-  base::UnixSocketRaw& client_sock = socketpair.first;
-  base::UnixSocketRaw& service_sock = socketpair.second;
-  client_sock.SetBlocking(false);
-  service_sock = base::UnixSocketRaw();
-  Client c(std::move(client_sock), {}, {}, {1}, nullptr);
-  EXPECT_EQ(c.IsConnected(), false);
-}
-
 }  // namespace
 }  // namespace profiling
 }  // namespace perfetto
diff --git a/src/profiling/memory/malloc_hooks.cc b/src/profiling/memory/malloc_hooks.cc
index c7fe4d5..6070a03 100644
--- a/src/profiling/memory/malloc_hooks.cc
+++ b/src/profiling/memory/malloc_hooks.cc
@@ -377,8 +377,7 @@
     if (PERFETTO_UNLIKELY(!s.locked()))
       AbortOnSpinlockTimeout();
 
-    // Only reject concurrent session if the previous one is still active.
-    if (g_client.ref() && g_client.ref()->IsConnected()) {
+    if (g_client.ref()) {
       PERFETTO_LOG("Rejecting concurrent profiling initialization.");
       return true;  // success as we're in a valid state
     }
diff --git a/tools/gen_build b/tools/gen_build
index e3e2999..307d693 100755
--- a/tools/gen_build
+++ b/tools/gen_build
@@ -62,6 +62,8 @@
   '//src/trace_processor:trace_processor',
   '//src/trace_processor:trace_processor_shell_host(//gn/standalone/toolchain:gcc_like_host)',
   '//tools/trace_to_text:trace_to_text_host(//gn/standalone/toolchain:gcc_like_host)',
+  '//protos/perfetto/config:merged_config_gen',
+  '//protos/perfetto/trace:merged_trace_gen',
 ]
 
 # Aliases to add to the BUILD file