Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef FRAMEWORK_NATIVE_CMDS_LSHAL_LSHAL_H_ |
| 18 | #define FRAMEWORK_NATIVE_CMDS_LSHAL_LSHAL_H_ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include <iostream> |
| 23 | #include <string> |
| 24 | #include <vector> |
| 25 | |
| 26 | #include <android/hidl/manager/1.0/IServiceManager.h> |
| 27 | |
| 28 | #include "TableEntry.h" |
| 29 | |
| 30 | namespace android { |
| 31 | namespace lshal { |
| 32 | |
| 33 | enum : unsigned int { |
| 34 | OK = 0, |
| 35 | USAGE = 1 << 0, |
| 36 | NO_BINDERIZED_MANAGER = 1 << 1, |
| 37 | NO_PASSTHROUGH_MANAGER = 1 << 2, |
| 38 | DUMP_BINDERIZED_ERROR = 1 << 3, |
| 39 | DUMP_PASSTHROUGH_ERROR = 1 << 4, |
| 40 | DUMP_ALL_LIBS_ERROR = 1 << 5, |
| 41 | }; |
| 42 | using Status = unsigned int; |
| 43 | |
| 44 | class Lshal { |
| 45 | public: |
| 46 | int main(int argc, char **argv); |
| 47 | |
| 48 | private: |
| 49 | Status parseArgs(int argc, char **argv); |
| 50 | Status fetch(); |
Yifan Hong | 38d53e0 | 2017-02-13 17:51:59 -0800 | [diff] [blame] | 51 | void postprocess(); |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 52 | void dump() const; |
| 53 | void usage() const; |
| 54 | void putEntry(TableEntry &&entry); |
| 55 | Status fetchPassthrough(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager); |
| 56 | Status fetchBinderized(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager); |
| 57 | Status fetchAllLibraries(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager); |
| 58 | bool getReferencedPids( |
| 59 | pid_t serverPid, std::map<uint64_t, Pids> *objects) const; |
Yifan Hong | 38d53e0 | 2017-02-13 17:51:59 -0800 | [diff] [blame] | 60 | void printLine( |
| 61 | const std::string &interfaceName, |
| 62 | const std::string &transport, const std::string &server, |
Yifan Hong | ae09a3d | 2017-02-14 17:33:50 -0800 | [diff] [blame] | 63 | const std::string &serverCmdline, |
| 64 | const std::string &address, const std::string &clients, |
| 65 | const std::string &clientCmdlines) const ; |
| 66 | // Return /proc/{pid}/cmdline if it exists, else empty string. |
| 67 | const std::string &getCmdline(pid_t pid); |
| 68 | // Call getCmdline on all pid in pids. If it returns empty string, the process might |
| 69 | // have died, and the pid is removed from pids. |
| 70 | void removeDeadProcesses(Pids *pids); |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 71 | |
Yifan Hong | 38d53e0 | 2017-02-13 17:51:59 -0800 | [diff] [blame] | 72 | Table mTable{}; |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 73 | std::ostream &mErr = std::cerr; |
| 74 | std::ostream &mOut = std::cout; |
Yifan Hong | 38d53e0 | 2017-02-13 17:51:59 -0800 | [diff] [blame] | 75 | TableEntryCompare mSortColumn = nullptr; |
| 76 | TableEntrySelect mSelectedColumns = 0; |
Yifan Hong | ae09a3d | 2017-02-14 17:33:50 -0800 | [diff] [blame] | 77 | // If true, cmdlines will be printed instead of pid. |
| 78 | bool mEnableCmdlines; |
| 79 | // If an entry does not exist, need to ask /proc/{pid}/cmdline to get it. |
| 80 | // If an entry exist but is an empty string, process might have died. |
| 81 | // If an entry exist and not empty, it contains the cached content of /proc/{pid}/cmdline. |
| 82 | std::map<pid_t, std::string> mCmdlines; |
Yifan Hong | b0dde93 | 2017-02-10 17:49:58 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | |
| 86 | } // namespace lshal |
| 87 | } // namespace android |
| 88 | |
| 89 | #endif // FRAMEWORK_NATIVE_CMDS_LSHAL_LSHAL_H_ |