Loading cmds/lshal/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ cc_test { "libgmock" ], shared_libs: [ "libvintf", "android.hardware.tests.baz@1.0" ], srcs: [ Loading cmds/lshal/ListCommand.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ NullableOStream<std::ostream> ListCommand::err() const { return mLshal.err(); } std::string getCmdline(pid_t pid) { std::string ListCommand::parseCmdline(pid_t pid) const { std::ifstream ifs("/proc/" + std::to_string(pid) + "/cmdline"); std::string cmdline; if (!ifs.is_open()) { Loading @@ -70,7 +70,7 @@ const std::string &ListCommand::getCmdline(pid_t pid) { if (pair != mCmdlines.end()) { return pair->second; } mCmdlines[pid] = ::android::lshal::getCmdline(pid); mCmdlines[pid] = parseCmdline(pid); return mCmdlines[pid]; } Loading cmds/lshal/ListCommand.h +10 −6 Original line number Diff line number Diff line Loading @@ -36,9 +36,16 @@ namespace lshal { class Lshal; struct PidInfo { std::map<uint64_t, Pids> refPids; // pids that are referenced uint32_t threadUsage; // number of threads in use uint32_t threadCount; // number of threads total }; class ListCommand { public: ListCommand(Lshal &lshal); virtual ~ListCommand() = default; Status main(const std::string &command, const Arg &arg); protected: Status parseArgs(const std::string &command, const Arg &arg); Loading @@ -50,12 +57,7 @@ protected: Status fetchBinderized(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager); Status fetchAllLibraries(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager); struct PidInfo { std::map<uint64_t, Pids> refPids; // pids that are referenced uint32_t threadUsage; // number of threads in use uint32_t threadCount; // number of threads total }; bool getPidInfo(pid_t serverPid, PidInfo *info) const; virtual bool getPidInfo(pid_t serverPid, PidInfo *info) const; void dumpTable(const NullableOStream<std::ostream>& out) const; void dumpVintf(const NullableOStream<std::ostream>& out) const; Loading @@ -64,6 +66,8 @@ protected: const std::string &serverCmdline, const std::string &address, const std::string &clients, const std::string &clientCmdlines) const; void addLine(TextTable *table, const TableEntry &entry); // Read and return /proc/{pid}/cmdline. virtual std::string parseCmdline(pid_t pid) const; // Return /proc/{pid}/cmdline if it exists, else empty string. const std::string &getCmdline(pid_t pid); // Call getCmdline on all pid in pids. If it returns empty string, the process might Loading cmds/lshal/TableEntry.cpp +22 −0 Original line number Diff line number Diff line Loading @@ -152,5 +152,27 @@ TextTable MergedTable::createTextTable() { return textTable; } bool TableEntry::operator==(const TableEntry& other) const { if (this == &other) { return true; } return interfaceName == other.interfaceName && transport == other.transport && serverPid == other.serverPid && threadUsage == other.threadUsage && threadCount == other.threadCount && serverCmdline == other.serverCmdline && serverObjectAddress == other.serverObjectAddress && clientPids == other.clientPids && clientCmdlines == other.clientCmdlines && arch == other.arch; } std::string TableEntry::to_string() const { std::stringstream ss; ss << "name=" << interfaceName << ";transport=" << transport << ";thread=" << getThreadUsage() << ";server=" << serverPid << "(" << serverObjectAddress << ";" << serverCmdline << ");clients=[" << join(clientPids, ";") << "](" << join(clientCmdlines, ";") << ");arch=" << getArchString(arch); return ss.str(); } } // namespace lshal } // namespace android cmds/lshal/TableEntry.h +4 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,9 @@ struct TableEntry { } std::string getField(TableColumnType type) const; bool operator==(const TableEntry& other) const; std::string to_string() const; }; using SelectedColumns = std::vector<TableColumnType>; Loading @@ -97,6 +100,7 @@ public: Entries::const_iterator begin() const { return mEntries.begin(); } Entries::iterator end() { return mEntries.end(); } Entries::const_iterator end() const { return mEntries.end(); } size_t size() const { return mEntries.size(); } void add(TableEntry&& entry) { mEntries.push_back(std::move(entry)); } Loading Loading
cmds/lshal/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,7 @@ cc_test { "libgmock" ], shared_libs: [ "libvintf", "android.hardware.tests.baz@1.0" ], srcs: [ Loading
cmds/lshal/ListCommand.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ NullableOStream<std::ostream> ListCommand::err() const { return mLshal.err(); } std::string getCmdline(pid_t pid) { std::string ListCommand::parseCmdline(pid_t pid) const { std::ifstream ifs("/proc/" + std::to_string(pid) + "/cmdline"); std::string cmdline; if (!ifs.is_open()) { Loading @@ -70,7 +70,7 @@ const std::string &ListCommand::getCmdline(pid_t pid) { if (pair != mCmdlines.end()) { return pair->second; } mCmdlines[pid] = ::android::lshal::getCmdline(pid); mCmdlines[pid] = parseCmdline(pid); return mCmdlines[pid]; } Loading
cmds/lshal/ListCommand.h +10 −6 Original line number Diff line number Diff line Loading @@ -36,9 +36,16 @@ namespace lshal { class Lshal; struct PidInfo { std::map<uint64_t, Pids> refPids; // pids that are referenced uint32_t threadUsage; // number of threads in use uint32_t threadCount; // number of threads total }; class ListCommand { public: ListCommand(Lshal &lshal); virtual ~ListCommand() = default; Status main(const std::string &command, const Arg &arg); protected: Status parseArgs(const std::string &command, const Arg &arg); Loading @@ -50,12 +57,7 @@ protected: Status fetchBinderized(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager); Status fetchAllLibraries(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager); struct PidInfo { std::map<uint64_t, Pids> refPids; // pids that are referenced uint32_t threadUsage; // number of threads in use uint32_t threadCount; // number of threads total }; bool getPidInfo(pid_t serverPid, PidInfo *info) const; virtual bool getPidInfo(pid_t serverPid, PidInfo *info) const; void dumpTable(const NullableOStream<std::ostream>& out) const; void dumpVintf(const NullableOStream<std::ostream>& out) const; Loading @@ -64,6 +66,8 @@ protected: const std::string &serverCmdline, const std::string &address, const std::string &clients, const std::string &clientCmdlines) const; void addLine(TextTable *table, const TableEntry &entry); // Read and return /proc/{pid}/cmdline. virtual std::string parseCmdline(pid_t pid) const; // Return /proc/{pid}/cmdline if it exists, else empty string. const std::string &getCmdline(pid_t pid); // Call getCmdline on all pid in pids. If it returns empty string, the process might Loading
cmds/lshal/TableEntry.cpp +22 −0 Original line number Diff line number Diff line Loading @@ -152,5 +152,27 @@ TextTable MergedTable::createTextTable() { return textTable; } bool TableEntry::operator==(const TableEntry& other) const { if (this == &other) { return true; } return interfaceName == other.interfaceName && transport == other.transport && serverPid == other.serverPid && threadUsage == other.threadUsage && threadCount == other.threadCount && serverCmdline == other.serverCmdline && serverObjectAddress == other.serverObjectAddress && clientPids == other.clientPids && clientCmdlines == other.clientCmdlines && arch == other.arch; } std::string TableEntry::to_string() const { std::stringstream ss; ss << "name=" << interfaceName << ";transport=" << transport << ";thread=" << getThreadUsage() << ";server=" << serverPid << "(" << serverObjectAddress << ";" << serverCmdline << ");clients=[" << join(clientPids, ";") << "](" << join(clientCmdlines, ";") << ");arch=" << getArchString(arch); return ss.str(); } } // namespace lshal } // namespace android
cmds/lshal/TableEntry.h +4 −0 Original line number Diff line number Diff line Loading @@ -85,6 +85,9 @@ struct TableEntry { } std::string getField(TableColumnType type) const; bool operator==(const TableEntry& other) const; std::string to_string() const; }; using SelectedColumns = std::vector<TableColumnType>; Loading @@ -97,6 +100,7 @@ public: Entries::const_iterator begin() const { return mEntries.begin(); } Entries::iterator end() { return mEntries.end(); } Entries::const_iterator end() const { return mEntries.end(); } size_t size() const { return mEntries.size(); } void add(TableEntry&& entry) { mEntries.push_back(std::move(entry)); } Loading