Skip to content

Commit f26f610

Browse files
Treehugger RobotGerrit Code Review
authored andcommitted
Merge "Add Tracing for Binder Caching" into main
2 parents a7e65a4 + a6676ba commit f26f610

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

libs/binder/BackendUnifiedServiceManager.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,30 @@ binder::Status BackendUnifiedServiceManager::updateCache(const std::string& serv
123123
if (!kUseCache) {
124124
return binder::Status::ok();
125125
}
126+
std::string traceStr;
127+
if (atrace_is_tag_enabled(ATRACE_TAG_AIDL)) {
128+
traceStr = "BinderCacheWithInvalidation::updateCache : " + serviceName;
129+
}
130+
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, traceStr.c_str());
131+
126132
if (service.getTag() == os::Service::Tag::binder) {
127133
sp<IBinder> binder = service.get<os::Service::Tag::binder>();
128-
if (binder && mCacheForGetService->isClientSideCachingEnabled(serviceName) &&
129-
binder->isBinderAlive()) {
134+
if (!binder) {
135+
binder::ScopedTrace
136+
aidlTrace(ATRACE_TAG_AIDL,
137+
"BinderCacheWithInvalidation::updateCache failed: binder_null");
138+
} else if (!binder->isBinderAlive()) {
139+
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
140+
"BinderCacheWithInvalidation::updateCache failed: "
141+
"isBinderAlive_false");
142+
} else if (mCacheForGetService->isClientSideCachingEnabled(serviceName)) {
143+
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
144+
"BinderCacheWithInvalidation::updateCache successful");
130145
return mCacheForGetService->setItem(serviceName, binder);
146+
} else {
147+
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
148+
"BinderCacheWithInvalidation::updateCache failed: "
149+
"caching_not_enabled");
131150
}
132151
}
133152
return binder::Status::ok();

libs/binder/BackendUnifiedServiceManager.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <android/os/BnServiceManager.h>
1919
#include <android/os/IServiceManager.h>
2020
#include <binder/IPCThreadState.h>
21+
#include <binder/Trace.h>
2122
#include <map>
2223
#include <memory>
2324

@@ -59,6 +60,12 @@ class BinderCacheWithInvalidation
5960
}
6061

6162
bool removeItem(const std::string& key, const sp<IBinder>& who) {
63+
std::string traceStr;
64+
uint64_t tag = ATRACE_TAG_AIDL;
65+
if (atrace_is_tag_enabled(tag)) {
66+
traceStr = "BinderCacheWithInvalidation::removeItem " + key;
67+
}
68+
binder::ScopedTrace aidlTrace(tag, traceStr.c_str());
6269
std::lock_guard<std::mutex> lock(mCacheMutex);
6370
if (auto it = mCache.find(key); it != mCache.end()) {
6471
if (it->second.service == who) {
@@ -81,11 +88,22 @@ class BinderCacheWithInvalidation
8188
if (item->localBinder() == nullptr) {
8289
status_t status = item->linkToDeath(deathRecipient);
8390
if (status != android::OK) {
91+
std::string traceStr;
92+
uint64_t tag = ATRACE_TAG_AIDL;
93+
if (atrace_is_tag_enabled(tag)) {
94+
traceStr =
95+
"BinderCacheWithInvalidation::setItem Failed LinkToDeath for service " +
96+
key + " : " + std::to_string(status);
97+
}
98+
binder::ScopedTrace aidlTrace(tag, traceStr.c_str());
99+
84100
ALOGE("Failed to linkToDeath binder for service %s. Error: %d", key.c_str(),
85101
status);
86102
return binder::Status::fromStatusT(status);
87103
}
88104
}
105+
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
106+
"BinderCacheWithInvalidation::setItem Successfully Cached");
89107
std::lock_guard<std::mutex> lock(mCacheMutex);
90108
Entry entry = {.service = item, .deathRecipient = deathRecipient};
91109
mCache[key] = entry;

0 commit comments

Comments
 (0)