diff options
author | Yabin Cui <yabinc@google.com> | 2016-12-13 13:47:49 -0800 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2016-12-13 13:55:50 -0800 |
commit | 5f43fc4ac870b49542b4cf530a3729f9f1e0e9ab (patch) | |
tree | 860ed3a71701008fe72152a4ed938c31b702ca28 /simpleperf/cmd_record_test.cpp | |
parent | 88ff807ea265e293ca72204e0328f840966bbb93 (diff) | |
download | extras-5f43fc4ac870b49542b4cf530a3729f9f1e0e9ab.tar.gz |
simpleperf: check monitored targets regularly.
When monitoring some threads/processes not forked by simpleperf,
check if these threads/processes exist regularly. So we can
stop profiling once all threads/processes exit.
Also handle SIGHUP signal, so we can finish profiling properly
when `adb shell simpleperf record xxx` is killed by Ctrl-C.
Add corresponding tests.
Bug: http://b/33558210
Test: run simpleperf_unit_test.
Change-Id: Ieae4d00d099dc1c7a0c51b0610dff43981bb642e
Diffstat (limited to 'simpleperf/cmd_record_test.cpp')
-rw-r--r-- | simpleperf/cmd_record_test.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp index 35f330ef..28e2e9b1 100644 --- a/simpleperf/cmd_record_test.cpp +++ b/simpleperf/cmd_record_test.cpp @@ -18,9 +18,11 @@ #include <android-base/stringprintf.h> #include <android-base/test_utils.h> +#include <sys/syscall.h> #include <map> #include <memory> +#include <thread> #include "command.h" #include "environment.h" @@ -335,3 +337,25 @@ TEST(record_cmd, support_modifier_for_clock_events) { } } } + +TEST(record_cmd, handle_SIGHUP) { + TemporaryFile tmpfile; + std::thread thread([]() { + sleep(1); + kill(getpid(), SIGHUP); + }); + thread.detach(); + ASSERT_TRUE(RecordCmd()->Run({"-o", tmpfile.path, "sleep", "1000000"})); +} + +TEST(record_cmd, stop_when_no_more_targets) { + TemporaryFile tmpfile; + std::atomic<int> tid(0); + std::thread thread([&]() { + tid = syscall(__NR_gettid); + sleep(1); + }); + thread.detach(); + while (tid == 0); + ASSERT_TRUE(RecordCmd()->Run({"-o", tmpfile.path, "-t", std::to_string(tid)})); +} |