OSDN Git Service

Revert "simpleperf: use libprocinfo."
authorJosh Gao <jmgao@google.com>
Tue, 15 Nov 2016 02:52:22 +0000 (02:52 +0000)
committerJosh Gao <jmgao@google.com>
Tue, 15 Nov 2016 02:52:22 +0000 (02:52 +0000)
This reverts commit 7eb4f9bd77b82fc54f6396dd62be5655097e028a.

Change-Id: I5c7c25d2962678dd1a1ed9146eacd6880044ee45

simpleperf/Android.mk
simpleperf/environment.cpp

index aab702b..3c40292 100644 (file)
@@ -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 \
index e3fd4ee..373f3e0 100644 (file)
@@ -31,7 +31,6 @@
 #include <android-base/parseint.h>
 #include <android-base/strings.h>
 #include <android-base/stringprintf.h>
-#include <procinfo/process.h>
 
 #if defined(__ANDROID__)
 #include <sys/system_properties.h>
@@ -219,22 +218,46 @@ void GetKernelAndModuleMmaps(KernelMmap* kernel_mmap, std::vector<KernelMmap>* 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<pid_t> GetThreadsInProcess(pid_t pid) {
   std::vector<pid_t> 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;
 }