summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2021-03-23 13:34:51 -0700
committerYabin Cui <yabinc@google.com>2021-03-23 15:10:19 -0700
commit58740ffd118bad9e29ce3dbe35e688e3f98cb371 (patch)
tree2dd21698012240b85b7b04464e415c0b3c4864a9
parent2881b21beda06a42c830e41a8019c292488a4880 (diff)
downloadextras-58740ffd118bad9e29ce3dbe35e688e3f98cb371.tar.gz
simpleperf: prepare recording etm data for kernel.
1. Use property to lower kptr_restrict in Android >= 12. 2. Add memory addr of kernel modules in etm recording file. Bug: 183135316 Test: run simpleperf_unit_test Change-Id: Ieeb7eee00bf0278ba0028397896b8bcb79165fa5
-rw-r--r--simpleperf/cmd_record.cpp11
-rw-r--r--simpleperf/cmd_record_test.cpp9
-rw-r--r--simpleperf/environment.cpp14
-rw-r--r--simpleperf/kallsyms.cpp11
-rw-r--r--simpleperf/kallsyms.h6
-rw-r--r--simpleperf/kallsyms_test.cpp16
6 files changed, 49 insertions, 18 deletions
diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp
index 1aec064a..cc87881e 100644
--- a/simpleperf/cmd_record.cpp
+++ b/simpleperf/cmd_record.cpp
@@ -1863,7 +1863,16 @@ bool RecordCommand::DumpBuildIdFeature() {
}
bool RecordCommand::DumpFileFeature() {
- return record_file_writer_->WriteFileFeatures(thread_tree_.GetAllDsos());
+ std::vector<Dso*> dso_v = thread_tree_.GetAllDsos();
+ // To parse ETM data for kernel modules, we need to dump memory address for kernel modules.
+ if (event_selection_set_.HasAuxTrace() && !event_selection_set_.ExcludeKernel()) {
+ for (Dso* dso : dso_v) {
+ if (dso->type() == DSO_KERNEL_MODULE) {
+ dso->CreateDumpId();
+ }
+ }
+ }
+ return record_file_writer_->WriteFileFeatures(dso_v);
}
bool RecordCommand::DumpMetaInfoFeature(bool kernel_symbols_available) {
diff --git a/simpleperf/cmd_record_test.cpp b/simpleperf/cmd_record_test.cpp
index b0e4e553..00b6463f 100644
--- a/simpleperf/cmd_record_test.cpp
+++ b/simpleperf/cmd_record_test.cpp
@@ -924,6 +924,15 @@ TEST(record_cmd, cs_etm_event) {
ASSERT_TRUE(has_aux);
}
+TEST(record_cmd, cs_etm_system_wide) {
+ TEST_REQUIRE_ROOT();
+ if (!ETMRecorder::GetInstance().CheckEtmSupport()) {
+ GTEST_LOG_(INFO) << "Omit this test since etm isn't supported on this device";
+ return;
+ }
+ ASSERT_TRUE(RunRecordCmd({"-e", "cs-etm", "-a"}));
+}
+
TEST(record_cmd, aux_buffer_size_option) {
if (!ETMRecorder::GetInstance().CheckEtmSupport()) {
GTEST_LOG_(INFO) << "Omit this test since etm isn't supported on this device";
diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp
index 98933581..fff0177d 100644
--- a/simpleperf/environment.cpp
+++ b/simpleperf/environment.cpp
@@ -181,11 +181,10 @@ std::vector<pid_t> GetAllProcesses() {
bool GetThreadMmapsInProcess(pid_t pid, std::vector<ThreadMmap>* thread_mmaps) {
thread_mmaps->clear();
- return android::procinfo::ReadProcessMaps(
- pid, [&](const android::procinfo::MapInfo& mapinfo) {
- thread_mmaps->emplace_back(mapinfo.start, mapinfo.end - mapinfo.start, mapinfo.pgoff,
- mapinfo.name.c_str(), mapinfo.flags);
- });
+ return android::procinfo::ReadProcessMaps(pid, [&](const android::procinfo::MapInfo& mapinfo) {
+ thread_mmaps->emplace_back(mapinfo.start, mapinfo.end - mapinfo.start, mapinfo.pgoff,
+ mapinfo.name.c_str(), mapinfo.flags);
+ });
}
bool GetKernelBuildId(BuildId* build_id) {
@@ -841,7 +840,10 @@ int GetAndroidVersion() {
static int android_version = -1;
if (android_version == -1) {
android_version = 0;
- std::string s = android::base::GetProperty("ro.build.version.release", "");
+ std::string s = android::base::GetProperty("ro.build.version.codename", "REL");
+ if (s == "REL") {
+ s = android::base::GetProperty("ro.build.version.release", "");
+ }
// The release string can be a list of numbers (like 8.1.0), a character (like Q)
// or many characters (like OMR1).
if (!s.empty()) {
diff --git a/simpleperf/kallsyms.cpp b/simpleperf/kallsyms.cpp
index ecea9fc4..8fd3d306 100644
--- a/simpleperf/kallsyms.cpp
+++ b/simpleperf/kallsyms.cpp
@@ -65,8 +65,8 @@ bool CanReadKernelSymbolAddresses() {
// This is based on the Perfetto implementation.
class ScopedKptrUnrestrict {
public:
- ScopedKptrUnrestrict(bool use_property = false); // Lowers kptr_restrict if necessary.
- ~ScopedKptrUnrestrict(); // Restores the initial kptr_restrict.
+ ScopedKptrUnrestrict(); // Lowers kptr_restrict if necessary.
+ ~ScopedKptrUnrestrict(); // Restores the initial kptr_restrict.
bool KallsymsAvailable(); // Indicates if access to kallsyms should be successful.
@@ -79,7 +79,8 @@ class ScopedKptrUnrestrict {
bool kallsyms_available_ = false;
};
-ScopedKptrUnrestrict::ScopedKptrUnrestrict(bool use_property) : use_property_(use_property) {
+ScopedKptrUnrestrict::ScopedKptrUnrestrict() {
+ use_property_ = GetAndroidVersion() >= 12;
if (CanReadKernelSymbolAddresses()) {
// Everything seems to work (e.g., we are running as root and kptr_restrict
// is < 2). Don't touching anything.
@@ -214,8 +215,8 @@ uint64_t GetKernelStartAddress() {
return 0;
}
-bool LoadKernelSymbols(std::string* kallsyms, bool use_property /* = false */) {
- ScopedKptrUnrestrict kptr_unrestrict(use_property);
+bool LoadKernelSymbols(std::string* kallsyms) {
+ ScopedKptrUnrestrict kptr_unrestrict;
if (kptr_unrestrict.KallsymsAvailable()) {
return android::base::ReadFileToString(kKallsymsPath, kallsyms);
}
diff --git a/simpleperf/kallsyms.h b/simpleperf/kallsyms.h
index ed097d29..cb1b5a6a 100644
--- a/simpleperf/kallsyms.h
+++ b/simpleperf/kallsyms.h
@@ -47,11 +47,7 @@ uint64_t GetKernelStartAddress();
// Loads the /proc/kallsyms file, requesting access if required. The value of
// kptr_restrict might be modified during the process. Its original value will
// be restored. This usually requires root privileges.
-// In some cases, the process might have enough permission to send a request to
-// init to change the value of kptr_restrict, using the system property
-// security.lower_kptr_restrict. For this scenario, the use_property
-// argument should be set to true.
-bool LoadKernelSymbols(std::string* kallsyms, bool use_property = false);
+bool LoadKernelSymbols(std::string* kallsyms);
#endif // defined(__linux__)
diff --git a/simpleperf/kallsyms_test.cpp b/simpleperf/kallsyms_test.cpp
index 12aefbc4..e97327c6 100644
--- a/simpleperf/kallsyms_test.cpp
+++ b/simpleperf/kallsyms_test.cpp
@@ -18,6 +18,7 @@
#include "get_test_data.h"
#include "kallsyms.h"
+#include "test_util.h"
using namespace simpleperf;
@@ -36,7 +37,7 @@ static bool KernelSymbolsMatch(const KernelSymbol& sym1, const KernelSymbol& sym
ModulesMatch(sym1.module, sym2.module);
}
-TEST(utils, ProcessKernelSymbols) {
+TEST(kallsyms, ProcessKernelSymbols) {
std::string data =
"ffffffffa005c4e4 d __warned.41698 [libsas]\n"
"aaaaaaaaaaaaaaaa T _text\n"
@@ -60,3 +61,16 @@ TEST(utils, ProcessKernelSymbols) {
ASSERT_FALSE(ProcessKernelSymbols(
data, std::bind(&KernelSymbolsMatch, std::placeholders::_1, expected_symbol)));
}
+
+#if defined(__ANDROID__)
+TEST(kallsyms, GetKernelStartAddress) {
+ TEST_REQUIRE_ROOT();
+ ASSERT_NE(GetKernelStartAddress(), 0u);
+}
+
+TEST(kallsyms, LoadKernelSymbols) {
+ TEST_REQUIRE_ROOT();
+ std::string kallsyms;
+ ASSERT_TRUE(LoadKernelSymbols(&kallsyms));
+}
+#endif // defined(__ANDROID__)