lshal: ListCommand::getPidInfo should be cached.
The function parses a big file and its result should be cached.
Add ListCommand::getPidInfoCached, which is a cached version
of this function.
Test: lshal_test
Change-Id: I03d8f149bf67b1512be431a3c4c29e83f7743a2f
diff --git a/cmds/lshal/ListCommand.h b/cmds/lshal/ListCommand.h
index 049533a..5af7ec2 100644
--- a/cmds/lshal/ListCommand.h
+++ b/cmds/lshal/ListCommand.h
@@ -85,7 +85,11 @@
Status fetchBinderized(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager);
Status fetchAllLibraries(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager);
+ // Get relevant information for a PID by parsing files under /d/binder.
+ // It is a virtual member function so that it can be mocked.
virtual bool getPidInfo(pid_t serverPid, PidInfo *info) const;
+ // Retrieve from mCachedPidInfos and call getPidInfo if necessary.
+ const PidInfo* getPidInfoCached(pid_t serverPid);
void dumpTable(const NullableOStream<std::ostream>& out) const;
void dumpVintf(const NullableOStream<std::ostream>& out) const;
@@ -129,6 +133,9 @@
// If an entry exist and not empty, it contains the cached content of /proc/{pid}/cmdline.
std::map<pid_t, std::string> mCmdlines;
+ // Cache for getPidInfo.
+ std::map<pid_t, PidInfo> mCachedPidInfos;
+
RegisteredOptions mOptions;
// All selected columns
std::vector<TableColumnType> mSelectedColumns;