diff --git a/processcore/formatter.h b/processcore/formatter.h index cbecd87..2262d8e 100644 --- a/processcore/formatter.h +++ b/processcore/formatter.h @@ -1,91 +1,91 @@ /* Copyright (C) 2019 Vlad Zagorodniy This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #pragma once // Own #include "unit.h" // Qt #include #include class KLocalizedString; namespace KSysGuard { /** * This enum type is used to specify format options. */ enum FormatOption { FormatOptionNone = 0, FormatOptionAgo = 1 << 0, FormatOptionShowNull = 1 << 1, }; Q_DECLARE_FLAGS(FormatOptions, FormatOption) class Q_DECL_EXPORT Formatter { public: /** * Returns the scale factor suitable for display. * - * @param value The maximium output value. + * @param value The maximum output value. * @param unit The unit of the value. * @param targetPrefix Preferred metric prefix. */ static qreal scaleDownFactor(const QVariant &value, Unit unit, MetricPrefix targetPrefix = MetricPrefixAutoAdjust); /** * Returns localized string that is suitable for display. * * @param value The maximum output value. * @param unit The unit of the value. * @param targetPrefix Preferred metric prefix. */ static KLocalizedString localizedString(const QVariant &value, Unit unit, MetricPrefix targetPrefix = MetricPrefixAutoAdjust); /** * Converts @p value to the appropriate displayable string. * * The returned string is localized. * * @param value The value to be converted. * @param unit The unit of the value. * @param targetPrefix Preferred metric prefix. * @param options */ static QString formatValue(const QVariant &value, Unit unit, MetricPrefix targetPrefix = MetricPrefixAutoAdjust, FormatOptions options = FormatOptionNone); /** * Returns a symbol that corresponds to the given @p unit. * * The returned unit symbol is localized. */ static QString symbol(Unit unit); }; } // namespace KSysGuard Q_DECLARE_OPERATORS_FOR_FLAGS(KSysGuard::FormatOptions) diff --git a/processcore/process.h b/processcore/process.h index 13cd598..7cc7ad2 100644 --- a/processcore/process.h +++ b/processcore/process.h @@ -1,276 +1,276 @@ /* This file is part of the KDE project Copyright (C) 2007 John Tapsell Copyright (C) 2015 Gregor Mi This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef PROCESS_H #define PROCESS_H #include #include #include #include namespace KSysGuard { class ProcessPrivate; // forward decl d-ptr class Q_DECL_EXPORT Process { public: enum ProcessStatus { Running, Sleeping, DiskSleep, Zombie, Stopped, Paging, Ended, OtherStatus = 99 }; enum IoPriorityClass { None, RealTime, BestEffort, Idle }; enum Scheduler { Other = 0, Fifo, RoundRobin, Batch, SchedulerIdle, Interactive }; ///< Interactive is Solaris only Process(); Process(qlonglong _pid, qlonglong _ppid, Process *_parent); virtual ~Process(); long pid() const; ///< The system's ID for this process. 1 for init. -1 for our virtual 'parent of init' process used just for convenience. long parentPid() const; ///< The system's ID for the parent of this process. Set to -1 if it has no parent (e.g. 'init' on Linux). void setParentPid(long parent_pid); /** A guaranteed NON-NULL pointer for all real processes to the parent process except for the fake process with pid -1. * The Parent's pid is the same value as the parent_pid. The parent process will be also pointed * to by ProcessModel::mPidToProcess to there is no need to worry about mem management in using parent. * For process without a parent (such as 'init' on Linux, parent will point to a (fake) process with pid -1 to simplify things. * For the fake process, this will point to NULL */ Process *parent() const; void setParent(Process *parent); QList & children() const; // REF, make non-ref later! ///< A list of all the direct children that the process has. Children of children are not listed here, so note that children_pids <= numChildren unsigned long& numChildren() const; // REF, make non-ref later! QString login() const; void setLogin(const QString &login); ///< The user login name. Only used for processes on remote machines. Otherwise use uid to get the name qlonglong uid() const; void setUid(qlonglong uid); ///< The user id that the process is running as qlonglong euid() const; void setEuid(qlonglong euid); ///< The effective user id that the process is running as qlonglong suid() const; void setSuid(qlonglong suid); ///< The set user id that the process is running as qlonglong fsuid() const; void setFsuid(qlonglong fsuid); ///< The file system user id that the process is running as. qlonglong gid() const; void setGid(qlonglong gid); ///< The process group id that the process is running as qlonglong egid() const; void setEgid(qlonglong egid); ///< The effective group id that the process is running as qlonglong sgid() const; void setSgid(qlonglong sgid); ///< The set group id that the process is running as qlonglong fsgid() const; void setFsgid(qlonglong fsgid); ///< The file system group id that the process is running as qlonglong tracerpid() const; void setTracerpid(qlonglong tracerpid); ///< If this is being debugged, this is the process that is debugging it, or 0 otherwise QByteArray tty() const; void setTty(const QByteArray &tty); ///< The name of the tty the process owns qlonglong userTime() const; void setUserTime(qlonglong userTime); ///< The time, in 100ths of a second, spent in total on user calls. -1 if not known qlonglong sysTime() const; void setSysTime(qlonglong sysTime); ///< The time, in 100ths of a second, spent in total on system calls. -1 if not known /** * the value is expressed in clock ticks (since Linux 2.6; we only handle this case) since system boot */ qlonglong startTime() const; void setStartTime(qlonglong startTime); /// The time the process started after system boot. Since Linux 2.6, the value is expressed in clock ticks. See man proc. int userUsage() const; void setUserUsage(int userUsage); ///< Percentage (0 to 100). It might be more than 100% on multiple cpu core systems int sysUsage() const; void setSysUsage(int sysUsage); ///< Percentage (0 to 100). It might be more than 100% on multiple cpu core systems int& totalUserUsage() const; // REF, make non-ref later! void setTotalUserUsage(int totalUserUsage); ///< Percentage (0 to 100) from the sum of itself and all its children recursively. If there's no children, it's equal to userUsage. It might be more than 100% on multiple cpu core systems int& totalSysUsage() const; // REF, make non-ref later! void setTotalSysUsage(int totalSysUsage); ///< Percentage (0 to 100) from the sum of itself and all its children recursively. If there's no children, it's equal to sysUsage. It might be more than 100% on multiple cpu core systems int niceLevel() const; void setNiceLevel(int niceLevel); ///< If Scheduler = Other, niceLevel is the niceness (-20 to 20) of this process. A lower number means a higher priority. Otherwise sched priority (1 to 99) Scheduler scheduler() const; void setScheduler(Scheduler scheduler); ///< The scheduler this process is running in. See man sched_getscheduler for more info IoPriorityClass ioPriorityClass() const; void setIoPriorityClass(IoPriorityClass ioPriorityClass); ///< The IO priority class. See man ionice for detailed information. int ioniceLevel() const; void setIoniceLevel(int ioniceLevel); ///< IO Niceness (0 to 7) of this process. A lower number means a higher io priority. -1 if not known or not applicable because ioPriorityClass is Idle or None qlonglong vmSize() const; void setVmSize(qlonglong vmSize); ///< Virtual memory size in KiloBytes, including memory used, mmap'ed files, graphics memory etc, qlonglong vmRSS() const; void setVmRSS(qlonglong vmRSS); ///< Physical memory used by the process and its shared libraries. If the process and libraries are swapped to disk, this could be as low as 0 qlonglong vmURSS() const; void setVmURSS(qlonglong vmURSS); ///< Physical memory used only by the process, and not counting the code for shared libraries. Set to -1 if unknown qlonglong vmPSS() const; void setVmPSS(qlonglong vmPSS); ///< Proportional set size, the amount of private physical memory used by the process + the amount of shared memory used divided over the number of processes using it. QString name() const; void setName(const QString &name); ///< The name (e.g. "ksysguard", "konversation", "init") QString& command() const; // REF, make non-ref later! void setCommand(const QString &command); ///< The command the process was launched with ProcessStatus status() const; void setStatus( ProcessStatus status); ///< Whether the process is running/sleeping/etc qlonglong ioCharactersRead() const; void setIoCharactersRead(qlonglong number); ///< The number of bytes which this task has caused to be read from storage qlonglong ioCharactersWritten() const; void setIoCharactersWritten(qlonglong number); ///< The number of bytes which this task has caused, or shall cause to be written to disk. qlonglong ioReadSyscalls() const; void setIoReadSyscalls(qlonglong number); ///< Number of read I/O operations, i.e. syscalls like read() and pread(). qlonglong ioWriteSyscalls() const; void setIoWriteSyscalls(qlonglong number); ///< Number of write I/O operations, i.e. syscalls like write() and pwrite(). qlonglong ioCharactersActuallyRead() const; void setIoCharactersActuallyRead(qlonglong number); ///< Number of bytes which this process really did cause to be fetched from the storage layer. qlonglong ioCharactersActuallyWritten() const; void setIoCharactersActuallyWritten(qlonglong number); ///< Attempt to count the number of bytes which this process caused to be sent to the storage layer. long ioCharactersReadRate() const; void setIoCharactersReadRate(long number); ///< The rate, in bytes per second, which this task has caused to be read from storage long ioCharactersWrittenRate() const; void setIoCharactersWrittenRate(long number); ///< The rate, in bytes per second, which this task has caused, or shall cause to be written to disk. long ioReadSyscallsRate() const; void setIoReadSyscallsRate(long number); ///< Number of read I/O operations per second, i.e. syscalls like read() and pread(). long ioWriteSyscallsRate() const; void setIoWriteSyscallsRate(long number); ///< Number of write I/O operations per second, i.e. syscalls like write() and pwrite(). long ioCharactersActuallyReadRate() const; void setIoCharactersActuallyReadRate(long number); ///< Number of bytes per second which this process really did cause to be fetched from the storage layer. long ioCharactersActuallyWrittenRate() const; void setIoCharactersActuallyWrittenRate(long number); ///< Attempt to count the number of bytes per second which this process caused to be sent to the storage layer. int numThreads() const; ///< Number of threads that this process has, including the main one. 0 if not known void setNumThreads(int number); ///< The number of threads that this process has, including this process. int noNewPrivileges() const; void setNoNewPrivileges(int number); ///< Linux process flag NoNewPrivileges int index() const; ///< Each process has a parent process. Each sibling has a unique number to identify it under that parent. This is that number. void setIndex(int index); qlonglong& vmSizeChange() const; // REF, make non-ref later! ///< The change in vmSize since last update, in KiB qlonglong& vmRSSChange() const; // REF, make non-ref later! ///< The change in vmRSS since last update, in KiB qlonglong& vmURSSChange() const; // REF, make non-ref later! ///< The change in vmURSS since last update, in KiB qlonglong vmPSSChange() const; ///< The change in vmPSS since last update, in KiB. unsigned long& pixmapBytes() const; // REF, make non-ref later! ///< The number of bytes used for pixmaps/images and not counted by vmRSS or vmURSS bool& hasManagedGuiWindow() const; // REF, make non-ref later! QElapsedTimer timeKillWasSent() const; ///< This is usually a NULL time. When trying to kill a process, this is the time that the kill signal was sent to the process. QString translatedStatus() const; ///< Returns a translated string of the status. e.g. "Running" etc QString niceLevelAsString() const; ///< Returns a simple translated string of the nice priority. e.g. "Normal", "High", etc QString ioniceLevelAsString() const; ///< Returns a simple translated string of the io nice priority. e.g. "Normal", "High", etc QString ioPriorityClassAsString() const; ///< Returns a translated string of the io nice class. i.e. "None", "Real Time", "Best Effort", "Idle" QString schedulerAsString() const; ///< Returns a translated string of the scheduler class. e.g. "FIFO", "Round Robin", "Batch" QString cGroup() const; void setCGroup(const QString &cGroup); ///< Linux Control Group (cgroup) QString macContext() const; void setMACContext(const QString &macContext); ///< Mandatory Access Control (SELinux or AppArmor) Context /** This is the number of 1/1000ths of a second since this * particular process was last updated compared to when all the processes * were updated. The purpose is to allow a more fine tracking of the time * a process has been running for. * * This is updated in processes.cpp and so shouldn't be touched by the - * OS dependant classes. + * OS dependent classes. */ int elapsedTimeMilliSeconds() const; void setElapsedTimeMilliSeconds(int value); /** An enum to keep track of what changed since the last update. Note that we * the maximum we can use is 0x4000, so some of the enums represent multiple variables */ enum Change { Nothing = 0x0, Uids = 0x1, Gids = 0x2, Tracerpid = 0x4, Tty = 0x8, Usage = 0x10, TotalUsage = 0x20, NiceLevels = 0x40, VmSize = 0x80, VmRSS = 0x100, VmURSS = 0x200, Name = 0x400, Command = 0x800, Status = 0x1000, Login = 0x2000, IO = 0x4000, NumThreads = 0x8000, VmPSS = 0x10000, }; Q_DECLARE_FLAGS(Changes, Change) Changes changes() const; /**< A QFlags representing what has changed */ void setChanges(Change changes); private: void clear(); private: ProcessPrivate* const d; }; Q_DECLARE_OPERATORS_FOR_FLAGS(Process::Changes) } #endif diff --git a/processcore/process_data_provider.h b/processcore/process_data_provider.h index fea2ab9..6459bcc 100644 --- a/processcore/process_data_provider.h +++ b/processcore/process_data_provider.h @@ -1,98 +1,98 @@ /* Copyright (c) 2019 David Edmundson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #pragma once #include #include #include namespace KSysGuard { class Processes; class Process; class ProcessAttribute; /** * Base class for a process plugin data * Plugins provide a list of additional attributes, which in turn have data about a given process */ class Q_DECL_EXPORT ProcessDataProvider : public QObject { Q_OBJECT public: ProcessDataProvider(QObject *parent, const QVariantList &args); ~ProcessDataProvider() override; /** * Accessors for process information matching */ KSysGuard::Processes *processes() const; /** * Returns a new process object for a given PID * This will update the process list if this PID does not exist yet * This may return a null pointer */ KSysGuard::Process *getProcess(long pid); /** * A list of all process attributes provided by this plugin * It is expected to remain constant through the lifespan of this class */ QVector attributes() const; /** * Called when processes should be updated if manually polled * Plugins can however update at any time if enabled */ virtual void update() { } /** * True when at least one attribute from this plugin is subscribed */ bool enabled() const; virtual void handleEnabledChanged(bool enabled) { Q_UNUSED(enabled) } // for any future compatibility virtual void virtual_hook(int id, void *data) { Q_UNUSED(id) Q_UNUSED(data) } protected: /** * Register a new process attribute - * Process attributes should be created in the plugin constuctor and must live for the duration the plugin + * Process attributes should be created in the plugin constructor and must live for the duration the plugin */ void addProcessAttribute(ProcessAttribute *attribute); private: class Private; QScopedPointer d; }; }