Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Unblock SIGPROF on flutter_tester start #12813

Merged
merged 4 commits into from
Oct 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions shell/testing/tester_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,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 <signal.h>
#endif // defined(OS_POSIX)

namespace flutter {

// Checks whether the engine's main Dart isolate has no pending work. If so,
Expand Down Expand Up @@ -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.
//
// 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();
Expand Down