OSDN Git Service

simpleperf: add --exit-with-parent option in record cmd.
authorYabin Cui <yabinc@google.com>
Tue, 8 Aug 2017 19:29:04 +0000 (12:29 -0700)
committerYabin Cui <yabinc@google.com>
Tue, 8 Aug 2017 21:26:12 +0000 (14:26 -0700)
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
simpleperf/cmd_record_test.cpp

index 487e219..6b2be76 100644 (file)
@@ -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"
 "                              <fd_no>, then close <fd_no>.\n"
 "--symfs <dir>    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<std::string>& 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;
index 4873230..56e1b22 100644 (file)
@@ -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"}));
+}