summaryrefslogtreecommitdiff
path: root/simpleperf/event_selection_set.h
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.h
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.h')
-rw-r--r--simpleperf/event_selection_set.h22
1 files changed, 17 insertions, 5 deletions
diff --git a/simpleperf/event_selection_set.h b/simpleperf/event_selection_set.h
index 3a3bd460..cc972bea 100644
--- a/simpleperf/event_selection_set.h
+++ b/simpleperf/event_selection_set.h
@@ -49,6 +49,20 @@ struct CountersInfo {
std::vector<CounterInfo> counters;
};
+struct SampleSpeed {
+ // There are two ways to set sample speed:
+ // 1. sample_freq: take [sample_freq] samples every second.
+ // 2. sample_period: take one sample every [sample_period] events happen.
+ uint64_t sample_freq;
+ uint64_t sample_period;
+ SampleSpeed(uint64_t freq = 0, uint64_t period = 0) : sample_freq(freq), sample_period(period) {}
+ bool UseFreq() const {
+ // Only use one way to set sample speed.
+ CHECK_NE(sample_freq != 0u, sample_period != 0u);
+ return sample_freq != 0u;
+ }
+};
+
// EventSelectionSet helps to monitor events. It is used in following steps:
// 1. Create an EventSelectionSet, and add event types to monitor by calling
// AddEventType() or AddEventGroup().
@@ -71,8 +85,8 @@ class EventSelectionSet {
bool empty() const { return groups_.empty(); }
- bool AddEventType(const std::string& event_name);
- bool AddEventGroup(const std::vector<std::string>& event_names);
+ bool AddEventType(const std::string& event_name, size_t* group_id = nullptr);
+ bool AddEventGroup(const std::vector<std::string>& event_names, size_t* group_id = nullptr);
std::vector<const EventType*> GetEvents() const;
std::vector<const EventType*> GetTracepointEvents() const;
bool ExcludeKernel() const;
@@ -82,9 +96,7 @@ class EventSelectionSet {
void SetEnableOnExec(bool enable);
bool GetEnableOnExec();
void SampleIdAll();
- void SetSampleFreq(uint64_t sample_freq);
- void SetSamplePeriod(uint64_t sample_period);
- void UseDefaultSampleFreq();
+ void SetSampleSpeed(size_t group_id, const SampleSpeed& speed);
bool SetBranchSampling(uint64_t branch_sample_type);
void EnableFpCallChainSampling();
bool EnableDwarfCallChainSampling(uint32_t dump_stack_size);