summaryrefslogtreecommitdiff
path: root/simpleperf/event_selection_set.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2017-08-03 15:54:43 -0700
committerYabin Cui <yabinc@google.com>2017-08-07 10:26:22 -0700
commit20b49f8991b55eda3309a0bbe3c18153376065da (patch)
treefeb15dfcdd33637db0ccc06c8cea0299e71bc91a /simpleperf/event_selection_set.cpp
parentb3734fda74ff55298be8849a9ef91ee8fef17d0d (diff)
downloadextras-20b49f8991b55eda3309a0bbe3c18153376065da.tar.gz
simpleperf: allow recording events in different speed.
Currently record command interface only allows one sample freq or sample period for all events. This is not convenient when recording both non tracepoint events and tracepoint events. This CL allows setting different sample speed for different events. For example, for "-f 1000 -e cpu-cycles -c 1 sched:sched_switch", "-f 1000" applies to cpu-cycles, and "-c 1" applies to sched:sched_switch. It also fixes a bug about trace-offcpu: if "-f 1000 --trace-offcpu" is used, the sched:sched_switch is be samples with "-f 1000". But we want to sample it with "-c 1". Also change the order of options in the help msg of record cmd to make it more readable. Remove -F option. Because adding it seems not useful. Bug: http://b/37572306 Test: run simpleperf_unit_test. Change-Id: Ifdbd27c8f9fec49aade0e0e6ce624d8114042020
Diffstat (limited to 'simpleperf/event_selection_set.cpp')
-rw-r--r--simpleperf/event_selection_set.cpp53
1 files changed, 21 insertions, 32 deletions
diff --git a/simpleperf/event_selection_set.cpp b/simpleperf/event_selection_set.cpp
index de04d3d1..e16a27d3 100644
--- a/simpleperf/event_selection_set.cpp
+++ b/simpleperf/event_selection_set.cpp
@@ -128,6 +128,14 @@ bool EventSelectionSet::BuildAndCheckEventSelection(
selection->event_attr.exclude_host = event_type->exclude_host;
selection->event_attr.exclude_guest = event_type->exclude_guest;
selection->event_attr.precise_ip = event_type->precise_ip;
+ if (event_type->event_type.type == PERF_TYPE_TRACEPOINT) {
+ selection->event_attr.freq = 0;
+ selection->event_attr.sample_period = DEFAULT_SAMPLE_PERIOD_FOR_TRACEPOINT_EVENT;
+ } else {
+ selection->event_attr.freq = 1;
+ selection->event_attr.sample_freq =
+ AdjustSampleFrequency(DEFAULT_SAMPLE_FREQ_FOR_NONTRACEPOINT_EVENT);
+ }
if (!IsEventAttrSupported(selection->event_attr)) {
LOG(ERROR) << "Event type '" << event_type->name
<< "' is not supported on the device";
@@ -147,12 +155,12 @@ bool EventSelectionSet::BuildAndCheckEventSelection(
return true;
}
-bool EventSelectionSet::AddEventType(const std::string& event_name) {
- return AddEventGroup(std::vector<std::string>(1, event_name));
+bool EventSelectionSet::AddEventType(const std::string& event_name, size_t* group_id) {
+ return AddEventGroup(std::vector<std::string>(1, event_name), group_id);
}
bool EventSelectionSet::AddEventGroup(
- const std::vector<std::string>& event_names) {
+ const std::vector<std::string>& event_names, size_t* group_id) {
EventSelectionGroup group;
for (const auto& event_name : event_names) {
EventSelection selection;
@@ -163,6 +171,9 @@ bool EventSelectionSet::AddEventGroup(
}
groups_.push_back(std::move(group));
UnionSampleType();
+ if (group_id != nullptr) {
+ *group_id = groups_.size() - 1;
+ }
return true;
}
@@ -284,37 +295,15 @@ void EventSelectionSet::SampleIdAll() {
}
}
-void EventSelectionSet::SetSampleFreq(uint64_t sample_freq) {
- for (auto& group : groups_) {
- for (auto& selection : group) {
+void EventSelectionSet::SetSampleSpeed(size_t group_id, const SampleSpeed& speed) {
+ CHECK_LT(group_id, groups_.size());
+ for (auto& selection : groups_[group_id]) {
+ if (speed.UseFreq()) {
selection.event_attr.freq = 1;
- selection.event_attr.sample_freq = sample_freq;
- }
- }
-}
-
-void EventSelectionSet::SetSamplePeriod(uint64_t sample_period) {
- for (auto& group : groups_) {
- for (auto& selection : group) {
+ selection.event_attr.sample_freq = speed.sample_freq;
+ } else {
selection.event_attr.freq = 0;
- selection.event_attr.sample_period = sample_period;
- }
- }
-}
-
-void EventSelectionSet::UseDefaultSampleFreq() {
- for (auto& group : groups_) {
- for (auto& selection : group) {
- if (selection.event_type_modifier.event_type.type ==
- PERF_TYPE_TRACEPOINT) {
- selection.event_attr.freq = 0;
- selection.event_attr.sample_period =
- DEFAULT_SAMPLE_PERIOD_FOR_TRACEPOINT_EVENT;
- } else {
- selection.event_attr.freq = 1;
- selection.event_attr.sample_freq =
- DEFAULT_SAMPLE_FREQ_FOR_NONTRACEPOINT_EVENT;
- }
+ selection.event_attr.sample_period = speed.sample_period;
}
}
}