blob: d06ec7d7cfef9fa3a1d03b97b9eef1c1c3cfb0e6 [file] [log] [blame]
Yifan Hong443df792017-05-09 18:49:45 -07001/*
2 * Copyright (C) 2017 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_LIST_COMMAND_H_
18#define FRAMEWORK_NATIVE_CMDS_LSHAL_LIST_COMMAND_H_
19
20#include <stdint.h>
21
22#include <fstream>
23#include <string>
24#include <vector>
25
26#include <android-base/macros.h>
27#include <android/hidl/manager/1.0/IServiceManager.h>
28
29#include "NullableOStream.h"
30#include "TableEntry.h"
Yifan Hong1bc1e9f2017-08-29 17:28:12 -070031#include "TextTable.h"
Yifan Hong443df792017-05-09 18:49:45 -070032#include "utils.h"
33
34namespace android {
35namespace lshal {
36
37class Lshal;
38
39class ListCommand {
40public:
41 ListCommand(Lshal &lshal);
42 Status main(const std::string &command, const Arg &arg);
43private:
44 Status parseArgs(const std::string &command, const Arg &arg);
45 Status fetch();
46 void postprocess();
47 void dump();
48 void putEntry(TableEntrySource source, TableEntry &&entry);
49 Status fetchPassthrough(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager);
50 Status fetchBinderized(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager);
51 Status fetchAllLibraries(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager);
Steven Morelandd8e20192017-05-24 11:23:08 -070052
53 struct PidInfo {
54 std::map<uint64_t, Pids> refPids; // pids that are referenced
55 uint32_t threadUsage; // number of threads in use
56 uint32_t threadCount; // number of threads total
57 };
58 bool getPidInfo(pid_t serverPid, PidInfo *info) const;
59
Yifan Hong443df792017-05-09 18:49:45 -070060 void dumpTable();
61 void dumpVintf() const;
Yifan Hong1bc1e9f2017-08-29 17:28:12 -070062 void addLine(TextTable *table, const std::string &interfaceName, const std::string &transport,
63 const std::string &arch, const std::string &threadUsage, const std::string &server,
64 const std::string &serverCmdline, const std::string &address,
65 const std::string &clients, const std::string &clientCmdlines) const;
66 void addLine(TextTable *table, const TableEntry &entry);
Yifan Hong443df792017-05-09 18:49:45 -070067 // Return /proc/{pid}/cmdline if it exists, else empty string.
68 const std::string &getCmdline(pid_t pid);
69 // Call getCmdline on all pid in pids. If it returns empty string, the process might
70 // have died, and the pid is removed from pids.
71 void removeDeadProcesses(Pids *pids);
72 void forEachTable(const std::function<void(Table &)> &f);
73 void forEachTable(const std::function<void(const Table &)> &f) const;
74
75 Lshal &mLshal;
76
77 Table mServicesTable{};
78 Table mPassthroughRefTable{};
79 Table mImplementationsTable{};
80
81 NullableOStream<std::ostream> mErr;
82 NullableOStream<std::ostream> mOut;
83 NullableOStream<std::ofstream> mFileOutput = nullptr;
84 TableEntryCompare mSortColumn = nullptr;
85 TableEntrySelect mSelectedColumns = 0;
86 // If true, cmdlines will be printed instead of pid.
87 bool mEnableCmdlines = false;
88
89 // If true, calls IBase::debug(...) on each service.
90 bool mEmitDebugInfo = false;
91
Yifan Hong6da06912017-05-12 16:56:43 -070092 // If true, output in VINTF format.
Yifan Hong443df792017-05-09 18:49:45 -070093 bool mVintf = false;
Yifan Hong6da06912017-05-12 16:56:43 -070094
95 // If true, explanatory text are not emitted.
96 bool mNeat = false;
97
Yifan Hong443df792017-05-09 18:49:45 -070098 // If an entry does not exist, need to ask /proc/{pid}/cmdline to get it.
99 // If an entry exist but is an empty string, process might have died.
100 // If an entry exist and not empty, it contains the cached content of /proc/{pid}/cmdline.
101 std::map<pid_t, std::string> mCmdlines;
102
103 DISALLOW_COPY_AND_ASSIGN(ListCommand);
104};
105
106
107} // namespace lshal
108} // namespace android
109
110#endif // FRAMEWORK_NATIVE_CMDS_LSHAL_LIST_COMMAND_H_