From 20b49f8991b55eda3309a0bbe3c18153376065da Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Thu, 3 Aug 2017 15:54:43 -0700 Subject: 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 --- simpleperf/event_selection_set.cpp | 53 +++++++++++++++----------------------- 1 file changed, 21 insertions(+), 32 deletions(-) (limited to 'simpleperf/event_selection_set.cpp') 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(1, event_name)); +bool EventSelectionSet::AddEventType(const std::string& event_name, size_t* group_id) { + return AddEventGroup(std::vector(1, event_name), group_id); } bool EventSelectionSet::AddEventGroup( - const std::vector& event_names) { + const std::vector& 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; } } } -- cgit v1.2.3