summaryrefslogtreecommitdiff
path: root/simpleperf/event_selection_set.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2015-08-19 15:46:51 -0700
committerYabin Cui <yabinc@google.com>2015-08-19 19:06:42 -0700
commitafdb9cea28340e31142fd66a90c88ed8e18ebbfa (patch)
treea2fa1692ee810fe388f25b0a4b34b9e59eb16f6e /simpleperf/event_selection_set.cpp
parentb84ee6cd81da6a0929035c589f1c0450e8d10902 (diff)
downloadextras-afdb9cea28340e31142fd66a90c88ed8e18ebbfa.tar.gz
Simpleperf: support multiple event types in record command.
Change-Id: I0aa0e8c9491370b5e4fafdaf8cdc5613c26c78f5
Diffstat (limited to 'simpleperf/event_selection_set.cpp')
-rw-r--r--simpleperf/event_selection_set.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/simpleperf/event_selection_set.cpp b/simpleperf/event_selection_set.cpp
index c3a538e8..b7fcd581 100644
--- a/simpleperf/event_selection_set.cpp
+++ b/simpleperf/event_selection_set.cpp
@@ -63,9 +63,22 @@ bool EventSelectionSet::AddEventType(const EventTypeAndModifier& event_type_modi
return false;
}
selections_.push_back(std::move(selection));
+ UnionSampleType();
return true;
}
+// Union the sample type of different event attrs can make reading sample records in perf.data
+// easier.
+void EventSelectionSet::UnionSampleType() {
+ uint64_t sample_type = 0;
+ for (auto& selection : selections_) {
+ sample_type |= selection.event_attr.sample_type;
+ }
+ for (auto& selection : selections_) {
+ selection.event_attr.sample_type = sample_type;
+ }
+}
+
void EventSelectionSet::SetEnableOnExec(bool enable) {
for (auto& selection : selections_) {
selection.event_attr.enable_on_exec = (enable ? 1 : 0);
@@ -291,12 +304,14 @@ EventSelectionSet::EventSelection* EventSelectionSet::FindSelectionByType(
return nullptr;
}
-const perf_event_attr& EventSelectionSet::FindEventAttrByType(
+const perf_event_attr* EventSelectionSet::FindEventAttrByType(
const EventTypeAndModifier& event_type_modifier) {
- return FindSelectionByType(event_type_modifier)->event_attr;
+ EventSelection* selection = FindSelectionByType(event_type_modifier);
+ return (selection != nullptr) ? &selection->event_attr : nullptr;
}
-const std::vector<std::unique_ptr<EventFd>>& EventSelectionSet::FindEventFdsByType(
+const std::vector<std::unique_ptr<EventFd>>* EventSelectionSet::FindEventFdsByType(
const EventTypeAndModifier& event_type_modifier) {
- return FindSelectionByType(event_type_modifier)->event_fds;
+ EventSelection* selection = FindSelectionByType(event_type_modifier);
+ return (selection != nullptr) ? &selection->event_fds : nullptr;
}