OSDN Git Service

Simpleperf: don't use ioctl(PERF_EVENT_IOC_ENABLE).
[android-x86/system-extras.git] / simpleperf / event_selection_set.cpp
index 1a9de63..74776dd 100644 (file)
@@ -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_) {