summaryrefslogtreecommitdiff
path: root/libs/binderdebug/BinderDebug.cpp
diff options
context:
space:
mode:
author Devin Moore <devinmoore@google.com> 2024-04-02 22:39:14 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2024-04-02 22:39:14 +0000
commit9c01ea307db822c56e6e6eeb58d1eca942fb2325 (patch)
tree0c8f4853ca05273474ca135da371f526710d07f9 /libs/binderdebug/BinderDebug.cpp
parent86d68513294b1ba39c8f68322995f15208721d30 (diff)
parent74661b828aca79e53a3268e85b553c03225faa8a (diff)
Merge "Add a method to get the binderfs transactions for a given process" into main am: 8c540c7795 am: 74661b828a
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2940609 Change-Id: I4996c3afec3761500a212267e54bc9333e4a8d83 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'libs/binderdebug/BinderDebug.cpp')
-rw-r--r--libs/binderdebug/BinderDebug.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/libs/binderdebug/BinderDebug.cpp b/libs/binderdebug/BinderDebug.cpp
index a8f2cbfb5b..19f3aad04f 100644
--- a/libs/binderdebug/BinderDebug.cpp
+++ b/libs/binderdebug/BinderDebug.cpp
@@ -199,4 +199,31 @@ status_t getBinderClientPids(BinderDebugContext context, pid_t pid, pid_t servic
return ret;
}
+status_t getBinderTransactions(pid_t pid, std::string& transactionsOutput) {
+ std::ifstream ifs("/dev/binderfs/binder_logs/transactions");
+ if (!ifs.is_open()) {
+ ifs.open("/d/binder/transactions");
+ if (!ifs.is_open()) {
+ LOG(ERROR) << "Could not open /dev/binderfs/binder_logs/transactions. "
+ << "Likely a permissions issue. errno: " << errno;
+ return -errno;
+ }
+ }
+
+ std::string line;
+ while (getline(ifs, line)) {
+ // The section for this pid ends with another "proc <pid>" for another
+ // process. There is only one entry per pid so we can stop looking after
+ // we've grabbed the whole section
+ if (base::StartsWith(line, "proc " + std::to_string(pid))) {
+ do {
+ transactionsOutput += line + '\n';
+ } while (getline(ifs, line) && !base::StartsWith(line, "proc "));
+ return OK;
+ }
+ }
+
+ return NAME_NOT_FOUND;
+}
+
} // namespace android