diff options
author | Yabin Cui <yabinc@google.com> | 2018-08-29 14:54:19 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2018-08-30 17:07:41 +0000 |
commit | 5edb7fc23c43620c095d1ec54e76818c163d688d (patch) | |
tree | 466c03ad972eb3691a7ce42fd8bcd0edff9a79e8 | |
parent | f11db565adf794d73f6874a084cbd4ffa14aadd0 (diff) | |
download | extras-5edb7fc23c43620c095d1ec54e76818c163d688d.tar.gz |
perfprofd: add env to disable change of perf_event_paranoid.
This is to avoid a cts test failure (which checks the value of
perf_event_paranoid) while perfprofd is running.
Bug: 111855759
Test: run perfprofd_test and perf_event_paranoid isn't changed.
Change-Id: Ifa610a21b560d0eb536cb76914b116bd1e769634
-rw-r--r-- | perfprofd/perfprofd_perf.cc | 8 | ||||
-rw-r--r-- | simpleperf/environment.cpp | 10 |
2 files changed, 13 insertions, 5 deletions
diff --git a/perfprofd/perfprofd_perf.cc b/perfprofd/perfprofd_perf.cc index 6ca1ef30..15dde6fb 100644 --- a/perfprofd/perfprofd_perf.cc +++ b/perfprofd/perfprofd_perf.cc @@ -63,6 +63,8 @@ PerfResult InvokePerf(Config& config, { std::vector<std::string> argv_backing; std::vector<const char*> argv_vector; + char paranoid_env[] = "PERFPROFD_DISABLE_PERF_EVENT_PARANOID_CHANGE=1"; + char* envp[2] = {paranoid_env, nullptr}; { auto add = [&argv_backing](auto arg) { @@ -184,7 +186,7 @@ PerfResult InvokePerf(Config& config, fprintf(stderr, "\n"); // exec - execvp(argv_vector[0], const_cast<char* const*>(argv_vector.data())); + execvpe(argv_vector[0], const_cast<char* const*>(argv_vector.data()), envp); fprintf(stderr, "exec failed: %s\n", strerror(errno)); exit(1); @@ -235,6 +237,8 @@ PerfResult InvokePerf(Config& config, bool FindSupportedPerfCounters(const std::string& perf_path) { const char* argv[] = { perf_path.c_str(), "list", nullptr }; + char paranoid_env[] = "PERFPROFD_DISABLE_PERF_EVENT_PARANOID_CHANGE=1"; + char* envp[2] = {paranoid_env, nullptr}; base::unique_fd link[2]; { @@ -266,7 +270,7 @@ bool FindSupportedPerfCounters(const std::string& perf_path) { link[1].reset(); // exec - execvp(argv[0], const_cast<char* const*>(argv)); + execvpe(argv[0], const_cast<char* const*>(argv), envp); PLOG(WARNING) << "exec failed"; exit(1); __builtin_unreachable(); diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp index f223bfcd..eed4ee42 100644 --- a/simpleperf/environment.cpp +++ b/simpleperf/environment.cpp @@ -321,7 +321,7 @@ static bool ReadPerfEventParanoid(int* value) { bool CanRecordRawData() { int value; - return IsRoot() || (ReadPerfEventParanoid(&value) && value == -1); + return ReadPerfEventParanoid(&value) && value == -1; } static const char* GetLimitLevelDescription(int limit_level) { @@ -340,8 +340,12 @@ bool CheckPerfEventLimit() { // 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; + if (IsRoot()) { + char* env = getenv("PERFPROFD_DISABLE_PERF_EVENT_PARANOID_CHANGE"); + if (env != nullptr && strcmp(env, "1") == 0) { + return true; + } + return android::base::WriteStringToFile("-1", "/proc/sys/kernel/perf_event_paranoid"); } int limit_level; bool can_read_paranoid = ReadPerfEventParanoid(&limit_level); |