diff options
| author | 2024-04-02 22:22:24 +0000 | |
|---|---|---|
| committer | 2024-04-02 22:22:24 +0000 | |
| commit | 74661b828aca79e53a3268e85b553c03225faa8a (patch) | |
| tree | 6bb17d2615129c98d4ce3c332711f1e60bcc2c39 | |
| parent | abd19c8d4883e9b84b38a8cab9c950cdb31648f5 (diff) | |
| parent | 8c540c77956b11f42a8ad2a4defa4d6edce4d639 (diff) | |
Merge "Add a method to get the binderfs transactions for a given process" into main am: 8c540c7795
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2940609
Change-Id: I9ed55684a3e36f7080d2e30cfdcdfbdaf9857985
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | libs/binderdebug/BinderDebug.cpp | 27 | ||||
| -rw-r--r-- | libs/binderdebug/include/binderdebug/BinderDebug.h | 8 |
2 files changed, 35 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 diff --git a/libs/binderdebug/include/binderdebug/BinderDebug.h b/libs/binderdebug/include/binderdebug/BinderDebug.h index 6ce8edfc7c..018393c128 100644 --- a/libs/binderdebug/include/binderdebug/BinderDebug.h +++ b/libs/binderdebug/include/binderdebug/BinderDebug.h @@ -44,4 +44,12 @@ status_t getBinderPidInfo(BinderDebugContext context, pid_t pid, BinderPidInfo* status_t getBinderClientPids(BinderDebugContext context, pid_t pid, pid_t servicePid, int32_t handle, std::vector<pid_t>* pids); +/** + * Get the transactions for a given process from /dev/binderfs/binder_logs/transactions + * Return: OK if the file was found and the pid was found in the file. + * -errno if there was an issue opening the file + * NAME_NOT_FOUND if the pid wasn't found in the file + */ +status_t getBinderTransactions(pid_t pid, std::string& transactionOutput); + } // namespace android |