OSDN Git Service

simpleperf: write -1 to perf_event_paranoid when running as root.
authorYabin Cui <yabinc@google.com>
Thu, 1 Jun 2017 20:23:29 +0000 (13:23 -0700)
committerYabin Cui <yabinc@google.com>
Thu, 1 Jun 2017 21:21:31 +0000 (14:21 -0700)
The monitored threads may create child processes not running as root.
This patch is to make sure they have permission to create inherited
tracepoint events.

Bug: http://b/62230699
Test: run simpleperf manually on device.
Change-Id: I02798c834f8a0500057e4e1c70291cfb05c3f92d

simpleperf/environment.cpp

index d0cb835..7fff85f 100644 (file)
@@ -361,8 +361,11 @@ static const char* GetLimitLevelDescription(int limit_level) {
 }
 
 bool CheckPerfEventLimit() {
-  // root is not limited by /proc/sys/kernel/perf_event_paranoid.
-  if (IsRoot()) {
+  // Root is not limited by /proc/sys/kernel/perf_event_paranoid. However, the monitored threads
+  // may create child processes not running as root. To make sure the child processes have
+  // enough permission to create inherited tracepoint events, write -1 to perf_event_paranoid.
+  // See http://b/62230699.
+  if (IsRoot() && android::base::WriteStringToFile("-1", "/proc/sys/kernel/perf_event_paranoid")) {
     return true;
   }
   int limit_level;