Changeset View
Changeset View
Standalone View
Standalone View
processcore/extended_process_list.cpp
Show All 12 Lines | 1 | /* | |||
---|---|---|---|---|---|
13 | 13 | | |||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | #include "extended_process_list.h" | 19 | #include "extended_process_list.h" | ||
20 | 20 | | |||
21 | #include <KPluginLoader> | 21 | #include <KLocalizedString> | ||
22 | #include <KPluginFactory> | 22 | #include <KPluginFactory> | ||
23 | #include <KPluginLoader> | ||||
23 | #include <KPluginMetaData> | 24 | #include <KPluginMetaData> | ||
25 | #include <KUser> | ||||
24 | 26 | | |||
25 | #include "process_data_provider.h" | 27 | #include "process.h" | ||
26 | #include "process_attribute.h" | 28 | #include "process_attribute.h" | ||
29 | #include "process_data_provider.h" | ||||
27 | #include "processcore_debug.h" | 30 | #include "processcore_debug.h" | ||
28 | 31 | | |||
29 | using namespace KSysGuard; | 32 | using namespace KSysGuard; | ||
30 | 33 | | |||
31 | class Q_DECL_HIDDEN ExtendedProcesses::Private | 34 | class Q_DECL_HIDDEN ExtendedProcesses::Private | ||
32 | { | 35 | { | ||
33 | public: | 36 | public: | ||
34 | Private(ExtendedProcesses *q); | 37 | Private(ExtendedProcesses *q); | ||
35 | void loadPlugins(); | 38 | void loadPlugins(); | ||
36 | 39 | | |||
37 | ExtendedProcesses *q; | 40 | ExtendedProcesses *q; | ||
41 | QVector<ProcessAttribute *> m_coreAttributes; | ||||
38 | QVector<ProcessDataProvider *> m_providers; | 42 | QVector<ProcessDataProvider *> m_providers; | ||
43 | QHash<K_UID, KUser> m_userCache; | ||||
44 | }; | ||||
45 | | ||||
46 | enum GroupPolicy { | ||||
47 | Accumulate, | ||||
48 | Average, | ||||
49 | ForwardFirstEntry | ||||
50 | }; | ||||
51 | | ||||
52 | template <class T> | ||||
53 | class ProcessSensor : public KSysGuard::ProcessAttribute | ||||
54 | { | ||||
55 | public: | ||||
56 | ProcessSensor(ExtendedProcesses *parent, const QString &id, const QString &name, std::function<T(KSysGuard::Process *)> extractFunc, KSysGuard::Process::Change changeFlag = KSysGuard::Process::Nothing, GroupPolicy groupPolicy = Accumulate) | ||||
57 | : KSysGuard::ProcessAttribute(id, name, parent) | ||||
58 | , m_extractFunc(extractFunc) | ||||
59 | , m_changeFlag(changeFlag) | ||||
60 | , m_groupPolicy(groupPolicy) | ||||
61 | { | ||||
62 | if (m_changeFlag != 0) { | ||||
63 | connect(parent, &ExtendedProcesses::processChanged, this, [this](KSysGuard::Process *process) { | ||||
64 | if (!process->changes().testFlag(m_changeFlag)) { | ||||
65 | return; | ||||
66 | } | ||||
67 | emit dataChanged(process); | ||||
68 | }); | ||||
69 | } | ||||
70 | } | ||||
71 | | ||||
72 | QVariant data(KSysGuard::Process *process) const override | ||||
73 | { | ||||
74 | return QVariant::fromValue(m_extractFunc(process)); | ||||
75 | } | ||||
76 | | ||||
77 | private: | ||||
78 | std::function<T(KSysGuard::Process *)> m_extractFunc; | ||||
79 | KSysGuard::Process::Change m_changeFlag; | ||||
80 | GroupPolicy m_groupPolicy = Accumulate; | ||||
39 | }; | 81 | }; | ||
40 | 82 | | |||
41 | ExtendedProcesses::Private::Private(ExtendedProcesses *_q) | 83 | ExtendedProcesses::Private::Private(ExtendedProcesses *_q) | ||
42 | : q(_q) | 84 | : q(_q) | ||
43 | { | 85 | { | ||
44 | } | 86 | } | ||
45 | 87 | | |||
46 | ExtendedProcesses::ExtendedProcesses(QObject *parent) | 88 | ExtendedProcesses::ExtendedProcesses(QObject *parent) | ||
47 | : Processes(QString(), parent) | 89 | : Processes(QString(), parent) | ||
48 | , d(new Private(this)) | 90 | , d(new Private(this)) | ||
49 | { | 91 | { | ||
50 | d->loadPlugins(); | 92 | d->loadPlugins(); | ||
51 | 93 | | |||
94 | auto pidSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("pid"), i18n("PID"), &KSysGuard::Process::pid, KSysGuard::Process::Status, ForwardFirstEntry); | ||||
broulik: Isn't the `typename` auto-deduced/implied? Doesn't hurt though. | |||||
95 | pidSensor->setDescription(i18n("The unique Process ID that identifies this process.")); | ||||
96 | d->m_coreAttributes << pidSensor; | ||||
97 | | ||||
98 | auto parentPidSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("parentPid"), i18n("Parent PID"), &KSysGuard::Process::parentPid, Process::Nothing, ForwardFirstEntry); | ||||
99 | d->m_coreAttributes << parentPidSensor; | ||||
100 | | ||||
broulik: Capture only `[this]` | |||||
101 | auto loginSensor = new ProcessSensor<QString>(this, QStringLiteral("login"), i18n("Login"), &KSysGuard::Process::login, KSysGuard::Process::Login, ForwardFirstEntry); | ||||
102 | loginSensor->setDescription(i18n("The user who owns this process.")); | ||||
103 | d->m_coreAttributes << loginSensor; | ||||
104 | | ||||
105 | auto uidSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("uid"), i18n("UID"), &KSysGuard::Process::uid, KSysGuard::Process::Uids, ForwardFirstEntry); | ||||
106 | d->m_coreAttributes << uidSensor; | ||||
107 | | ||||
108 | auto userNameSensor = new ProcessSensor<QString>( | ||||
109 | this, QStringLiteral("username"), i18n("Username"), [this](KSysGuard::Process *p) { | ||||
110 | const K_UID uid = p->uid(); | ||||
broulik: Does this need caching? | |||||
111 | auto userIt = d->m_userCache.constFind(uid); | ||||
112 | if (userIt == d->m_userCache.constEnd()) { | ||||
113 | userIt = d->m_userCache.insert(uid, KUser(uid)); | ||||
114 | } | ||||
115 | return userIt->loginName(); | ||||
116 | }, | ||||
117 | KSysGuard::Process::Uids, ForwardFirstEntry); | ||||
118 | d->m_coreAttributes << userNameSensor; | ||||
119 | | ||||
120 | auto canUserLoginSensor = new ProcessSensor<bool>( | ||||
121 | this, QStringLiteral("canUserLogin"), i18n("Can Login"), [this](KSysGuard::Process *p) { | ||||
122 | const K_UID uid = p->uid(); | ||||
123 | if (uid == 65534) { // special value meaning nobody | ||||
broulik: Add a comment that this magic number is `nobody` | |||||
124 | return false; | ||||
125 | } | ||||
126 | auto userIt = d->m_userCache.constFind(uid); | ||||
127 | if (userIt == d->m_userCache.constEnd()) { | ||||
128 | userIt = d->m_userCache.insert(uid, KUser(uid)); | ||||
129 | } | ||||
130 | | ||||
131 | if (!userIt->isValid()) { | ||||
132 | // For some reason the user isn't recognised. This might happen under certain security situations. | ||||
133 | // Just return true to be safe | ||||
134 | return true; | ||||
135 | } | ||||
136 | const QString shell = userIt->shell(); | ||||
137 | if (shell == QLatin1String("/bin/false")) { //FIXME - add in any other shells it could be for false | ||||
138 | return false; | ||||
139 | } | ||||
140 | return true; | ||||
141 | }, | ||||
142 | KSysGuard::Process::Uids, ForwardFirstEntry); | ||||
143 | d->m_coreAttributes << canUserLoginSensor; | ||||
144 | | ||||
145 | auto euidSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("euid"), i18n("EUID"), &KSysGuard::Process::euid, KSysGuard::Process::Uids, ForwardFirstEntry); | ||||
146 | d->m_coreAttributes << euidSensor; | ||||
147 | | ||||
148 | auto suidSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("suid"), | ||||
149 | i18n("suid"), &KSysGuard::Process::suid, KSysGuard::Process::Uids, ForwardFirstEntry); | ||||
150 | d->m_coreAttributes << suidSensor; | ||||
151 | | ||||
152 | auto fsuidSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("fsuid"), i18n("fsuid"), &KSysGuard::Process::fsuid, KSysGuard::Process::Uids, ForwardFirstEntry); | ||||
153 | d->m_coreAttributes << fsuidSensor; | ||||
154 | | ||||
155 | auto gidSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("gid"), i18n("gid"), &KSysGuard::Process::gid, KSysGuard::Process::Gids, ForwardFirstEntry); | ||||
156 | d->m_coreAttributes << gidSensor; | ||||
157 | | ||||
158 | auto egidSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("egid"), i18n("egid"), &KSysGuard::Process::egid, KSysGuard::Process::Gids, ForwardFirstEntry); | ||||
159 | d->m_coreAttributes << egidSensor; | ||||
160 | | ||||
161 | auto sgidSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("sgid"), i18n("sgid"), &KSysGuard::Process::sgid, KSysGuard::Process::Gids, ForwardFirstEntry); | ||||
162 | d->m_coreAttributes << sgidSensor; | ||||
163 | | ||||
164 | auto fsgidSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("fsgid"), i18n("fsgid"), &KSysGuard::Process::fsgid, KSysGuard::Process::Gids, ForwardFirstEntry); | ||||
165 | d->m_coreAttributes << fsgidSensor; | ||||
166 | | ||||
167 | auto tracerpidSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("tracerpid"), i18n("Tracer Pid"), &KSysGuard::Process::tracerpid, Process::Nothing, ForwardFirstEntry); | ||||
168 | d->m_coreAttributes << tracerpidSensor; | ||||
169 | | ||||
170 | auto ttySensor = new ProcessSensor<QByteArray>(this, QStringLiteral("tty"), i18n("tty"), &KSysGuard::Process::tty, KSysGuard::Process::Tty, ForwardFirstEntry); | ||||
171 | ttySensor->setDescription(i18n("The controlling terminal on which this process is running.")); | ||||
172 | d->m_coreAttributes << ttySensor; | ||||
173 | | ||||
174 | auto userTimeSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("userTime"), i18n("User Time"), &KSysGuard::Process::userTime); | ||||
175 | d->m_coreAttributes << userTimeSensor; | ||||
176 | | ||||
177 | auto sysTimeSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("sysTime"), i18n("System Time"), &KSysGuard::Process::sysTime); | ||||
178 | sysTimeSensor->setUnit(KSysGuard::UnitSecond); | ||||
179 | d->m_coreAttributes << sysTimeSensor; | ||||
180 | | ||||
181 | auto timeSensor = new ProcessSensor<qlonglong>( | ||||
182 | this, QStringLiteral("totalUsage"), i18n("Total Time"), [](KSysGuard::Process *p) { | ||||
183 | return p->userTime() + p->sysTime(); | ||||
184 | }, | ||||
185 | KSysGuard::Process::Usage); | ||||
186 | timeSensor->setShortName(i18n("Time")); | ||||
187 | timeSensor->setUnit(KSysGuard::UnitSecond); | ||||
188 | timeSensor->setDescription(i18n("The total user and system time that this process has been running for")); | ||||
189 | d->m_coreAttributes << timeSensor; | ||||
190 | | ||||
191 | auto startTimeSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("startTime"), i18n("Start Time"), &KSysGuard::Process::startTime, Process::Nothing, ForwardFirstEntry); //Is this correct for apps? | ||||
192 | startTimeSensor->setDescription(i18n("The elapsed time since the process was started.")); | ||||
193 | startTimeSensor->setUnit(KSysGuard::UnitTime); | ||||
194 | d->m_coreAttributes << startTimeSensor; | ||||
195 | | ||||
196 | auto userUsageSensor = new ProcessSensor<int>(this, QStringLiteral("userUsage"), i18n("User CPU Usage"), &KSysGuard::Process::userUsage, KSysGuard::Process::Usage); | ||||
197 | userUsageSensor->setShortName(i18n("User CPU")); | ||||
198 | userUsageSensor->setMin(0); | ||||
199 | userUsageSensor->setMax(100); | ||||
200 | userUsageSensor->setUnit(KSysGuard::UnitPercent); | ||||
201 | d->m_coreAttributes << userUsageSensor; | ||||
202 | | ||||
203 | auto sysUsageSensor = new ProcessSensor<int>(this, QStringLiteral("sysUsage"), i18n("System CPU Usage"), &KSysGuard::Process::sysUsage, KSysGuard::Process::Usage); | ||||
204 | sysUsageSensor->setShortName(i18n("System CPU")); | ||||
205 | sysUsageSensor->setMin(0); | ||||
206 | sysUsageSensor->setMax(100); | ||||
207 | sysUsageSensor->setUnit(KSysGuard::UnitPercent); | ||||
208 | d->m_coreAttributes << sysUsageSensor; | ||||
209 | | ||||
210 | auto usageSensor = new ProcessSensor<int>( | ||||
211 | this, QStringLiteral("usage"), i18n("Total CPU Usage"), [](KSysGuard::Process *p) { | ||||
212 | return p->userUsage() + p->sysUsage(); | ||||
213 | }, | ||||
214 | KSysGuard::Process::Usage, Accumulate); | ||||
215 | usageSensor->setShortName(i18n("CPU")); | ||||
216 | usageSensor->setMin(0); | ||||
217 | usageSensor->setMax(100); | ||||
218 | usageSensor->setUnit(KSysGuard::UnitPercent); | ||||
219 | usageSensor->setDescription(i18n("The current total CPU usage of the process.")); | ||||
220 | d->m_coreAttributes << usageSensor; | ||||
221 | | ||||
222 | auto totalUserUsageSensor = new ProcessSensor<int>(this, QStringLiteral("totalUserUsage"), i18n("Group User CPU Usage"), &KSysGuard::Process::totalUserUsage, KSysGuard::Process::TotalUsage, Average); | ||||
223 | totalUserUsageSensor->setDescription(i18n("The amount of userspace CPU used by this process and all its children.")); | ||||
224 | totalUserUsageSensor->setMin(0); | ||||
225 | totalUserUsageSensor->setMax(100); | ||||
226 | totalUserUsageSensor->setUnit(KSysGuard::UnitPercent); | ||||
227 | d->m_coreAttributes << totalUserUsageSensor; | ||||
228 | | ||||
229 | auto totalSysUsageSensor = new ProcessSensor<int>(this, QStringLiteral("totalSysUsage"), i18n("Group System CPU Usage"), &KSysGuard::Process::totalSysUsage, KSysGuard::Process::TotalUsage, Average); | ||||
230 | totalUserUsageSensor->setDescription(i18n("The amount of system CPU used by this process and all its children.")); | ||||
231 | totalSysUsageSensor->setMin(0); | ||||
232 | totalSysUsageSensor->setMax(100); | ||||
233 | totalSysUsageSensor->setUnit(KSysGuard::UnitPercent); | ||||
234 | d->m_coreAttributes << totalSysUsageSensor; | ||||
235 | | ||||
236 | auto totalUsageSensor = new ProcessSensor<int>( | ||||
237 | this, QStringLiteral("totalUsage"), i18n("Group Total CPU Usage"), [](KSysGuard::Process *p) { | ||||
238 | return p->totalUserUsage() + p->totalSysUsage(); | ||||
239 | }, | ||||
240 | KSysGuard::Process::TotalUsage, Average); | ||||
241 | totalUsageSensor->setShortName(i18n("Group CPU")); | ||||
242 | totalUserUsageSensor->setDescription(i18n("The total amount of CPU used by this process and all its children.")); | ||||
243 | totalUsageSensor->setMin(0); | ||||
244 | totalUsageSensor->setMax(100); | ||||
245 | totalUsageSensor->setUnit(KSysGuard::UnitPercent); | ||||
246 | d->m_coreAttributes << totalUsageSensor; | ||||
247 | | ||||
248 | auto niceLevelSensor = new ProcessSensor<int>(this, QStringLiteral("niceLevel"), i18n("Nice Level"), &KSysGuard::Process::niceLevel, KSysGuard::Process::NiceLevels); | ||||
249 | niceLevelSensor->setDescription(i18n("The priority with which this process is being run. For the normal scheduler, this ranges from 19 (very nice, least priority) to -19 (top priority).")); | ||||
250 | d->m_coreAttributes << niceLevelSensor; | ||||
251 | | ||||
252 | auto schedulerSensor = new ProcessSensor<uint>(this, QStringLiteral("scheduler"), i18n("Scheduler"), &KSysGuard::Process::scheduler, KSysGuard::Process::NiceLevels); | ||||
253 | d->m_coreAttributes << schedulerSensor; | ||||
254 | | ||||
255 | auto ioPriorityClassSensor = new ProcessSensor<uint>(this, QStringLiteral("ioPriorityClass"), i18n("IO Priority Class"), | ||||
256 | &KSysGuard::Process::ioPriorityClass, KSysGuard::Process::NiceLevels); | ||||
257 | d->m_coreAttributes << ioPriorityClassSensor; | ||||
258 | | ||||
259 | auto ioniceLevelSensor = new ProcessSensor<int>(this, QStringLiteral("ioniceLevel"), i18n("IO Nice Level"), &KSysGuard::Process::ioniceLevel, KSysGuard::Process::NiceLevels); | ||||
260 | ioniceLevelSensor->setUnit(KSysGuard::UnitNone); | ||||
261 | d->m_coreAttributes << ioniceLevelSensor; | ||||
262 | | ||||
263 | auto vmSizeSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("vmSize"), i18n("VM Size"), &KSysGuard::Process::vmSize, KSysGuard::Process::VmSize); | ||||
264 | vmSizeSensor->setUnit(KSysGuard::UnitKiloByte); | ||||
265 | vmSizeSensor->setMin(0); | ||||
266 | vmSizeSensor->setMax(totalPhysicalMemory()); | ||||
267 | vmSizeSensor->setDescription(i18n("This is the amount of virtual memory space that the process is using, included shared libraries, graphics memory, files on disk, and so on. This number is almost meaningless.")); | ||||
268 | d->m_coreAttributes << vmSizeSensor; | ||||
269 | | ||||
270 | auto vmRSSSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("vmRSS"), i18n("RSS Memory Usage"), &KSysGuard::Process::vmRSS, KSysGuard::Process::VmRSS); | ||||
271 | vmRSSSensor->setUnit(KSysGuard::UnitKiloByte); | ||||
272 | vmRSSSensor->setMin(0); | ||||
273 | vmRSSSensor->setMax(totalPhysicalMemory()); | ||||
274 | vmRSSSensor->setDescription(i18n("This is the amount of physical memory that this process is using and includes the amount of memory used by shared libraries.")); | ||||
275 | | ||||
276 | auto vmURSSSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("vmURSS"), i18n("Private Memory Usage"), &KSysGuard::Process::vmURSS, KSysGuard::Process::VmURSS); | ||||
277 | vmURSSSensor->setUnit(KSysGuard::UnitKiloByte); | ||||
278 | vmURSSSensor->setShortName(i18n("Private")); | ||||
279 | vmURSSSensor->setMin(0); | ||||
280 | vmURSSSensor->setMax(totalPhysicalMemory()); | ||||
281 | vmURSSSensor->setDescription(i18n("This is the amount of physical memory that this process is using by itself, and approximates the Private memory usage of the process.<br>It does not include any swapped out memory, nor the code size of its shared libraries.")); | ||||
282 | d->m_coreAttributes << vmURSSSensor; | ||||
283 | | ||||
284 | auto sharedMemorySensor = new ProcessSensor<qlonglong>( | ||||
285 | this, QStringLiteral("vmShared"), i18n("Shared Memory Usage"), [](KSysGuard::Process *p) -> qlonglong { | ||||
286 | if (p->vmRSS() - p->vmURSS() < 0 || p->vmURSS() == -1) { | ||||
287 | return 0; | ||||
288 | } | ||||
289 | return (qlonglong)(p->vmRSS() - p->vmURSS()); | ||||
290 | }, | ||||
291 | KSysGuard::Process::VmRSS); | ||||
292 | d->m_coreAttributes << sharedMemorySensor; | ||||
293 | sharedMemorySensor->setShortName(i18n("Shared")); | ||||
294 | sharedMemorySensor->setDescription(i18n("This is approximately the amount of real physical memory that this process's shared libraries are using.<br>This memory is shared among all processes that use this library.")); | ||||
295 | sharedMemorySensor->setUnit(KSysGuard::UnitKiloByte); | ||||
296 | sharedMemorySensor->setMin(0); | ||||
297 | sharedMemorySensor->setMax(totalPhysicalMemory()); | ||||
298 | | ||||
299 | auto vmPSSSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("vmPSS"), i18n("Memory Usage"), &KSysGuard::Process::vmPSS, KSysGuard::Process::VmPSS); | ||||
300 | vmPSSSensor->setShortName(i18n("Memory")); | ||||
301 | vmPSSSensor->setUnit(KSysGuard::UnitKiloByte); | ||||
302 | vmPSSSensor->setMin(0); | ||||
303 | vmPSSSensor->setMax(totalPhysicalMemory()); | ||||
304 | vmPSSSensor->setDescription(i18n("This is an approximation of the real amount of physical memory that this process is using. It is calculated by dividing the process' shared memory usage by the amount of processes sharing that memory, then adding the process' private memory.")); | ||||
305 | d->m_coreAttributes << vmPSSSensor; | ||||
306 | | ||||
307 | auto nameSensor = new ProcessSensor<QString>(this, QStringLiteral("name"), i18n("Name"), &KSysGuard::Process::name, KSysGuard::Process::Name, ForwardFirstEntry); | ||||
308 | nameSensor->setDescription(i18n("The process name.")); | ||||
309 | d->m_coreAttributes << nameSensor; | ||||
310 | | ||||
311 | auto commandSensor = new ProcessSensor<QString>(this, QStringLiteral("command"), i18n("Command"), &KSysGuard::Process::command, KSysGuard::Process::Command, ForwardFirstEntry); | ||||
312 | commandSensor->setDescription(i18n("The command with which this process was launched.")); | ||||
313 | d->m_coreAttributes << commandSensor; | ||||
314 | | ||||
315 | auto statusSensor = new ProcessSensor<uint>(this, QStringLiteral("status"), i18n("Status"), &KSysGuard::Process::status, KSysGuard::Process::Status); | ||||
316 | d->m_coreAttributes << statusSensor; | ||||
317 | | ||||
318 | auto ioCharactersReadSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("ioCharactersRead"), i18n("IO Characters Read"), &KSysGuard::Process::ioCharactersRead, KSysGuard::Process::IO); | ||||
319 | ioCharactersReadSensor->setUnit(KSysGuard::UnitByte); | ||||
320 | d->m_coreAttributes << ioCharactersReadSensor; | ||||
321 | | ||||
322 | auto ioCharactersWrittenSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("ioCharactersWritten"), i18n("IO Characters Written"), &KSysGuard::Process::ioCharactersWritten, KSysGuard::Process::IO); | ||||
323 | ioCharactersWrittenSensor->setUnit(KSysGuard::UnitByte); | ||||
324 | d->m_coreAttributes << ioCharactersWrittenSensor; | ||||
325 | | ||||
326 | auto ioReadSyscallsSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("ioReadSyscalls"), i18n("IO Read Syscalls"), &KSysGuard::Process::ioReadSyscalls, KSysGuard::Process::IO); | ||||
327 | ioReadSyscallsSensor->setUnit(KSysGuard::UnitRate); | ||||
328 | d->m_coreAttributes << ioReadSyscallsSensor; | ||||
329 | | ||||
330 | auto ioReadSyscallsRateSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("ioReadSyscallsRate"), i18n("IO Read Syscalls Rate"), &KSysGuard::Process::ioReadSyscallsRate, KSysGuard::Process::IO); | ||||
331 | ioReadSyscallsRateSensor->setUnit(KSysGuard::UnitRate); | ||||
332 | d->m_coreAttributes << ioReadSyscallsSensor; | ||||
333 | | ||||
334 | auto ioWriteSyscallsSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("ioWriteSyscalls"), i18n("IO Write Syscalls"), &KSysGuard::Process::ioWriteSyscalls, KSysGuard::Process::IO); | ||||
335 | ioWriteSyscallsSensor->setUnit(KSysGuard::UnitRate); | ||||
336 | d->m_coreAttributes << ioWriteSyscallsSensor; | ||||
337 | | ||||
338 | auto ioWriteSyscallsRateSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("ioReadSyscallsRate"), i18n("IO Write Syscalls Rate"), &KSysGuard::Process::ioWriteSyscallsRate, KSysGuard::Process::IO); | ||||
339 | ioWriteSyscallsRateSensor->setUnit(KSysGuard::UnitRate); | ||||
340 | d->m_coreAttributes << ioWriteSyscallsRateSensor; | ||||
341 | | ||||
342 | auto ioCharactersActuallyReadSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("ioCharactersActuallyRead"), i18n("IO Characters Actually Read"), &KSysGuard::Process::ioCharactersActuallyRead, KSysGuard::Process::IO); | ||||
343 | ioCharactersActuallyReadSensor->setUnit(KSysGuard::UnitByte); | ||||
344 | d->m_coreAttributes << ioCharactersActuallyReadSensor; | ||||
345 | | ||||
346 | auto ioCharactersReadRateSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("ioCharactersReadRate"), i18n("IO Characters Read Rate"), &KSysGuard::Process::ioCharactersReadRate, KSysGuard::Process::IO); | ||||
347 | ioCharactersReadRateSensor->setDescription(i18n("The read rate for all of a process' IO, including disk cache and other non-physical IO.")); | ||||
348 | ioCharactersReadRateSensor->setUnit(KSysGuard::UnitByteRate); | ||||
349 | d->m_coreAttributes << ioCharactersReadRateSensor; | ||||
350 | | ||||
351 | auto ioCharactersWrittenRateSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("ioCharactersWrittenRate"), i18n("IO Characters Written Rate"), &KSysGuard::Process::ioCharactersWrittenRate, KSysGuard::Process::IO); | ||||
352 | ioCharactersWrittenRateSensor->setDescription(i18n("The write rate for all of a process' IO, including disk cache and other nonphysical IO.")); | ||||
353 | ioCharactersWrittenRateSensor->setUnit(KSysGuard::UnitByteRate); | ||||
354 | d->m_coreAttributes << ioCharactersWrittenRateSensor; | ||||
355 | | ||||
broulik: Do any of the sensor names need / used to have i18n context? | |||||
356 | auto ioCharactersActuallyReadRateSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("ioCharactersActuallyReadRate"), i18n("Disk Read Rate"), &KSysGuard::Process::ioCharactersActuallyReadRate, KSysGuard::Process::IO); | ||||
357 | ioCharactersActuallyReadRateSensor->setUnit(KSysGuard::UnitByteRate); | ||||
358 | ioCharactersActuallyReadRateSensor->setShortName(i18n("Read")); | ||||
359 | ioCharactersActuallyReadRateSensor->setDescription(i18n("The rate of data being read from disk.")); | ||||
360 | d->m_coreAttributes << ioCharactersActuallyReadRateSensor; | ||||
361 | | ||||
362 | auto ioCharactersActuallyWrittenRateSensor = new ProcessSensor<qlonglong>(this, QStringLiteral("ioCharactersActuallyWrittenRate"), i18n("Disk Write Rate"), &KSysGuard::Process::ioCharactersActuallyWrittenRate, KSysGuard::Process::IO); | ||||
363 | ioCharactersActuallyWrittenRateSensor->setUnit(KSysGuard::UnitByteRate); | ||||
364 | ioCharactersActuallyWrittenRateSensor->setShortName(i18n("Write")); | ||||
365 | ioCharactersActuallyWrittenRateSensor->setDescription(i18n("The rate of data being written to the disk.")); | ||||
366 | d->m_coreAttributes << ioCharactersActuallyWrittenRateSensor; | ||||
367 | | ||||
368 | auto numThreadsSensor = new ProcessSensor<int>(this, QStringLiteral("numThreads"), i18n("Threads"), &KSysGuard::Process::numThreads, KSysGuard::Process::NumThreads, ForwardFirstEntry); | ||||
369 | d->m_coreAttributes << numThreadsSensor; | ||||
370 | | ||||
52 | connect(this, &KSysGuard::Processes::beginRemoveProcess, this, [this](KSysGuard::Process *process) { | 371 | connect(this, &KSysGuard::Processes::beginRemoveProcess, this, [this](KSysGuard::Process *process) { | ||
53 | const auto attrs = attributes(); | 372 | const auto attrs = attributes(); | ||
54 | for (auto a : attrs) { | 373 | for (auto a : attrs) { | ||
55 | a->clearData(process); | 374 | a->clearData(process); | ||
56 | } | 375 | } | ||
57 | }); | 376 | }); | ||
58 | 377 | | |||
59 | connect(this, &KSysGuard::Processes::updated, this, [this]() { | 378 | connect(this, &KSysGuard::Processes::updated, this, [this]() { | ||
60 | for (auto p : qAsConst(d->m_providers)) { | 379 | for (auto p : qAsConst(d->m_providers)) { | ||
61 | if (p->enabled()) { | 380 | if (p->enabled()) { | ||
62 | p->update(); | 381 | p->update(); | ||
63 | } | 382 | } | ||
64 | } | 383 | } | ||
65 | }); | 384 | }); | ||
66 | } | 385 | } | ||
67 | 386 | | |||
68 | ExtendedProcesses::~ExtendedProcesses() | 387 | ExtendedProcesses::~ExtendedProcesses() | ||
69 | { | 388 | { | ||
70 | } | 389 | } | ||
71 | 390 | | |||
72 | QVector<ProcessAttribute *> ExtendedProcesses::attributes() const | 391 | QVector<ProcessAttribute *> ExtendedProcesses::attributes() const | ||
73 | { | 392 | { | ||
393 | return d->m_coreAttributes + extendedAttributes(); | ||||
394 | } | ||||
395 | | ||||
396 | QVector<ProcessAttribute *> ExtendedProcesses::extendedAttributes() const | ||||
397 | { | ||||
74 | QVector<ProcessAttribute *> rc; | 398 | QVector<ProcessAttribute *> rc; | ||
broulik: This could have used a `reserve` call :) | |||||
not a meaningful one, each provider can add provide many attributes davidedmundson: not a meaningful one, each provider can add provide many attributes | |||||
75 | for (auto p : qAsConst(d->m_providers)) { | 399 | for (auto p : qAsConst(d->m_providers)) { | ||
76 | rc << p->attributes(); | 400 | rc << p->attributes(); | ||
77 | } | 401 | } | ||
78 | return rc; | 402 | return rc; | ||
79 | } | 403 | } | ||
80 | 404 | | |||
81 | void ExtendedProcesses::Private::loadPlugins() | 405 | void ExtendedProcesses::Private::loadPlugins() | ||
82 | { | 406 | { | ||
Show All 17 Lines |
Isn't the typename auto-deduced/implied? Doesn't hurt though.