diff options
author | Yabin Cui <yabinc@google.com> | 2015-10-26 16:15:29 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2015-10-30 12:08:08 -0700 |
commit | cb4c17ea53269ced994a2d849cbafb1afd5296e1 (patch) | |
tree | 167b3af4203bc2f74d8a49d986522e47d89f44c5 /simpleperf/event_selection_set.cpp | |
parent | c5ca81d0d4adc1da4325a89dc958b515691a4e0d (diff) | |
download | extras-cb4c17ea53269ced994a2d849cbafb1afd5296e1.tar.gz |
simpleperf: support --cpu option in record/stat command.
--cpu option is used to record on selected cpus.
Change-Id: If5bb9b42a064d2ff69fbeec77906fc79943dddc1
Diffstat (limited to 'simpleperf/event_selection_set.cpp')
-rw-r--r-- | simpleperf/event_selection_set.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/simpleperf/event_selection_set.cpp b/simpleperf/event_selection_set.cpp index e42b89a4..1a9de630 100644 --- a/simpleperf/event_selection_set.cpp +++ b/simpleperf/event_selection_set.cpp @@ -166,18 +166,29 @@ void EventSelectionSet::SetInherit(bool enable) { } } -bool EventSelectionSet::OpenEventFilesForAllCpus() { - return OpenEventFilesForThreadsOnAllCpus({-1}); +static bool CheckIfCpusOnline(const std::vector<int>& cpus) { + std::vector<int> online_cpus = GetOnlineCpus(); + for (const auto& cpu : cpus) { + if (std::find(online_cpus.begin(), online_cpus.end(), cpu) == online_cpus.end()) { + LOG(ERROR) << "cpu " << cpu << " is not online."; + return false; + } + } + return true; } -bool EventSelectionSet::OpenEventFilesForThreads(const std::vector<pid_t>& threads) { - return OpenEventFiles(threads, {-1}); +bool EventSelectionSet::OpenEventFilesForCpus(const std::vector<int>& cpus) { + return OpenEventFilesForThreadsOnCpus({-1}, cpus); } -bool EventSelectionSet::OpenEventFilesForThreadsOnAllCpus(const std::vector<pid_t>& threads) { - std::vector<int> cpus = GetOnlineCpus(); - if (cpus.empty()) { - return false; +bool EventSelectionSet::OpenEventFilesForThreadsOnCpus(const std::vector<pid_t>& threads, + std::vector<int> cpus) { + if (!cpus.empty()) { + if (!CheckIfCpusOnline(cpus)) { + return false; + } + } else { + cpus = GetOnlineCpus(); } return OpenEventFiles(threads, cpus); } |