diff options
author | Yabin Cui <yabinc@google.com> | 2017-08-25 11:17:45 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2017-08-28 19:07:10 +0000 |
commit | 16006b9403d4e26f56d6492e0fa99b483e5dac31 (patch) | |
tree | 3f1932b819342d8a1b99297aeefdc8aea709ab10 | |
parent | eb29dced7182d4fc955fd380ba97c67f8285e5b0 (diff) | |
download | extras-16006b9403d4e26f56d6492e0fa99b483e5dac31.tar.gz |
simpleperf: fix check of opening perf event files.
When asked to monitor a process, record/stat cmd checks if we can
open perf event files for all threads successfully. However, it
fails when the monitored process has an exiting thread. This makes
record_cmd.duration_option test flakey, when there are exiting
threads in other tests, like record_cmd.handle_SIGHUP.
To fix this, only check if we can open perf event files for at
least one thread for each monitored process.
Bug: http://b/65047463
Bug: 64709603 (presubmit balking at the line above)
Test: run CtsSimpleperfTestCases.
Change-Id: Ia02ed498f49c9c6c452023ad31abb01a58071152
(cherry picked from commit b3ae56e485b4d971a909a8b04da65713a3d56872)
-rw-r--r-- | simpleperf/event_selection_set.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/simpleperf/event_selection_set.cpp b/simpleperf/event_selection_set.cpp index 86f57b9d..7458572d 100644 --- a/simpleperf/event_selection_set.cpp +++ b/simpleperf/event_selection_set.cpp @@ -342,7 +342,7 @@ bool EventSelectionSet::OpenEventFilesOnGroup(EventSelectionGroup& group, EventFd* group_fd = nullptr; for (auto& selection : group) { std::unique_ptr<EventFd> event_fd = - EventFd::OpenEventFile(selection.event_attr, tid, cpu, group_fd); + EventFd::OpenEventFile(selection.event_attr, tid, cpu, group_fd, false); if (event_fd != nullptr) { LOG(VERBOSE) << "OpenEventFile for " << event_fd->Name(); event_fds.push_back(std::move(event_fd)); @@ -402,24 +402,25 @@ bool EventSelectionSet::OpenEventFiles(const std::vector<int>& on_cpus) { } } else { for (const auto& pair : process_map) { + size_t success_count = 0; + std::string failed_event_type; for (const auto& tid : pair.second) { - size_t success_cpu_count = 0; - std::string failed_event_type; for (const auto& cpu : cpus) { if (OpenEventFilesOnGroup(group, tid, cpu, &failed_event_type)) { - success_cpu_count++; + success_count++; } } - // As the online cpus can be enabled or disabled at runtime, we may not - // open event file for all cpus successfully. But we should open at - // least one cpu successfully. - if (success_cpu_count == 0) { - PLOG(ERROR) << "failed to open perf event file for event_type " - << failed_event_type << " for " - << (tid == -1 ? "all threads" : "thread " + std::to_string(tid)) - << " on all cpus"; - return false; - } + } + // We can't guarantee to open perf event file successfully for each thread on each cpu. + // Because threads may exit between PrepareThreads() and OpenEventFilesOnGroup(), and + // cpus may be offlined between GetOnlineCpus() and OpenEventFilesOnGroup(). + // So we only check that we can at least monitor one thread for each process. + if (success_count == 0) { + PLOG(ERROR) << "failed to open perf event file for event_type " + << failed_event_type << " for " + << (pair.first == -1 ? "all threads" + : "threads in process " + std::to_string(pair.first)); + return false; } } } |