add more spacing
[personal-kdebase.git] / workspace / libs / ksysguard / processcore / process.cpp
blob673e0b24c7dfb15b25b95d2289d760bc7c2b76ec
1 /* This file is part of the KDE project
3 Copyright (C) 2007 John Tapsell <tapsell@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 #include "process.h"
25 KSysGuard::Process::Process() {
26 clear();
28 KSysGuard::Process::Process(long long _pid, long long _ppid, Process *_parent) {
29 clear();
30 pid = _pid;
31 parent_pid = _ppid;
32 parent = _parent;
35 QString KSysGuard::Process::niceLevelAsString() const {
36 // Just some rough heuristic to map a number to how nice it is
37 if( niceLevel == 0) return i18nc("Process Niceness", "Normal");
38 if( niceLevel >= 10) return i18nc("Process Niceness", "Very low priority");
39 if( niceLevel > 0) return i18nc("Process Niceness", "Low priority");
40 if( niceLevel <= -10) return i18nc("Process Niceness", "Very high priority");
41 if( niceLevel < 0) return i18nc("Process Niceness", "High priority");
42 return QString(); //impossible;
45 QString KSysGuard::Process::ioniceLevelAsString() const {
46 // Just some rough heuristic to map a number to how nice it is
47 if( ioniceLevel == 4) return i18nc("Process Niceness", "Normal");
48 if( ioniceLevel >= 6) return i18nc("Process Niceness", "Very low priority");
49 if( ioniceLevel > 4) return i18nc("Process Niceness", "Low priority");
50 if( ioniceLevel <= 2) return i18nc("Process Niceness", "Very high priority");
51 if( ioniceLevel < 4) return i18nc("Process Niceness", "High priority");
52 return QString(); //impossible;
56 QString KSysGuard::Process::ioPriorityClassAsString() const {
57 switch( ioPriorityClass ) {
58 case None: return i18nc("Priority Class", "None");
59 case RealTime: return i18nc("Priority Class", "Real Time");
60 case BestEffort: return i18nc("Priority Class", "Best Effort");
61 case Idle: return i18nc("Priority Class", "Idle");
62 default: return i18nc("Priority Class", "Unknown");
66 QString KSysGuard::Process::translatedStatus() const {
67 switch( status ) {
68 case Running: return i18nc("process status", "running");
69 case Sleeping: return i18nc("process status", "sleeping");
70 case DiskSleep: return i18nc("process status", "disk sleep");
71 case Zombie: return i18nc("process status", "zombie");
72 case Stopped: return i18nc("process status", "stopped");
73 case Paging: return i18nc("process status", "paging");
74 default: return i18nc("process status", "unknown");
78 QString KSysGuard::Process::schedulerAsString() const {
79 switch( scheduler ) {
80 case Fifo: return i18nc("Scheduler", "FIFO");
81 case RoundRobin: return i18nc("Scheduler", "Round Robin");
82 case Batch: return i18nc("Scheduler", "Batch");
83 default: return QString();
87 void KSysGuard::Process::clear() {
88 pid = 0;
89 parent_pid = 0;
90 uid = 0;
91 gid = -1;
92 suid = euid = fsuid = -1;
93 sgid = egid = fsgid = -1;
94 tracerpid = 0;
95 userTime = -1;
96 sysTime = -1;
97 userUsage=0;
98 sysUsage=0;
99 totalUserUsage=0;
100 totalSysUsage=0;
101 numChildren=0;
102 niceLevel=0;
103 vmSize=0;
104 vmRSS = 0;
105 vmURSS = 0;
106 status=OtherStatus;
107 parent = NULL;
108 ioPriorityClass = None;
109 ioniceLevel = -1;
110 scheduler = Other;
111 changes = Process::Nothing;
113 void KSysGuard::Process::setLogin(QString _login) {
114 if(login == _login) return;
115 login = _login;
116 changes |= Process::Login;
118 void KSysGuard::Process::setUid(long long _uid) {
119 if(uid == _uid) return;
120 uid = _uid;
121 changes |= Process::Uids;
123 void KSysGuard::Process::setEuid(long long _euid) {
124 if(euid == _euid) return;
125 euid = _euid;
126 changes |= Process::Uids;
128 void KSysGuard::Process::setSuid(long long _suid) {
129 if(suid == _suid) return;
130 suid = _suid;
131 changes |= Process::Uids;
133 void KSysGuard::Process::setFsuid(long long _fsuid) {
134 if(fsuid == _fsuid) return;
135 fsuid = _fsuid;
136 changes |= Process::Uids;
139 void KSysGuard::Process::setGid(long long _gid) {
140 if(gid == _gid) return;
141 gid = _gid;
142 changes |= Process::Gids;
144 void KSysGuard::Process::setEgid(long long _egid) {
145 if(egid == _egid) return;
146 egid = _egid;
147 changes |= Process::Gids;
149 void KSysGuard::Process::setSgid(long long _sgid) {
150 if(sgid == _sgid) return;
151 sgid = _sgid;
152 changes |= Process::Gids;
154 void KSysGuard::Process::setFsgid(long long _fsgid) {
155 if(fsgid == _fsgid) return;
156 fsgid = _fsgid;
157 changes |= Process::Gids;
160 void KSysGuard::Process::setTracerpid(long long _tracerpid) {
161 if(tracerpid == _tracerpid) return;
162 tracerpid = _tracerpid;
163 changes |= Process::Tracerpid;
165 void KSysGuard::Process::setTty(QByteArray _tty) {
166 if(tty == _tty) return;
167 tty = _tty;
168 changes |= Process::Tty;
170 void KSysGuard::Process::setUserTime(long long _userTime) {
171 userTime = _userTime;
173 void KSysGuard::Process::setSysTime(long long _sysTime) {
174 sysTime = _sysTime;
176 void KSysGuard::Process::setUserUsage(int _userUsage) {
177 if(userUsage == _userUsage) return;
178 userUsage = _userUsage;
179 changes |= Process::Usage;
181 void KSysGuard::Process::setSysUsage(int _sysUsage) {
182 if(sysUsage == _sysUsage) return;
183 sysUsage = _sysUsage;
184 changes |= Process::Usage;
186 void KSysGuard::Process::setTotalUserUsage(int _totalUserUsage) {
187 if(totalUserUsage == _totalUserUsage) return;
188 totalUserUsage = _totalUserUsage;
189 changes |= Process::TotalUsage;
191 void KSysGuard::Process::setTotalSysUsage(int _totalSysUsage) {
192 if(totalSysUsage == _totalSysUsage) return;
193 totalSysUsage = _totalSysUsage;
194 changes |= Process::TotalUsage;
196 void KSysGuard::Process::setNiceLevel(int _niceLevel) {
197 if(niceLevel == _niceLevel) return;
198 niceLevel = _niceLevel;
199 changes |= Process::NiceLevels;
201 void KSysGuard::Process::setscheduler(Scheduler _scheduler) {
202 if(scheduler == _scheduler) return;
203 scheduler = _scheduler;
204 changes |= Process::NiceLevels;
206 void KSysGuard::Process::setIoPriorityClass(IoPriorityClass _ioPriorityClass) {
207 if(ioPriorityClass == _ioPriorityClass) return;
208 ioPriorityClass = _ioPriorityClass;
209 changes |= Process::NiceLevels;
211 void KSysGuard::Process::setIoniceLevel(int _ioniceLevel) {
212 if(ioniceLevel == _ioniceLevel) return;
213 ioniceLevel = _ioniceLevel;
214 changes |= Process::NiceLevels;
216 void KSysGuard::Process::setVmSize(long _vmSize) {
217 if(vmSize == _vmSize) return;
218 vmSize = _vmSize;
219 changes |= Process::VmSize;
221 void KSysGuard::Process::setVmRSS(long _vmRSS) {
222 if(vmRSS == _vmRSS) return;
223 vmRSS = _vmRSS;
224 changes |= Process::VmRSS;
226 void KSysGuard::Process::setVmURSS(long _vmURSS) {
227 if(vmURSS == _vmURSS) return;
228 vmURSS = _vmURSS;
229 changes |= Process::VmURSS;
231 void KSysGuard::Process::setName(QString _name) {
232 if(name == _name) return;
233 name = _name;
234 changes |= Process::Name;
236 void KSysGuard::Process::setCommand(QString _command) {
237 if(command == _command) return;
238 command = _command;
239 changes |= Process::Command;
241 void KSysGuard::Process::setStatus(ProcessStatus _status) {
242 if(status == _status) return;
243 status = _status;
244 changes |= Process::Status;