summaryrefslogtreecommitdiff
path: root/simpleperf/event_selection_set.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2015-06-25 17:42:23 -0700
committerYabin Cui <yabinc@google.com>2015-06-29 14:48:38 -0700
commit9fd3cc1048a3d0338df4a48760dfd655560992a1 (patch)
tree531ebc2c2aad8a0b0094bba788a06ad96835af07 /simpleperf/event_selection_set.cpp
parent19fadc64c50a13a1e65ad43b50cd15ea96263371 (diff)
downloadextras-9fd3cc1048a3d0338df4a48760dfd655560992a1.tar.gz
Simpleperf: support build on mac.
Bug: 19483574 Change-Id: I6c28541944bc0a4e6fc07d7ea5a8fb5f71890510
Diffstat (limited to 'simpleperf/event_selection_set.cpp')
-rw-r--r--simpleperf/event_selection_set.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/simpleperf/event_selection_set.cpp b/simpleperf/event_selection_set.cpp
index 0f23c149..a9a0f969 100644
--- a/simpleperf/event_selection_set.cpp
+++ b/simpleperf/event_selection_set.cpp
@@ -24,18 +24,17 @@
#include "event_type.h"
bool IsBranchSamplingSupported() {
- std::unique_ptr<EventTypeAndModifier> event_type_modifier = ParseEventType("cpu-cycles", false);
- if (event_type_modifier == nullptr) {
+ const EventType* type = FindEventTypeByName("cpu-cycles");
+ if (type == nullptr) {
return false;
}
- perf_event_attr attr = CreateDefaultPerfEventAttr(event_type_modifier->event_type);
+ perf_event_attr attr = CreateDefaultPerfEventAttr(*type);
attr.sample_type |= PERF_SAMPLE_BRANCH_STACK;
attr.branch_sample_type = PERF_SAMPLE_BRANCH_ANY;
- auto event_fd = EventFd::OpenEventFile(attr, getpid(), -1, false);
- return event_fd != nullptr;
+ return IsEventAttrSupportedByKernel(attr);
}
-void EventSelectionSet::AddEventType(const EventTypeAndModifier& event_type_modifier) {
+bool EventSelectionSet::AddEventType(const EventTypeAndModifier& event_type_modifier) {
EventSelection selection;
selection.event_type = event_type_modifier.event_type;
selection.event_attr = CreateDefaultPerfEventAttr(event_type_modifier.event_type);
@@ -45,7 +44,12 @@ void EventSelectionSet::AddEventType(const EventTypeAndModifier& event_type_modi
selection.event_attr.exclude_host = event_type_modifier.exclude_host;
selection.event_attr.exclude_guest = event_type_modifier.exclude_guest;
selection.event_attr.precise_ip = event_type_modifier.precise_ip;
+ if (!IsEventAttrSupportedByKernel(selection.event_attr)) {
+ LOG(ERROR) << "Event type '" << selection.event_type.name << "' is not supported by the kernel";
+ return false;
+ }
selections_.push_back(std::move(selection));
+ return true;
}
void EventSelectionSet::SetEnableOnExec(bool enable) {