summaryrefslogtreecommitdiff
path: root/simpleperf/event_selection_set.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2015-06-09 13:38:42 -0700
committerYabin Cui <yabinc@google.com>2015-06-10 16:56:41 -0700
commit7d4904d5fc038f8125cfc63a5eaa4669ee2aebda (patch)
treece69dfcb8782e8ec50a2a692ebcde6b9b2ee8d16 /simpleperf/event_selection_set.cpp
parentf7383f39e5a66731e6e34ca85c1ad599f39faf1d (diff)
downloadextras-7d4904d5fc038f8125cfc63a5eaa4669ee2aebda.tar.gz
Simpleperf: fix a few bugs.
Fix mistyped word. Kill workload process when exiting. Add checking of whether branch sampling is supported. Bug: 19483574 Change-Id: Ibe48914cd92da1ee40bf67c0c47a6376a7291e8c
Diffstat (limited to 'simpleperf/event_selection_set.cpp')
-rw-r--r--simpleperf/event_selection_set.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/simpleperf/event_selection_set.cpp b/simpleperf/event_selection_set.cpp
index 6f14b804..644938c1 100644
--- a/simpleperf/event_selection_set.cpp
+++ b/simpleperf/event_selection_set.cpp
@@ -22,6 +22,18 @@
#include "event_attr.h"
#include "event_type.h"
+bool IsBranchSamplingSupported() {
+ const EventType* event_type = EventTypeFactory::FindEventTypeByName("cpu-cycles", false);
+ if (event_type == nullptr) {
+ return false;
+ }
+ perf_event_attr attr = CreateDefaultPerfEventAttr(*event_type);
+ attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
+ attr.branch_sample_type = PERF_SAMPLE_BRANCH_ANY;
+ auto event_fd = EventFd::OpenEventFileForProcess(attr, getpid(), false);
+ return event_fd != nullptr;
+}
+
void EventSelectionSet::AddEventType(const EventType& event_type) {
EventSelection selection;
selection.event_type = &event_type;
@@ -64,6 +76,10 @@ bool EventSelectionSet::SetBranchSampling(uint64_t branch_sample_type) {
LOG(ERROR) << "Invalid branch_sample_type: 0x" << std::hex << branch_sample_type;
return false;
}
+ if (branch_sample_type != 0 && !IsBranchSamplingSupported()) {
+ LOG(ERROR) << "branch stack sampling is not supported on this device.";
+ return false;
+ }
for (auto& selection : selections_) {
perf_event_attr& attr = selection.event_attr;
if (branch_sample_type != 0) {
@@ -103,8 +119,6 @@ bool EventSelectionSet::OpenEventFilesForProcess(pid_t pid) {
for (auto& selection : selections_) {
auto event_fd = EventFd::OpenEventFileForProcess(selection.event_attr, pid);
if (event_fd == nullptr) {
- PLOG(ERROR) << "failed to open perf event file for event type " << selection.event_type->name
- << " on pid " << pid;
return false;
}
selection.event_fds.push_back(std::move(event_fd));