blob: 51f1ca580e2f496fae8614a52602924f03f86bb6 [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();
Yifan Hongca3b6602017-09-07 16:44:27 -070047 Status dump();
Yifan Hong443df792017-05-09 18:49:45 -070048 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 Hongca3b6602017-09-07 16:44:27 -070060 void dumpTable(const NullableOStream<std::ostream>& out) const;
61 void dumpVintf(const NullableOStream<std::ostream>& out) 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
Yifan Hong76ac14a2017-09-08 14:59:04 -070075 NullableOStream<std::ostream> err() const;
76 NullableOStream<std::ostream> out() const;
77
Yifan Hong443df792017-05-09 18:49:45 -070078 Lshal &mLshal;
79
80 Table mServicesTable{};
81 Table mPassthroughRefTable{};
82 Table mImplementationsTable{};
83
Yifan Hongca3b6602017-09-07 16:44:27 -070084 std::string mFileOutputPath;
Yifan Hong443df792017-05-09 18:49:45 -070085 TableEntryCompare mSortColumn = nullptr;
Yifan Hong443df792017-05-09 18:49:45 -070086
Yifan Hong443df792017-05-09 18:49:45 -070087 bool mEmitDebugInfo = false;
88
Yifan Hong6da06912017-05-12 16:56:43 -070089 // If true, output in VINTF format.
Yifan Hong443df792017-05-09 18:49:45 -070090 bool mVintf = false;
Yifan Hong6da06912017-05-12 16:56:43 -070091
92 // If true, explanatory text are not emitted.
93 bool mNeat = false;
94
Yifan Hong443df792017-05-09 18:49:45 -070095 // If an entry does not exist, need to ask /proc/{pid}/cmdline to get it.
96 // If an entry exist but is an empty string, process might have died.
97 // If an entry exist and not empty, it contains the cached content of /proc/{pid}/cmdline.
98 std::map<pid_t, std::string> mCmdlines;
99
100 DISALLOW_COPY_AND_ASSIGN(ListCommand);
101};
102
103
104} // namespace lshal
105} // namespace android
106
107#endif // FRAMEWORK_NATIVE_CMDS_LSHAL_LIST_COMMAND_H_