diff options
author | Yabin Cui <yabinc@google.com> | 2020-04-06 16:26:41 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2020-04-06 16:31:10 -0700 |
commit | c98cb1193d73c1fa616d0d366a221751fde38f67 (patch) | |
tree | da314bf4ccb9a63cda092562a10e7b172fa9d835 /simpleperf/environment.cpp | |
parent | 4d1a421368e14e976de90ea0c40fb70c08d514a8 (diff) | |
download | extras-c98cb1193d73c1fa616d0d366a221751fde38f67.tar.gz |
simpleperf: fix CanRecordRawData.
sys.init.perf_lsm_hooks isn't accessible in app context, thus
checking it in CanRecordRawData() breaks recording app with
--trace-offcpu option.
Fix it by not recording raw data in non-root users.
Bug: 153381808
Test: run simpleperf_unit_test.
Test: run test.py *TraceOffCpu*.
Change-Id: Id87c73d25b19b265c022c4fa6ebb8e7d3a84152b
Diffstat (limited to 'simpleperf/environment.cpp')
-rw-r--r-- | simpleperf/environment.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp index e16e496f..5b2fcaa8 100644 --- a/simpleperf/environment.cpp +++ b/simpleperf/environment.cpp @@ -299,18 +299,15 @@ bool CanRecordRawData() { if (IsRoot()) { return true; } - int value; - if (!ReadPerfEventParanoid(&value) || value > -1) { - return false; - } #if defined(__ANDROID__) - // If perf_event_open() is controlled by selinux, simpleperf can't record tracepoint raw data - // unless running as root. - if (android::base::GetProperty("sys.init.perf_lsm_hooks", "") == "1") { - return false; - } + // Android R uses selinux to control perf_event_open. Whether raw data can be recorded is hard + // to check unless we really try it. And probably there is no need to record raw data in non-root + // users. + return false; +#else + int value; + return ReadPerfEventParanoid(&value) && value == -1; #endif - return true; } static const char* GetLimitLevelDescription(int limit_level) { |