From 49bdb3d52dec84a715159c325748e5f15d69b9ce Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Tue, 15 Nov 2016 02:52:22 +0000 Subject: [PATCH] Revert "simpleperf: use libprocinfo." This reverts commit 7eb4f9bd77b82fc54f6396dd62be5655097e028a. Change-Id: I5c7c25d2962678dd1a1ed9146eacd6880044ee45 --- simpleperf/Android.mk | 2 -- simpleperf/environment.cpp | 43 +++++++++++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/simpleperf/Android.mk b/simpleperf/Android.mk index aab702b5..3c402921 100644 --- a/simpleperf/Android.mk +++ b/simpleperf/Android.mk @@ -43,7 +43,6 @@ simpleperf_static_libraries_target := \ libbase \ libcutils \ liblog \ - libprocinfo \ libutils \ liblzma \ libLLVMObject \ @@ -72,7 +71,6 @@ simpleperf_static_libraries_host := \ libprotobuf-cpp-lite \ simpleperf_static_libraries_host_linux := \ - libprocinfo \ libbacktrace_offline \ libbacktrace \ libunwind \ diff --git a/simpleperf/environment.cpp b/simpleperf/environment.cpp index e3fd4ee5..373f3e04 100644 --- a/simpleperf/environment.cpp +++ b/simpleperf/environment.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #if defined(__ANDROID__) #include @@ -219,22 +218,46 @@ void GetKernelAndModuleMmaps(KernelMmap* kernel_mmap, std::vector* m } static bool ReadThreadNameAndPid(pid_t tid, std::string* comm, pid_t* pid) { - android::procinfo::ProcessInfo procinfo; - if (!android::procinfo::GetProcessInfo(tid, &procinfo)) { + std::string status_file = android::base::StringPrintf("/proc/%d/status", tid); + FILE* fp = fopen(status_file.c_str(), "re"); + if (fp == nullptr) { return false; } - if (comm != nullptr) { - *comm = procinfo.name; - } - if (pid != nullptr) { - *pid = procinfo.pid; + bool read_comm = false; + bool read_tgid = false; + LineReader reader(fp); + char* line; + while ((line = reader.ReadLine()) != nullptr) { + char s[reader.MaxLineSize()]; + pid_t tgid; + if (sscanf(line, "Name:%s", s) == 1) { + read_comm = true; + if (comm != nullptr) { + *comm = s; + } + } else if (sscanf(line, "Tgid:%d", &tgid) == 1) { + read_tgid = true; + if (pid != nullptr) { + *pid = tgid; + } + } + if (read_comm && read_tgid) { + return true; + } } - return true; + return false; } std::vector GetThreadsInProcess(pid_t pid) { std::vector result; - android::procinfo::GetProcessTids(pid, &result); + std::string task_dirname = android::base::StringPrintf("/proc/%d/task", pid); + for (const auto& name : GetSubDirs(task_dirname)) { + int tid; + if (!android::base::ParseInt(name.c_str(), &tid, 0)) { + continue; + } + result.push_back(tid); + } return result; } -- 2.11.0