From 6d087d5dc5f301516f51f94832ba093ba2f01129 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Tue, 8 Aug 2017 12:29:04 -0700 Subject: [PATCH] simpleperf: add --exit-with-parent option in record cmd. This makes it optional whether simpleperf stops recording when the parent dies. Bug: http://b/64391339 Test: run simpleperf_unit_test. Change-Id: I0827a17d6fedbb9763347df76da9dc981fea6312 --- simpleperf/cmd_record.cpp | 6 ++++-- simpleperf/cmd_record_test.cpp | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp index 487e2199..6b2be764 100644 --- a/simpleperf/cmd_record.cpp +++ b/simpleperf/cmd_record.cpp @@ -155,6 +155,8 @@ class RecordCommand : public Command { " will be unwound while recording by default. But it may lose\n" " records as stacking unwinding can be time consuming. Use this\n" " option to unwind the user's stack after recording.\n" +"--exit-with-parent Stop recording when the process starting\n" +" simpleperf dies.\n" "--start_profiling_fd fd_no After starting profiling, write \"STARTED\" to\n" " , then close .\n" "--symfs Look for files with symbols relative to this directory.\n" @@ -188,8 +190,6 @@ class RecordCommand : public Command { in_app_context_(false), trace_offcpu_(false), exclude_kernel_callchain_(false) { - // Stop profiling if parent exits. - prctl(PR_SET_PDEATHSIG, SIGHUP, 0, 0, 0); // If we run `adb shell simpleperf record xxx` and stop profiling by ctrl-c, adb closes // sockets connecting simpleperf. After that, simpleperf will receive SIGPIPE when writing // to stdout/stderr, which is a problem when we use '--app' option. So ignore SIGPIPE to @@ -525,6 +525,8 @@ bool RecordCommand::ParseOptions(const std::vector& args, wait_setting_speed_event_groups_.push_back(group_id); } } + } else if (args[i] == "--exit-with-parent") { + prctl(PR_SET_PDEATHSIG, SIGHUP, 0, 0, 0); } else if (args[i] == "-g") { fp_callchain_sampling_ = false; dwarf_callchain_sampling_ = true; diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index 48732302..56e1b225 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -486,3 +486,7 @@ TEST(record_cmd, trace_offcpu_option) { ASSERT_EQ(info_map["trace_offcpu"], "true"); CheckEventType(tmpfile.path, "sched:sched_switch", 1u, 0u); } + +TEST(record_cmd, exit_with_parent_option) { + ASSERT_TRUE(RunRecordCmd({"--exit-with-parent"})); +} -- 2.11.0