summaryrefslogtreecommitdiff
path: root/simpleperf/cmd_stat.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2016-12-13 13:47:49 -0800
committerYabin Cui <yabinc@google.com>2016-12-13 13:55:50 -0800
commit5f43fc4ac870b49542b4cf530a3729f9f1e0e9ab (patch)
tree860ed3a71701008fe72152a4ed938c31b702ca28 /simpleperf/cmd_stat.cpp
parent88ff807ea265e293ca72204e0328f840966bbb93 (diff)
downloadextras-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_stat.cpp')
-rw-r--r--simpleperf/cmd_stat.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/simpleperf/cmd_stat.cpp b/simpleperf/cmd_stat.cpp
index 06258f36..423fbffb 100644
--- a/simpleperf/cmd_stat.cpp
+++ b/simpleperf/cmd_stat.cpp
@@ -349,6 +349,7 @@ bool StatCommand::Run(const std::vector<std::string>& args) {
return false;
}
}
+ bool need_to_check_targets = false;
if (system_wide_collection_) {
event_selection_set_.AddMonitoredThreads({-1});
} else if (!event_selection_set_.HasMonitoredTarget()) {
@@ -360,6 +361,8 @@ bool StatCommand::Run(const std::vector<std::string>& args) {
<< "No threads to monitor. Try `simpleperf help stat` for help\n";
return false;
}
+ } else {
+ need_to_check_targets = true;
}
// 3. Open perf_event_files and output file if defined.
@@ -382,14 +385,18 @@ bool StatCommand::Run(const std::vector<std::string>& args) {
// 4. Create IOEventLoop and add signal/periodic Events.
IOEventLoop loop;
+ event_selection_set_.SetIOEventLoop(loop);
std::chrono::time_point<std::chrono::steady_clock> start_time;
std::vector<CountersInfo> counters;
if (system_wide_collection_ || (!cpus_.empty() && cpus_[0] != -1)) {
- if (!event_selection_set_.HandleCpuHotplugEvents(loop, cpus_)) {
+ if (!event_selection_set_.HandleCpuHotplugEvents(cpus_)) {
return false;
}
}
- if (!loop.AddSignalEvents({SIGCHLD, SIGINT, SIGTERM},
+ if (need_to_check_targets && !event_selection_set_.StopWhenNoMoreTargets()) {
+ return false;
+ }
+ if (!loop.AddSignalEvents({SIGCHLD, SIGINT, SIGTERM, SIGHUP},
[&]() { return loop.ExitLoop(); })) {
return false;
}