From c98cb1193d73c1fa616d0d366a221751fde38f67 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Mon, 6 Apr 2020 16:26:41 -0700 Subject: 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 --- simpleperf/environment.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'simpleperf/environment.cpp') 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) { -- cgit v1.2.3