summaryrefslogtreecommitdiffstats
path: root/libbacktrace
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2018-05-10 17:19:12 -0700
committerYabin Cui <yabinc@google.com>2018-05-14 14:00:18 -0700
commit3841accba82b47087647d023e670219ac3627710 (patch)
tree2e5d901771563dded16721f694530b3ddc53e8ed /libbacktrace
parent3607fe672a1aa0fa775df01b60d18d287e7f8686 (diff)
downloadsystem_core-3841accba82b47087647d023e670219ac3627710.tar.gz
system_core-3841accba82b47087647d023e670219ac3627710.tar.bz2
system_core-3841accba82b47087647d023e670219ac3627710.zip
libprocinfo: add functions reading process map file.
Add test and benchmark. Also switch libbacktrace, libunwindstack, libmemunreachable to use libprocinfo for map file reading. The benchmark shows using libprocinfo speeds up map file reading in libbacktrace and libunwindstack 18% - 36% on walleye. Bug: http://b/79118393 Test: run procinfo_test. Test: run libunwindstack_test. Test: run libbacktrace_test. Test: run memunreachable_test. Change-Id: Icf281c352f4103fc8d4ba6732c5c07b943330ca1
Diffstat (limited to 'libbacktrace')
-rw-r--r--libbacktrace/Android.bp5
-rw-r--r--libbacktrace/BacktraceMap.cpp40
-rw-r--r--libbacktrace/include/backtrace/BacktraceMap.h2
3 files changed, 20 insertions, 27 deletions
diff --git a/libbacktrace/Android.bp b/libbacktrace/Android.bp
index 11b8144be..4987ba131 100644
--- a/libbacktrace/Android.bp
+++ b/libbacktrace/Android.bp
@@ -91,7 +91,10 @@ cc_library {
"libdexfile",
],
- static_libs: ["libcutils"],
+ static_libs: [
+ "libcutils",
+ "libprocinfo",
+ ],
// libdexfile will eventually properly export headers, for now
// include these directly.
diff --git a/libbacktrace/BacktraceMap.cpp b/libbacktrace/BacktraceMap.cpp
index bdae14062..399721dc1 100644
--- a/libbacktrace/BacktraceMap.cpp
+++ b/libbacktrace/BacktraceMap.cpp
@@ -28,6 +28,9 @@
#include <backtrace/Backtrace.h>
#include <backtrace/BacktraceMap.h>
#include <backtrace/backtrace_constants.h>
+#if defined(__linux__)
+#include <procinfo/process_map.h>
+#endif
#include "thread_utils.h"
@@ -60,27 +63,19 @@ void BacktraceMap::FillIn(uint64_t addr, backtrace_map_t* map) {
*map = {};
}
-bool BacktraceMap::ParseLine(const char* line, backtrace_map_t* map) {
+#if defined(__APPLE__)
+static bool ParseLine(const char* line, backtrace_map_t* map) {
uint64_t start;
uint64_t end;
char permissions[5];
int name_pos;
-#if defined(__APPLE__)
// Mac OS vmmap(1) output:
// __TEXT 0009f000-000a1000 [ 8K 8K] r-x/rwx SM=COW /Volumes/android/dalvik-dev/out/host/darwin-x86/bin/libcorkscrew_test\n
// 012345678901234567890123456789012345678901234567890123456789
// 0 1 2 3 4 5
if (sscanf(line, "%*21c %" SCNx64 "-%" SCNx64 " [%*13c] %3c/%*3c SM=%*3c %n",
&start, &end, permissions, &name_pos) != 3) {
-#else
-// Linux /proc/<pid>/maps lines:
-// 6f000000-6f01e000 rwxp 00000000 00:0c 16389419 /system/lib/libcomposer.so\n
-// 012345678901234567890123456789012345678901234567890123456789
-// 0 1 2 3 4 5
- if (sscanf(line, "%" SCNx64 "-%" SCNx64 " %4s %*x %*x:%*x %*d %n",
- &start, &end, permissions, &name_pos) != 3) {
-#endif
return false;
}
@@ -107,24 +102,15 @@ bool BacktraceMap::ParseLine(const char* line, backtrace_map_t* map) {
map->flags, map->name.c_str());
return true;
}
+#endif // defined(__APPLE__)
bool BacktraceMap::Build() {
#if defined(__APPLE__)
char cmd[sizeof(pid_t)*3 + sizeof("vmmap -w -resident -submap -allSplitLibs -interleaved ") + 1];
-#else
- char path[sizeof(pid_t)*3 + sizeof("/proc//maps") + 1];
-#endif
char line[1024];
-
-#if defined(__APPLE__)
// cmd is guaranteed to always be big enough to hold this string.
snprintf(cmd, sizeof(cmd), "vmmap -w -resident -submap -allSplitLibs -interleaved %d", pid_);
FILE* fp = popen(cmd, "r");
-#else
- // path is guaranteed to always be big enough to hold this string.
- snprintf(path, sizeof(path), "/proc/%d/maps", pid_);
- FILE* fp = fopen(path, "r");
-#endif
if (fp == nullptr) {
return false;
}
@@ -135,13 +121,19 @@ bool BacktraceMap::Build() {
maps_.push_back(map);
}
}
-#if defined(__APPLE__)
pclose(fp);
+ return true;
#else
- fclose(fp);
+ return android::procinfo::ReadProcessMaps(
+ pid_, [&](uint64_t start, uint64_t end, uint16_t flags, uint64_t, const char* name) {
+ maps_.resize(maps_.size() + 1);
+ backtrace_map_t& map = maps_.back();
+ map.start = start;
+ map.end = end;
+ map.flags = flags;
+ map.name = name;
+ });
#endif
-
- return true;
}
#if defined(__APPLE__)
diff --git a/libbacktrace/include/backtrace/BacktraceMap.h b/libbacktrace/include/backtrace/BacktraceMap.h
index c94cad188..a9cfce4cb 100644
--- a/libbacktrace/include/backtrace/BacktraceMap.h
+++ b/libbacktrace/include/backtrace/BacktraceMap.h
@@ -169,8 +169,6 @@ public:
virtual uint64_t GetLoadBias(size_t /* index */) { return 0; }
- virtual bool ParseLine(const char* line, backtrace_map_t* map);
-
pid_t pid_;
std::deque<backtrace_map_t> maps_;
std::vector<std::string> suffixes_to_ignore_;