Skip to content

Commit a6676ba

Browse files
committed
Add Tracing for Binder Caching
Test: perfetto -c <perfetto config> Bug: 333854840 Change-Id: Iffb1e00f94722f60c85305e0596ce58b0df5a6da
1 parent 4811398 commit a6676ba

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
@@ -114,11 +114,30 @@ binder::Status BackendUnifiedServiceManager::updateCache(const std::string& serv
114114
if (!kUseCache) {
115115
return binder::Status::ok();
116116
}
117+
std::string traceStr;
118+
if (atrace_is_tag_enabled(ATRACE_TAG_AIDL)) {
119+
traceStr = "BinderCacheWithInvalidation::updateCache : " + serviceName;
120+
}
121+
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL, traceStr.c_str());
122+
117123
if (service.getTag() == os::Service::Tag::binder) {
118124
sp<IBinder> binder = service.get<os::Service::Tag::binder>();
119-
if (binder && mCacheForGetService->isClientSideCachingEnabled(serviceName) &&
120-
binder->isBinderAlive()) {
125+
if (!binder) {
126+
binder::ScopedTrace
127+
aidlTrace(ATRACE_TAG_AIDL,
128+
"BinderCacheWithInvalidation::updateCache failed: binder_null");
129+
} else if (!binder->isBinderAlive()) {
130+
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
131+
"BinderCacheWithInvalidation::updateCache failed: "
132+
"isBinderAlive_false");
133+
} else if (mCacheForGetService->isClientSideCachingEnabled(serviceName)) {
134+
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
135+
"BinderCacheWithInvalidation::updateCache successful");
121136
return mCacheForGetService->setItem(serviceName, binder);
137+
} else {
138+
binder::ScopedTrace aidlTrace(ATRACE_TAG_AIDL,
139+
"BinderCacheWithInvalidation::updateCache failed: "
140+
"caching_not_enabled");
122141
}
123142
}
124143
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)