summaryrefslogtreecommitdiff
path: root/simpleperf/cmd_record.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2015-06-15 13:57:23 -0700
committerYabin Cui <yabinc@google.com>2015-06-19 11:09:21 -0700
commitd115b2f738f2cef352877b26c2d93460ac9fea25 (patch)
treee1ec58f463c6acc0a451e58caef23568fc1a1f02 /simpleperf/cmd_record.cpp
parent60ed78f3cb49e873d0a9aa40d5db33818d0259c2 (diff)
downloadextras-d115b2f738f2cef352877b26c2d93460ac9fea25.tar.gz
Simpleperf: support event type modifier.
Also fix a bug in event_attr dumping. Bug: 19483574 Change-Id: I255647d1471acab3a63c3dc787ab06b3d2bee294
Diffstat (limited to 'simpleperf/cmd_record.cpp')
-rw-r--r--simpleperf/cmd_record.cpp32
1 files changed, 19 insertions, 13 deletions
diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp
index e87a7ec1..b59dcdc2 100644
--- a/simpleperf/cmd_record.cpp
+++ b/simpleperf/cmd_record.cpp
@@ -61,8 +61,12 @@ class RecordCommand : public Command {
" -a System-wide collection.\n"
" -b Enable take branch stack sampling. Same as '-j any'\n"
" -c count Set event sample period.\n"
- " -e event Select the event to sample (Use `simpleperf list`)\n"
- " to find all possible event names.\n"
+ " -e event[:modifier]\n"
+ " Select the event to sample. Use `simpleperf list` to find\n"
+ " all possible event names. Modifiers can be added to define\n"
+ " how the event should be monitored. Possible modifiers are:\n"
+ " u - monitor user space events only\n"
+ " k - monitor kernel space events only\n"
" -f freq Set event sample frequency.\n"
" -F freq Same as '-f freq'.\n"
" -g Enables call-graph recording.\n"
@@ -88,7 +92,6 @@ class RecordCommand : public Command {
system_wide_collection_(false),
branch_sampling_(0),
callchain_sampling_(false),
- measured_event_type_(nullptr),
perf_mmap_pages_(256),
record_filename_("perf.data") {
signaled = false;
@@ -117,8 +120,8 @@ class RecordCommand : public Command {
bool system_wide_collection_;
std::vector<pid_t> monitored_threads_;
uint64_t branch_sampling_;
+ std::unique_ptr<EventTypeAndModifier> measured_event_type_modifier_;
bool callchain_sampling_;
- const EventType* measured_event_type_;
EventSelectionSet event_selection_set_;
// mmap pages used by each perf event file, should be power of 2.
@@ -136,7 +139,7 @@ bool RecordCommand::Run(const std::vector<std::string>& args) {
if (!ParseOptions(args, &workload_args)) {
return false;
}
- if (measured_event_type_ == nullptr) {
+ if (measured_event_type_modifier_ == nullptr) {
if (!SetMeasuredEventType(default_measured_event_type)) {
return false;
}
@@ -182,8 +185,9 @@ bool RecordCommand::Run(const std::vector<std::string>& args) {
// 4. Open record file writer, and dump kernel/modules/threads mmap information.
record_file_writer_ = RecordFileWriter::CreateInstance(
- record_filename_, event_selection_set_.FindEventAttrByType(*measured_event_type_),
- event_selection_set_.FindEventFdsByType(*measured_event_type_));
+ record_filename_,
+ event_selection_set_.FindEventAttrByType(measured_event_type_modifier_->event_type),
+ event_selection_set_.FindEventFdsByType(measured_event_type_modifier_->event_type));
if (record_file_writer_ == nullptr) {
return false;
}
@@ -320,16 +324,16 @@ bool RecordCommand::ParseOptions(const std::vector<std::string>& args,
}
bool RecordCommand::SetMeasuredEventType(const std::string& event_type_name) {
- const EventType* event_type = EventTypeFactory::FindEventTypeByName(event_type_name);
- if (event_type == nullptr) {
+ std::unique_ptr<EventTypeAndModifier> event_type_modifier = ParseEventType(event_type_name);
+ if (event_type_modifier == nullptr) {
return false;
}
- measured_event_type_ = event_type;
+ measured_event_type_modifier_ = std::move(event_type_modifier);
return true;
}
bool RecordCommand::SetEventSelection() {
- event_selection_set_.AddEventType(*measured_event_type_);
+ event_selection_set_.AddEventType(*measured_event_type_modifier_);
if (use_sample_freq_) {
event_selection_set_.SetSampleFreq(sample_freq_);
} else {
@@ -355,7 +359,8 @@ bool RecordCommand::DumpKernelAndModuleMmaps() {
if (!GetKernelAndModuleMmaps(&kernel_mmap, &module_mmaps)) {
return false;
}
- const perf_event_attr& attr = event_selection_set_.FindEventAttrByType(*measured_event_type_);
+ const perf_event_attr& attr =
+ event_selection_set_.FindEventAttrByType(measured_event_type_modifier_->event_type);
MmapRecord mmap_record = CreateMmapRecord(attr, true, UINT_MAX, 0, kernel_mmap.start_addr,
kernel_mmap.len, kernel_mmap.pgoff, kernel_mmap.name);
if (!record_file_writer_->WriteData(mmap_record.BinaryFormat())) {
@@ -380,7 +385,8 @@ bool RecordCommand::DumpThreadCommAndMmaps() {
if (!GetThreadComms(&thread_comms)) {
return false;
}
- const perf_event_attr& attr = event_selection_set_.FindEventAttrByType(*measured_event_type_);
+ const perf_event_attr& attr =
+ event_selection_set_.FindEventAttrByType(measured_event_type_modifier_->event_type);
for (auto& thread : thread_comms) {
CommRecord record = CreateCommRecord(attr, thread.tgid, thread.tid, thread.comm);
if (!record_file_writer_->WriteData(record.BinaryFormat())) {