From a5d86d2d3951c82b20fd195edf705bfb81fe21be Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Fri, 4 Oct 2019 16:13:52 -0700 Subject: [PATCH 1/4] Unblock SIGPROF on flutter_tester start Fixes https://github.com/flutter/flutter/issues/35140 --- shell/testing/tester_main.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/shell/testing/tester_main.cc b/shell/testing/tester_main.cc index 52f6b15590f6c..3390b9ff62f1b 100644 --- a/shell/testing/tester_main.cc +++ b/shell/testing/tester_main.cc @@ -6,6 +6,10 @@ #include +#if defined(OS_POSIX) +#include +#endif // defined(OS_POSIX) + #include "flutter/assets/asset_manager.h" #include "flutter/assets/directory_asset_bundle.h" #include "flutter/fml/file.h" @@ -71,9 +75,31 @@ class ScriptCompletionTaskObserver { FML_DISALLOW_COPY_AND_ASSIGN(ScriptCompletionTaskObserver); }; +// Processes spawned via dart:io inherit their signal handling from the parent +// process. As part of spawning, the spawner blocks signals temporarily, so we +// need to explicitly unblock the signals we care about in the new process. In +// particular, we need to unblock SIGPROF for CPU profiling to work on the +// mutator thread in the main isolate in this process (threads spawned by the VM +// know about this limitation and automatically have this signal unblocked). +static void UnblockSIGPROF() { +#if defined(OS_POSIX) + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGPROF); + pthread_sigmask(SIG_UNBLOCK, &set, NULL); +#endif // defined(OS_POSIX) +} + int RunTester(const flutter::Settings& settings, bool run_forever) { const auto thread_label = "io.flutter.test"; + // Necessary if we want to use the CPU profiler on the main isolate's mutator + // thread. See https://github.com/flutter/flutter/issues/35140. + // + // OSX WARNING: avoid spawning additional threads before this call due to a + // kernel bug that may enable SIGPROF on an unintended thread in the process. + UnblockSIGPROF(); + fml::MessageLoop::EnsureInitializedForCurrentThread(); auto current_task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner(); From 1f5a74f3195649e408d7be960098caf120d8bac9 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Mon, 7 Oct 2019 08:42:17 -0700 Subject: [PATCH 2/4] Move signal.h include --- shell/testing/tester_main.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shell/testing/tester_main.cc b/shell/testing/tester_main.cc index 3390b9ff62f1b..0f17ed5ec3a6b 100644 --- a/shell/testing/tester_main.cc +++ b/shell/testing/tester_main.cc @@ -6,10 +6,6 @@ #include -#if defined(OS_POSIX) -#include -#endif // defined(OS_POSIX) - #include "flutter/assets/asset_manager.h" #include "flutter/assets/directory_asset_bundle.h" #include "flutter/fml/file.h" @@ -26,6 +22,10 @@ #include "third_party/dart/runtime/include/bin/dart_io_api.h" #include "third_party/dart/runtime/include/dart_api.h" +#if defined(OS_POSIX) +#include +#endif // defined(OS_POSIX) + namespace flutter { // Checks whether the engine's main Dart isolate has no pending work. If so, From c277cee6e11f83b654240d658113276cfe8f29ab Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Mon, 7 Oct 2019 08:48:54 -0700 Subject: [PATCH 3/4] Formatting --- shell/testing/tester_main.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/testing/tester_main.cc b/shell/testing/tester_main.cc index 0f17ed5ec3a6b..5bc58b35cd152 100644 --- a/shell/testing/tester_main.cc +++ b/shell/testing/tester_main.cc @@ -24,7 +24,7 @@ #if defined(OS_POSIX) #include -#endif // defined(OS_POSIX) +#endif // defined(OS_POSIX) namespace flutter { @@ -87,7 +87,7 @@ static void UnblockSIGPROF() { sigemptyset(&set); sigaddset(&set, SIGPROF); pthread_sigmask(SIG_UNBLOCK, &set, NULL); -#endif // defined(OS_POSIX) +#endif // defined(OS_POSIX) } int RunTester(const flutter::Settings& settings, bool run_forever) { From 6d7f45fb7194a39995bf58861d91aba8d0848c30 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Tue, 8 Oct 2019 15:12:39 -0700 Subject: [PATCH 4/4] Update tester_main.cc --- shell/testing/tester_main.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/testing/tester_main.cc b/shell/testing/tester_main.cc index 5bc58b35cd152..c1560e982b207 100644 --- a/shell/testing/tester_main.cc +++ b/shell/testing/tester_main.cc @@ -94,7 +94,7 @@ int RunTester(const flutter::Settings& settings, bool run_forever) { const auto thread_label = "io.flutter.test"; // Necessary if we want to use the CPU profiler on the main isolate's mutator - // thread. See https://github.com/flutter/flutter/issues/35140. + // thread. // // OSX WARNING: avoid spawning additional threads before this call due to a // kernel bug that may enable SIGPROF on an unintended thread in the process.