From def9faea5ebf63e195f65949c4b6aae89cdb22d9 Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Thu, 5 Aug 2021 19:05:45 +0000 Subject: dumpsys: display the client PIDs of all of the services When gathering info on a service, get the BpBinder handle to look up the node number of the binder service in binder_logs/proc/. Look up the node number in binder_logs/state from the binder service. That entry in the state file has the client PIDs. Example output: $ adb shell dumpsys --clients android.hardware.power.IPower/default Client PIDs: 437, 708, 203 Test: adb root && adb shell dumpsys --clients Test: adb shell dumpsys --clients power Test: adb shell dumpsys --clients --pid Change-Id: I0daebc18cb9f47925ccec5a3eb0b09c4b1e43fe4 --- libs/binderdebug/BinderDebug.cpp | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'libs/binderdebug/BinderDebug.cpp') diff --git a/libs/binderdebug/BinderDebug.cpp b/libs/binderdebug/BinderDebug.cpp index b435dba197..d086b49a7b 100644 --- a/libs/binderdebug/BinderDebug.cpp +++ b/libs/binderdebug/BinderDebug.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include #include @@ -116,4 +117,60 @@ status_t getBinderPidInfo(BinderDebugContext context, pid_t pid, BinderPidInfo* return ret; } +status_t getBinderClientPids(BinderDebugContext context, pid_t pid, pid_t servicePid, + int32_t handle, std::vector* pids) { + std::smatch match; + static const std::regex kNodeNumber("^\\s+ref \\d+:\\s+desc\\s+(\\d+)\\s+node\\s+(\\d+).*"); + std::string contextStr = contextToString(context); + int32_t node; + status_t ret = scanBinderContext(pid, contextStr, [&](const std::string& line) { + if (std::regex_search(line, match, kNodeNumber)) { + const std::string& descString = match.str(1); + int32_t desc; + if (!::android::base::ParseInt(descString.c_str(), &desc)) { + LOG(ERROR) << "Failed to parse desc int: " << descString; + return; + } + if (handle != desc) { + return; + } + const std::string& nodeString = match.str(2); + if (!::android::base::ParseInt(nodeString.c_str(), &node)) { + LOG(ERROR) << "Failed to parse node int: " << nodeString; + return; + } + return; + } + return; + }); + if (ret != OK) { + return ret; + } + static const std::regex kClients("^\\s+node\\s+(\\d+).*proc\\s+([\\d+\\s*]*)"); + ret = scanBinderContext(servicePid, contextStr, [&](const std::string& line) { + if (std::regex_search(line, match, kClients)) { + const std::string nodeString = match.str(1); + int32_t matchedNode; + if (!::android::base::ParseInt(nodeString.c_str(), &matchedNode)) { + LOG(ERROR) << "Failed to parse node int: " << nodeString; + return; + } + if (node != matchedNode) { + return; + } + const std::string clients = match.str(2); + for (const std::string& pidStr : base::Split(clients, " ")) { + int32_t pid; + if (!::android::base::ParseInt(pidStr, &pid)) { + return; + } + pids->push_back(pid); + } + return; + } + return; + }); + return ret; +} + } // namespace android -- cgit v1.2.3-59-g8ed1b