summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2020-04-06 16:26:41 -0700
committerYabin Cui <yabinc@google.com>2020-04-06 23:46:23 -0700
commitbcf045413b6760d6a31a8fdfb85b22b7854d12df (patch)
tree6b6c42e543d0d9a33efdb555a234a7dd1425e4d9
parentc118258b5f24ae4ce3fbff947ef26b1c80d3a3df (diff)
downloadextras-bcf045413b6760d6a31a8fdfb85b22b7854d12df.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 (cherry picked from commit c98cb1193d73c1fa616d0d366a221751fde38f67)
-rw-r--r--simpleperf/environment.cpp17
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) {