diff options
author | Yabin Cui <yabinc@google.com> | 2015-12-05 00:15:38 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-12-05 00:15:38 +0000 |
commit | b9ca50b319d2083c5a92c468e54796b0e71a4ad9 (patch) | |
tree | d669a9e0da05254aab47edf54a529d36c3f46903 | |
parent | 5d8fdbb6ff3d617e48198e12a2b1c10b48d22f79 (diff) | |
parent | a46794fa2963de93a9d25fd6945d3c58121e2ba6 (diff) | |
download | extras-b9ca50b319d2083c5a92c468e54796b0e71a4ad9.tar.gz |
Merge "Simpleperf: don't use ioctl(PERF_EVENT_IOC_ENABLE)."
-rw-r--r-- | simpleperf/cmd_record.cpp | 5 | ||||
-rw-r--r-- | simpleperf/cmd_stat.cpp | 5 | ||||
-rw-r--r-- | simpleperf/event_attr.cpp | 2 | ||||
-rw-r--r-- | simpleperf/event_fd.cpp | 18 | ||||
-rw-r--r-- | simpleperf/event_fd.h | 6 | ||||
-rw-r--r-- | simpleperf/event_selection_set.cpp | 23 | ||||
-rw-r--r-- | simpleperf/event_selection_set.h | 1 |
7 files changed, 12 insertions, 48 deletions
diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp index 5ca04144..54310419 100644 --- a/simpleperf/cmd_record.cpp +++ b/simpleperf/cmd_record.cpp @@ -231,11 +231,6 @@ bool RecordCommand::Run(const std::vector<std::string>& args) { } // 5. Write records in mmap buffers of perf_event_files to output file while workload is running. - if (!event_selection_set_.GetEnableOnExec()) { - if (!event_selection_set_.EnableEvents()) { - return false; - } - } if (workload != nullptr && !workload->Start()) { return false; } diff --git a/simpleperf/cmd_stat.cpp b/simpleperf/cmd_stat.cpp index fbc0caa8..e25cf5ae 100644 --- a/simpleperf/cmd_stat.cpp +++ b/simpleperf/cmd_stat.cpp @@ -145,11 +145,6 @@ bool StatCommand::Run(const std::vector<std::string>& args) { // 4. Count events while workload running. auto start_time = std::chrono::steady_clock::now(); - if (!event_selection_set_.GetEnableOnExec()) { - if (!event_selection_set_.EnableEvents()) { - return false; - } - } if (workload != nullptr && !workload->Start()) { return false; } diff --git a/simpleperf/event_attr.cpp b/simpleperf/event_attr.cpp index 6ac74941..c9449b14 100644 --- a/simpleperf/event_attr.cpp +++ b/simpleperf/event_attr.cpp @@ -82,7 +82,7 @@ perf_event_attr CreateDefaultPerfEventAttr(const EventType& event_type) { attr.config = event_type.config; attr.mmap = 1; attr.comm = 1; - attr.disabled = 1; + attr.disabled = 0; // Changing read_format affects the layout of the data read from perf_event_file, namely // PerfCounter in event_fd.h. attr.read_format = diff --git a/simpleperf/event_fd.cpp b/simpleperf/event_fd.cpp index 205fa965..ec06f6fd 100644 --- a/simpleperf/event_fd.cpp +++ b/simpleperf/event_fd.cpp @@ -95,24 +95,6 @@ uint64_t EventFd::Id() const { return id_; } -bool EventFd::EnableEvent() { - int result = ioctl(perf_event_fd_, PERF_EVENT_IOC_ENABLE, 0); - if (result < 0) { - PLOG(ERROR) << "ioctl(enable) " << Name() << " failed"; - return false; - } - return true; -} - -bool EventFd::DisableEvent() { - int result = ioctl(perf_event_fd_, PERF_EVENT_IOC_DISABLE, 0); - if (result < 0) { - PLOG(ERROR) << "ioctl(disable) " << Name() << " failed"; - return false; - } - return true; -} - bool EventFd::ReadCounter(PerfCounter* counter) const { CHECK(counter != nullptr); if (!android::base::ReadFully(perf_event_fd_, counter, sizeof(*counter))) { diff --git a/simpleperf/event_fd.h b/simpleperf/event_fd.h index c54af97e..cc0c0618 100644 --- a/simpleperf/event_fd.h +++ b/simpleperf/event_fd.h @@ -53,12 +53,6 @@ class EventFd { return cpu_; } - // It tells the kernel to start counting and recording events specified by this file. - bool EnableEvent(); - - // It tells the kernel to stop counting and recording events specified by this file. - bool DisableEvent(); - bool ReadCounter(PerfCounter* counter) const; // Call mmap() for this perf_event_file, so we can read sampled records from mapped area. diff --git a/simpleperf/event_selection_set.cpp b/simpleperf/event_selection_set.cpp index 02a16778..038e577e 100644 --- a/simpleperf/event_selection_set.cpp +++ b/simpleperf/event_selection_set.cpp @@ -81,7 +81,17 @@ void EventSelectionSet::UnionSampleType() { void EventSelectionSet::SetEnableOnExec(bool enable) { for (auto& selection : selections_) { - selection.event_attr.enable_on_exec = (enable ? 1 : 0); + // If sampling is enabled on exec, then it is disabled at startup, otherwise + // it should be enabled at startup. Don't use ioctl(PERF_EVENT_IOC_ENABLE) + // to enable it after perf_event_open(). Because some android kernels can't + // handle ioctl() well when cpu-hotplug happens. See http://b/25193162. + if (enable) { + selection.event_attr.enable_on_exec = 1; + selection.event_attr.disabled = 1; + } else { + selection.event_attr.enable_on_exec = 0; + selection.event_attr.disabled = 0; + } } } @@ -218,17 +228,6 @@ bool EventSelectionSet::OpenEventFiles(const std::vector<pid_t>& threads, return true; } -bool EventSelectionSet::EnableEvents() { - for (auto& selection : selections_) { - for (auto& event_fd : selection.event_fds) { - if (!event_fd->EnableEvent()) { - return false; - } - } - } - return true; -} - bool EventSelectionSet::ReadCounters(std::vector<CountersInfo>* counters) { counters->clear(); for (auto& selection : selections_) { diff --git a/simpleperf/event_selection_set.h b/simpleperf/event_selection_set.h index 705bc35f..cba9dc62 100644 --- a/simpleperf/event_selection_set.h +++ b/simpleperf/event_selection_set.h @@ -70,7 +70,6 @@ class EventSelectionSet { bool OpenEventFilesForCpus(const std::vector<int>& cpus); bool OpenEventFilesForThreadsOnCpus(const std::vector<pid_t>& threads, std::vector<int> cpus); - bool EnableEvents(); bool ReadCounters(std::vector<CountersInfo>* counters); void PreparePollForEventFiles(std::vector<pollfd>* pollfds); bool MmapEventFiles(size_t mmap_pages); |