================
@@ -479,246 +481,131 @@ std::string PlatformAndroid::GetRunAs() {
return run_as.str();
}
-// Helper function to populate process status information from
-// /proc/[pid]/status
-void PlatformAndroid::PopulateProcessStatusInfo(
- lldb::pid_t pid, ProcessInstanceInfo &process_info) {
- // Read /proc/[pid]/status to get parent PID, UIDs, and GIDs
- Status error;
- AdbClientUP status_adb = GetAdbClient(error);
- if (error.Fail())
- return;
-
- std::string status_output;
- StreamString status_cmd;
- status_cmd.Printf(
- "cat /proc/%llu/status 2>/dev/null | grep -E '^(PPid|Uid|Gid):'",
- static_cast<unsigned long long>(pid));
- Status status_error =
- status_adb->Shell(status_cmd.GetData(), seconds(5), &status_output);
+static bool NeedsCmdlineSupplement(const ProcessInstanceInfo &proc_info) {
+ llvm::StringRef name =
+ proc_info.GetExecutableFile().GetFilename().GetStringRef();
+ return name.contains("app_process") || name.contains("zygote");
+}
- if (status_error.Fail() || status_output.empty())
+// Fetch /proc/PID/cmdline for processes to get actual package names.
+// Android apps often show as "zygote" or "app_process" without this.
+static void SupplementWithCmdlineInfo(ProcessInstanceInfoList &proc_infos,
+ AdbClient *adb, Log *log) {
+ if (proc_infos.empty())
return;
- llvm::SmallVector<llvm::StringRef, 16> lines;
- llvm::StringRef(status_output).split(lines, '\n');
-
- for (llvm::StringRef line : lines) {
- line = line.trim();
- if (line.starts_with("PPid:")) {
- llvm::StringRef ppid_str = line.substr(5).trim();
- lldb::pid_t ppid;
- if (llvm::to_integer(ppid_str, ppid))
- process_info.SetParentProcessID(ppid);
- } else if (line.starts_with("Uid:")) {
- llvm::SmallVector<llvm::StringRef, 4> uid_parts;
- line.substr(4).trim().split(uid_parts, '\t', -1, false);
- if (uid_parts.size() >= 2) {
- uint32_t uid, euid;
- if (llvm::to_integer(uid_parts[0].trim(), uid))
- process_info.SetUserID(uid);
- if (llvm::to_integer(uid_parts[1].trim(), euid))
- process_info.SetEffectiveUserID(euid);
- }
- } else if (line.starts_with("Gid:")) {
- llvm::SmallVector<llvm::StringRef, 4> gid_parts;
- line.substr(4).trim().split(gid_parts, '\t', -1, false);
- if (gid_parts.size() >= 2) {
- uint32_t gid, egid;
- if (llvm::to_integer(gid_parts[0].trim(), gid))
- process_info.SetGroupID(gid);
- if (llvm::to_integer(gid_parts[1].trim(), egid))
- process_info.SetEffectiveGroupID(egid);
- }
+ std::unordered_map<lldb::pid_t, ProcessInstanceInfo *> pid_map;
+ std::string pid_list;
+ for (auto &proc_info : proc_infos) {
+ if (NeedsCmdlineSupplement(proc_info)) {
+ lldb::pid_t pid = proc_info.GetProcessID();
+ pid_map[pid] = &proc_info;
+ if (!pid_list.empty())
+ pid_list += " ";
+ pid_list += std::to_string(pid);
}
}
-}
-// Helper function to populate command line arguments from /proc/[pid]/cmdline
-void PlatformAndroid::PopulateProcessCommandLine(
- lldb::pid_t pid, ProcessInstanceInfo &process_info) {
- // Read /proc/[pid]/cmdline to get command line arguments
- Status error;
- AdbClientUP cmdline_adb = GetAdbClient(error);
- if (error.Fail())
+ if (pid_list.empty())
return;
+ // Use xargs -P to parallelize cmdline fetching (up to 8 concurrent reads)
+ StreamString cmd;
+ cmd.Printf(
+ "echo '%s' | xargs -n 1 -P 8 sh -c "
+ "'echo \"$1:$(cat /proc/$1/cmdline 2>/dev/null | tr \"\\0\" \" \")\"'
sh",
+ pid_list.c_str());
+
std::string cmdline_output;
- StreamString cmdline_cmd;
- cmdline_cmd.Printf("cat /proc/%llu/cmdline 2>/dev/null | tr '\\000' ' '",
- static_cast<unsigned long long>(pid));
- Status cmdline_error =
- cmdline_adb->Shell(cmdline_cmd.GetData(), seconds(5), &cmdline_output);
+ Status error = adb->Shell(cmd.GetData(), seconds(5), &cmdline_output);
- if (cmdline_error.Fail() || cmdline_output.empty())
+ if (error.Fail() || cmdline_output.empty())
return;
- cmdline_output = llvm::StringRef(cmdline_output).trim().str();
- if (cmdline_output.empty())
- return;
+ llvm::SmallVector<llvm::StringRef, 256> lines;
+ llvm::StringRef(cmdline_output).split(lines, '\n', -1, false);
- llvm::SmallVector<llvm::StringRef, 16> args;
- llvm::StringRef(cmdline_output).split(args, ' ', -1, false);
- if (args.empty())
- return;
+ for (llvm::StringRef line : lines) {
+ line = line.trim();
+ auto colon_pos = line.find(':');
----------------
JDevlieghere wrote:
This looks like a good candidate for using StringRef::split.
https://github.com/llvm/llvm-project/pull/164333
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits