summaryrefslogtreecommitdiff
path: root/libs/binderdebug/BinderDebug.cpp
diff options
context:
space:
mode:
author Devin Moore <devinmoore@google.com> 2021-08-05 19:05:45 +0000
committer Devin Moore <devinmoore@google.com> 2021-08-06 17:03:13 +0000
commitdef9faea5ebf63e195f65949c4b6aae89cdb22d9 (patch)
tree05a791e1157e6d38575762161bf78d7ea99bf9d7 /libs/binderdebug/BinderDebug.cpp
parentf6f2e64c29af2200e89fdf39ccc23d2bb57cce07 (diff)
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/<pid>. 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
Diffstat (limited to 'libs/binderdebug/BinderDebug.cpp')
-rw-r--r--libs/binderdebug/BinderDebug.cpp57
1 files changed, 57 insertions, 0 deletions
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 <android-base/logging.h>
#include <android-base/parseint.h>
#include <android-base/strings.h>
#include <binder/Binder.h>
@@ -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<pid_t>* 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