blob: a75db04960fdab559d1faa7beeec59e5db5c9fe5 [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"
31#include "utils.h"
32
33namespace android {
34namespace lshal {
35
36class Lshal;
37
38class ListCommand {
39public:
40 ListCommand(Lshal &lshal);
41 Status main(const std::string &command, const Arg &arg);
42private:
43 Status parseArgs(const std::string &command, const Arg &arg);
44 Status fetch();
45 void postprocess();
46 void dump();
47 void putEntry(TableEntrySource source, TableEntry &&entry);
48 Status fetchPassthrough(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager);
49 Status fetchBinderized(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager);
50 Status fetchAllLibraries(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager);
Steven Morelandd8e20192017-05-24 11:23:08 -070051
52 struct PidInfo {
53 std::map<uint64_t, Pids> refPids; // pids that are referenced
54 uint32_t threadUsage; // number of threads in use
55 uint32_t threadCount; // number of threads total
56 };
57 bool getPidInfo(pid_t serverPid, PidInfo *info) const;
58
Yifan Hong443df792017-05-09 18:49:45 -070059 void dumpTable();
60 void dumpVintf() const;
61 void printLine(
62 const std::string &interfaceName,
63 const std::string &transport,
64 const std::string &arch,
Steven Morelandd8e20192017-05-24 11:23:08 -070065 const std::string &threadUsage,
Yifan Hong443df792017-05-09 18:49:45 -070066 const std::string &server,
67 const std::string &serverCmdline,
Steven Morelandd8e20192017-05-24 11:23:08 -070068 const std::string &address,
69 const std::string &clients,
70 const std::string &clientCmdlines) const;
Yifan Hong443df792017-05-09 18:49:45 -070071 // Return /proc/{pid}/cmdline if it exists, else empty string.
72 const std::string &getCmdline(pid_t pid);
73 // Call getCmdline on all pid in pids. If it returns empty string, the process might
74 // have died, and the pid is removed from pids.
75 void removeDeadProcesses(Pids *pids);
76 void forEachTable(const std::function<void(Table &)> &f);
77 void forEachTable(const std::function<void(const Table &)> &f) const;
78
79 Lshal &mLshal;
80
81 Table mServicesTable{};
82 Table mPassthroughRefTable{};
83 Table mImplementationsTable{};
84
85 NullableOStream<std::ostream> mErr;
86 NullableOStream<std::ostream> mOut;
87 NullableOStream<std::ofstream> mFileOutput = nullptr;
88 TableEntryCompare mSortColumn = nullptr;
89 TableEntrySelect mSelectedColumns = 0;
90 // If true, cmdlines will be printed instead of pid.
91 bool mEnableCmdlines = false;
92
93 // If true, calls IBase::debug(...) on each service.
94 bool mEmitDebugInfo = false;
95
Yifan Hong6da06912017-05-12 16:56:43 -070096 // If true, output in VINTF format.
Yifan Hong443df792017-05-09 18:49:45 -070097 bool mVintf = false;
Yifan Hong6da06912017-05-12 16:56:43 -070098
99 // If true, explanatory text are not emitted.
100 bool mNeat = false;
101
Yifan Hong443df792017-05-09 18:49:45 -0700102 // If an entry does not exist, need to ask /proc/{pid}/cmdline to get it.
103 // If an entry exist but is an empty string, process might have died.
104 // If an entry exist and not empty, it contains the cached content of /proc/{pid}/cmdline.
105 std::map<pid_t, std::string> mCmdlines;
106
107 DISALLOW_COPY_AND_ASSIGN(ListCommand);
108};
109
110
111} // namespace lshal
112} // namespace android
113
114#endif // FRAMEWORK_NATIVE_CMDS_LSHAL_LIST_COMMAND_H_