blob: dac8b5e3b751da1f31e3c06fded341ed675d13f0 [file] [log] [blame]
Yifan Hongb0dde932017-02-10 17:49:58 -08001/*
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_TABLE_ENTRY_H_
18#define FRAMEWORK_NATIVE_CMDS_LSHAL_TABLE_ENTRY_H_
19
20#include <stdint.h>
21
22#include <string>
23#include <vector>
Yifan Hong38d53e02017-02-13 17:51:59 -080024#include <iostream>
Yifan Hongb0dde932017-02-10 17:49:58 -080025
Yifan Hongd4a77e82017-09-06 19:40:24 -070026#include "TextTable.h"
27
Yifan Hongb0dde932017-02-10 17:49:58 -080028namespace android {
29namespace lshal {
30
31using Pids = std::vector<int32_t>;
32
Yifan Hong4b865492017-02-28 19:38:24 -080033enum : unsigned int {
34 HWSERVICEMANAGER_LIST, // through defaultServiceManager()->list()
35 PTSERVICEMANAGER_REG_CLIENT, // through registerPassthroughClient
36 LIST_DLLIB, // through listing dynamic libraries
37};
38using TableEntrySource = unsigned int;
39
Yifan Hongb4479022017-03-02 16:54:11 -080040enum : unsigned int {
41 ARCH_UNKNOWN = 0,
Yifan Hong3fdbd9f2017-03-08 14:01:58 -080042 ARCH32 = 1 << 0,
43 ARCH64 = 1 << 1,
Yifan Hongb4479022017-03-02 16:54:11 -080044 ARCH_BOTH = ARCH32 | ARCH64
45};
46using Architecture = unsigned int;
47
Yifan Hongd4a77e82017-09-06 19:40:24 -070048enum class TableColumnType : unsigned int {
49 INTERFACE_NAME,
50 TRANSPORT,
51 SERVER_PID,
52 SERVER_CMD,
53 SERVER_ADDR,
54 CLIENT_PIDS,
55 CLIENT_CMDS,
56 ARCH,
57 THREADS,
58};
59
Yifan Hongb0dde932017-02-10 17:49:58 -080060struct TableEntry {
61 std::string interfaceName;
62 std::string transport;
63 int32_t serverPid;
Steven Morelandd8e20192017-05-24 11:23:08 -070064 uint32_t threadUsage;
65 uint32_t threadCount;
Yifan Hongae09a3d2017-02-14 17:33:50 -080066 std::string serverCmdline;
Yifan Hongb0dde932017-02-10 17:49:58 -080067 uint64_t serverObjectAddress;
68 Pids clientPids;
Yifan Hongae09a3d2017-02-14 17:33:50 -080069 std::vector<std::string> clientCmdlines;
Yifan Hongb4479022017-03-02 16:54:11 -080070 Architecture arch;
Yifan Hong38d53e02017-02-13 17:51:59 -080071
72 static bool sortByInterfaceName(const TableEntry &a, const TableEntry &b) {
73 return a.interfaceName < b.interfaceName;
74 };
75 static bool sortByServerPid(const TableEntry &a, const TableEntry &b) {
76 return a.serverPid < b.serverPid;
77 };
Steven Morelandd8e20192017-05-24 11:23:08 -070078
79 std::string getThreadUsage() const {
80 if (threadCount == 0) {
81 return "N/A";
82 }
83
84 return std::to_string(threadUsage) + "/" + std::to_string(threadCount);
85 }
Yifan Hongd4a77e82017-09-06 19:40:24 -070086
87 std::string getField(TableColumnType type) const;
Yifan Hongb0dde932017-02-10 17:49:58 -080088};
89
Yifan Hongd4a77e82017-09-06 19:40:24 -070090using SelectedColumns = std::vector<TableColumnType>;
Yifan Honga3b87092017-03-02 19:19:29 -080091
Yifan Hongd4a77e82017-09-06 19:40:24 -070092class Table {
93public:
94 using Entries = std::vector<TableEntry>;
95
96 Entries::iterator begin() { return mEntries.begin(); }
97 Entries::const_iterator begin() const { return mEntries.begin(); }
98 Entries::iterator end() { return mEntries.end(); }
99 Entries::const_iterator end() const { return mEntries.end(); }
100
101 void add(TableEntry&& entry) { mEntries.push_back(std::move(entry)); }
102
103 void setSelectedColumns(const SelectedColumns& s) { mSelectedColumns = s; }
104 const SelectedColumns& getSelectedColumns() const { return mSelectedColumns; }
105
106 void setDescription(std::string&& d) { mDescription = std::move(d); }
107
108 // Write table content.
109 TextTable createTextTable(bool neat = true,
110 const std::function<std::string(const std::string&)>& emitDebugInfo = nullptr) const;
111
112private:
113 std::string mDescription;
114 Entries mEntries;
115 SelectedColumns mSelectedColumns;
Yifan Honga3b87092017-03-02 19:19:29 -0800116};
117
Yifan Hong38d53e02017-02-13 17:51:59 -0800118using TableEntryCompare = std::function<bool(const TableEntry &, const TableEntry &)>;
119
Yifan Hongd4a77e82017-09-06 19:40:24 -0700120class MergedTable {
121public:
122 MergedTable(std::vector<const Table*>&& tables) : mTables(std::move(tables)) {}
123 TextTable createTextTable();
124private:
125 std::vector<const Table*> mTables;
Yifan Hong38d53e02017-02-13 17:51:59 -0800126};
127
Yifan Hongb0dde932017-02-10 17:49:58 -0800128enum {
129 NO_PID = -1,
130 NO_PTR = 0
131};
132
133} // namespace lshal
134} // namespace android
135
136#endif // FRAMEWORK_NATIVE_CMDS_LSHAL_TABLE_ENTRY_H_