libs: remove unused ksysguard history feature

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-10-17 02:35:07 +03:00
parent 1a27d46115
commit 4a7c54a13b
8 changed files with 9 additions and 647 deletions

View file

@ -10,13 +10,6 @@ include(KDE4Defaults)
set(LIBRARY_TYPE SHARED)
find_package(ZLIB)
set_package_properties(ZLIB PROPERTIES
DESCRIPTION "Support for gzip compressed files and data streams"
URL "http://www.zlib.net"
TYPE REQUIRED
)
find_package(PNG)
set_package_properties(PNG PROPERTIES
DESCRIPTION "An Open, Extensible Image Format with Lossless Compression"

View file

@ -7,15 +7,10 @@ set(ksysguard_LIB_SRCS
processes_local_p.cpp
processes_remote_p.cpp
processes_base_p.cpp
processes_atop_p.cpp
)
add_library(processcore SHARED ${ksysguard_LIB_SRCS})
target_link_libraries(processcore PRIVATE
${KDE4_KDECORE_LIBS}
${ZLIB_LIBRARIES}
)
target_link_libraries(processcore PUBLIC
${KDE4_KDECORE_LIBS}
)

View file

@ -23,7 +23,6 @@
#include "processes_base_p.h"
#include "processes_local_p.h"
#include "processes_remote_p.h"
#include "processes_atop_p.h"
#include "process.h"
#include <klocale.h>
@ -50,13 +49,11 @@ namespace KSysGuard
Private(Processes *q_ptr) {
mFakeProcess.parent = &mFakeProcess;
mAbstractProcesses = 0;
mHistoricProcesses = 0;
mIsLocalHost = true;
mProcesses.insert(-1, &mFakeProcess);
mElapsedTimeMilliSeconds = 0;
mHavePreviousIoValues = false;
mUpdateFlags = 0;
mUsingHistoricalData = false;
q = q_ptr;
}
~Private();
@ -71,7 +68,6 @@ namespace KSysGuard
Process mFakeProcess; ///< A fake process with pid -1 just so that even init points to a parent
AbstractProcesses *mAbstractProcesses; ///< The OS specific code to get the process information
ProcessesATop *mHistoricProcesses; ///< A way to get historic information about processes
bool mIsLocalHost; ///< Whether this is localhost or not
QTime mLastUpdated; ///< This is the time we last updated. Used to calculate cpu usage.
@ -79,7 +75,6 @@ namespace KSysGuard
Processes::UpdateFlags mUpdateFlags;
bool mHavePreviousIoValues; ///< This is whether we updated the IO value on the last update
bool mUsingHistoricalData; ///< Whether to return historical data for updateProcess() etc
Processes *q;
};
@ -188,15 +183,11 @@ bool Processes::updateProcessInfo(Process *ps) {
}
ps->changes = Process::Nothing;
bool success;
if(d->mUsingHistoricalData)
success = d->mHistoricProcesses->updateProcessInfo(ps->pid, ps);
else
success = d->mAbstractProcesses->updateProcessInfo(ps->pid, ps);
bool success = d->mAbstractProcesses->updateProcessInfo(ps->pid, ps);
#ifndef Q_OS_NETBSD
//Now we have the process info. Calculate the cpu usage and total cpu usage for itself and all its parents
if(!d->mUsingHistoricalData && d->mElapsedTimeMilliSeconds != 0) { //Update the user usage and sys usage
if(d->mElapsedTimeMilliSeconds != 0) { //Update the user usage and sys usage
/* The elapsed time is the d->mElapsedTimeMilliSeconds
* (which is of the order 2 seconds or so) plus a small
* correction where we get the amount of time elapsed since
@ -230,7 +221,7 @@ bool Processes::updateProcessInfo(Process *ps) {
}
}
#endif // !Q_OS_NETBSD
if(d->mUsingHistoricalData || d->mElapsedTimeMilliSeconds != 0) {
if(d->mElapsedTimeMilliSeconds != 0) {
ps->setTotalUserUsage(ps->userUsage);
ps->setTotalSysUsage(ps->sysUsage);
if(ps->userUsage != 0 || ps->sysUsage != 0) {
@ -283,11 +274,7 @@ bool Processes::addProcess(long pid, long ppid)
}
bool Processes::updateOrAddProcess( long pid)
{
long ppid;
if(d->mUsingHistoricalData)
ppid = d->mHistoricProcesses->getParentPid(pid);
else
ppid = d->mAbstractProcesses->getParentPid(pid);
long ppid = d->mAbstractProcesses->getParentPid(pid);
if (ppid == pid) //Shouldn't ever happen
ppid = -1;
@ -310,12 +297,10 @@ void Processes::updateAllProcesses(long updateDurationMS, Processes::UpdateFlags
{
d->mUpdateFlags = updateFlags;
if(d->mUsingHistoricalData || d->mLastUpdated.elapsed() >= updateDurationMS || !d->mLastUpdated.isValid()) {
if(d->mLastUpdated.elapsed() >= updateDurationMS || !d->mLastUpdated.isValid()) {
d->mElapsedTimeMilliSeconds = d->mLastUpdated.restart();
if(d->mUsingHistoricalData)
d->mHistoricProcesses->updateAllProcesses(d->mUpdateFlags);
else
d->mAbstractProcesses->updateAllProcesses(d->mUpdateFlags); //For a local machine, this will directly call Processes::processesUpdated()
//For a local machine, this will directly call Processes::processesUpdated()
d->mAbstractProcesses->updateAllProcesses(d->mUpdateFlags);
}
}
@ -330,11 +315,7 @@ void Processes::processesUpdated() {
}
}
if(d->mUsingHistoricalData)
d->mToBeProcessed = d->mHistoricProcesses->getAllPids();
else
d->mToBeProcessed = d->mAbstractProcesses->getAllPids();
d->mToBeProcessed = d->mAbstractProcesses->getAllPids();
QSet<long> beingProcessed(d->mToBeProcessed); //keep a copy so that we can replace mProcessedLastTime with this at the end of this function
@ -415,28 +396,16 @@ bool Processes::killProcess(long pid) {
bool Processes::sendSignal(long pid, int sig) {
d->mAbstractProcesses->errorCode = Unknown;
if(d->mUsingHistoricalData) {
d->mAbstractProcesses->errorCode = NotSupported;
return false;
}
return d->mAbstractProcesses->sendSignal(pid, sig);
}
bool Processes::setNiceness(long pid, int priority) {
d->mAbstractProcesses->errorCode = Unknown;
if(d->mUsingHistoricalData) {
d->mAbstractProcesses->errorCode = NotSupported;
return false;
}
return d->mAbstractProcesses->setNiceness(pid, priority);
}
bool Processes::setScheduler(long pid, KSysGuard::Process::Scheduler priorityClass, int priority) {
d->mAbstractProcesses->errorCode = Unknown;
if(d->mUsingHistoricalData) {
d->mAbstractProcesses->errorCode = NotSupported;
return false;
}
return d->mAbstractProcesses->setScheduler(pid, priorityClass, priority);
}
@ -454,79 +423,6 @@ void Processes::answerReceived( int id, const QList<QByteArray>& answer ) {
processes->answerReceived(id, answer);
}
QList< QPair<QDateTime,uint> > Processes::historiesAvailable() const
{
if(!d->mIsLocalHost)
return QList< QPair<QDateTime,uint> >();
if(!d->mHistoricProcesses)
d->mHistoricProcesses = new ProcessesATop();
return d->mHistoricProcesses->historiesAvailable();
}
void Processes::useCurrentData()
{
if(d->mUsingHistoricalData) {
delete d->mHistoricProcesses;
d->mHistoricProcesses = NULL;
connect( d->mAbstractProcesses, SIGNAL(processesUpdated()), SLOT(processesUpdated()));
d->mUsingHistoricalData = false;
}
}
bool Processes::setViewingTime(const QDateTime &when)
{
d->mAbstractProcesses->errorCode = Unknown;
if(!d->mIsLocalHost) {
d->mAbstractProcesses->errorCode = NotSupported;
return false;
}
if(!d->mUsingHistoricalData) {
if(!d->mHistoricProcesses)
d->mHistoricProcesses = new ProcessesATop();
disconnect( d->mAbstractProcesses, SIGNAL(processesUpdated()), this, SLOT(processesUpdated()));
connect( d->mHistoricProcesses, SIGNAL(processesUpdated()), SLOT(processesUpdated()));
d->mUsingHistoricalData = true;
}
return d->mHistoricProcesses->setViewingTime(when);
}
bool Processes::loadHistoryFile(const QString &filename)
{
d->mAbstractProcesses->errorCode = Unknown;
if(!d->mIsLocalHost) {
d->mAbstractProcesses->errorCode = NotSupported;
return false;
}
if(!d->mHistoricProcesses)
d->mHistoricProcesses = new ProcessesATop(false);
return d->mHistoricProcesses->loadHistoryFile(filename);
}
QString Processes::historyFileName() const
{
if(!d->mIsLocalHost || !d->mHistoricProcesses)
return QString();
return d->mHistoricProcesses->historyFileName();
}
QDateTime Processes::viewingTime() const
{
if(!d->mIsLocalHost || !d->mHistoricProcesses)
return QDateTime();
return d->mHistoricProcesses->viewingTime();
}
bool Processes::isHistoryAvailable() const
{
if(!d->mIsLocalHost)
return false;
if(!d->mHistoricProcesses)
d->mHistoricProcesses = new ProcessesATop();
return d->mHistoricProcesses->isHistoryAvailable();
}
}
#include "moc_processes.cpp"

View file

@ -168,23 +168,6 @@ namespace KSysGuard
/** Update/add process for given pid immediately */
bool updateOrAddProcess( long pid);
/** Whether we can get historic process and system data */
bool isHistoryAvailable() const;
/** Stop using historical data and use the most recent up-to-date data */
void useCurrentData();
/** Return a list of end times and intervals for all the available history */
QList< QPair<QDateTime, uint> > historiesAvailable() const;
/** Use historical process data closest to the given date-time.
* Returns false if it is outside the range available or there is a problem
* getting the data. */
bool setViewingTime(const QDateTime &when);
QDateTime viewingTime() const;
bool loadHistoryFile(const QString &filename);
QString historyFileName() const;
public Q_SLOTS:
/** The abstract processes has updated its list of processes */
void processesUpdated();

View file

@ -1,361 +0,0 @@
/* This file is part of the KDE project
Copyright (C) 2007 John Tapsell <tapsell@kde.org>
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.
*/
#include "processes_atop_p.h"
#include "process.h"
#include "atop_p.h"
#include <klocale.h>
#include <zlib.h>
#include <QFile>
#include <QHash>
#include <QSet>
#include <QByteArray>
#include <QTextStream>
#include <QtCore/qendian.h>
#include <QDebug>
namespace KSysGuard
{
class ProcessesATop::Private
{
public:
Private();
~Private();
QFile atopLog;
bool ready;
bool loadDataForHistory(int index);
bool loadHistoryFile(const QString &filename);
RawHeader rh;
RawRecord rr;
// SStat sstats;
PStat *pstats;
QList<long> pids; //This is a list of process pid's, in the exact same order as pstats
QString lastError;
QList<long> historyOffsets; //< The file offset where each history is stored
QList< QPair<QDateTime, uint> > historyTimes; //< The end time for each history record and its interval, probably in order from oldest to newest
int currentlySelectedIndex;
};
ProcessesATop::Private::Private() :
ready(false),
pstats(NULL),
currentlySelectedIndex(-1)
{
}
ProcessesATop::Private::~Private()
{
}
QString ProcessesATop::historyFileName() const {
return d->atopLog.fileName();
}
bool ProcessesATop::loadHistoryFile(const QString &filename)
{
return d->loadHistoryFile(filename);
}
bool ProcessesATop::Private::loadHistoryFile(const QString &filename) {
atopLog.setFileName(filename);
ready = false;
currentlySelectedIndex = -1;
if(!atopLog.exists()) {
lastError = "File " + filename + " does not exist";
return false;
}
if(!atopLog.open(QIODevice::ReadOnly)) {
lastError = "Could not open file" + filename;
return false;
}
int sizeRead = atopLog.read((char*)(&rh), sizeof(RawHeader));
if(sizeRead != sizeof(RawHeader)) {
lastError = "Could not read header from file" + filename;
return false;
}
if(rh.magic != ATOPLOGMAGIC) {
lastError = "File " + filename + " does not contain raw atop/atopsar output (wrong magic number)";
return false;
}
if (/*rh.sstatlen != sizeof(SStat) ||*/
rh.pstatlen != sizeof(PStat) ||
rh.rawheadlen != sizeof(RawHeader) ||
rh.rawreclen != sizeof(RawRecord) )
{
lastError = "File " + filename + " has incompatible format";
if (rh.aversion & 0x8000) {
lastError = QString("(created by version %1.%2. This program understands the format written by version 1.23")
.arg((rh.aversion >> 8) & 0x7f, rh.aversion & 0xff);
}
return false;
}
/* Read the first data header */
int offset = atopLog.pos();
historyTimes.clear();
historyOffsets.clear();
while( !atopLog.atEnd() && atopLog.read((char*)(&rr), sizeof(RawRecord)) == sizeof(RawRecord) ) {
historyOffsets << offset;
historyTimes << QPair<QDateTime,uint>(QDateTime::fromTime_t(rr.curtime), rr.interval);
offset += sizeof(RawRecord) + rr.scomplen + rr.pcomplen;
atopLog.seek(offset);
}
if(currentlySelectedIndex >= historyOffsets.size())
currentlySelectedIndex = historyOffsets.size() - 1;
ready = true;
return true;
}
bool ProcessesATop::Private::loadDataForHistory(int index)
{
delete [] pstats;
pstats = NULL;
atopLog.seek(historyOffsets.at(index));
/*Read the first data header */
if( atopLog.read((char*)(&rr), sizeof(RawRecord)) != sizeof(RawRecord) ) {
lastError = "Could not read data header";
return false;
}
if( historyTimes.at(index).first != QDateTime::fromTime_t(rr.curtime) ||
historyTimes.at(index).second != rr.interval) {
lastError = "INTERNAL ERROR WITH loadDataForHistory";
ready = false;
return false;
}
atopLog.seek(atopLog.pos() + rr.scomplen);
QByteArray processRecord;
processRecord.resize(rr.pcomplen);
// qToBigEndian( rr.pcomplen, (uchar*)processRecord.data() );
unsigned int dataRead = 0;
do {
int ret = atopLog.read( processRecord.data() + dataRead, rr.pcomplen - dataRead);
if(ret == -1) {
lastError = "Stream interrupted while being read";
return false;
}
dataRead += ret;
} while(dataRead < rr.pcomplen);
Q_ASSERT(dataRead == rr.pcomplen);
//Q_ASSERT( (index + 1 ==historyTimes.count()) || atopLog.pos() == historyTimes.at(index+1));
pstats = new PStat[ rr.nlist ];
unsigned long uncompressedLength= sizeof(struct PStat) * rr.nlist;
int ret = uncompress((Byte *)pstats, &uncompressedLength, (Byte *)processRecord.constData(), rr.pcomplen);
if(ret != Z_OK && ret != Z_STREAM_END && ret != Z_NEED_DICT) {
switch(ret) {
case Z_MEM_ERROR:
lastError = "Could not uncompress record data due to lack of memory";
break;
case Z_BUF_ERROR:
lastError = "Could not uncompress record data due to lack of room in buffer";
break;
case Z_DATA_ERROR:
lastError = "Could not uncompress record data due to corrupted data";
break;
default:
lastError = "Could not uncompress record data due to unexpected error: " + QString::number(ret);
break;
}
delete [] pstats;
pstats = NULL;
return false;
}
pids.clear();
for(uint i = 0; i < rr.nlist; i++) {
pids << pstats[i].gen.pid;
}
return true;
}
ProcessesATop::ProcessesATop(bool loadDefaultFile) : d(new Private())
{
if(loadDefaultFile)
loadHistoryFile("/var/log/atop.log");
}
bool ProcessesATop::isHistoryAvailable() const
{
return d->ready;
}
long ProcessesATop::getParentPid(long pid) {
int index = d->pids.indexOf(pid);
if(index < 0)
return 0;
return d->pstats[index].gen.ppid;
}
bool ProcessesATop::updateProcessInfo( long pid, Process *process)
{
int index = d->pids.indexOf(pid);
if(index < 0)
return false;
PStat &p = d->pstats[index];
process->parent_pid = p.gen.ppid;
process->setUid(p.gen.ruid);
process->setEuid(p.gen.ruid);
process->setSuid(p.gen.ruid);
process->setFsuid(p.gen.ruid);
process->setGid(p.gen.rgid);
process->setEgid(p.gen.rgid);
process->setSgid(p.gen.rgid);
process->setFsgid(p.gen.rgid);
process->setTracerpid(-1);
process->setNumThreads(p.gen.nthr);
// process->setTty
process->setUserTime(p.cpu.utime * 100/d->rh.hertz);//check - divide by interval maybe?
process->setSysTime(p.cpu.stime * 100/d->rh.hertz); //check
process->setUserUsage( process->userTime / d->rr.interval );
process->setSysUsage( process->sysTime / d->rr.interval );
process->setNiceLevel(p.cpu.nice);
// process->setscheduler(p.cpu.policy);
process->setVmSize(p.mem.vmem);
process->setVmRSS(p.mem.rmem);
process->vmSizeChange = p.mem.vgrow;
process->vmRSSChange = p.mem.rgrow;
process->setVmURSS(0);
process->vmURSSChange = 0;
/* Fill in name and command */
QString name = QString::fromUtf8(p.gen.name, qstrnlen(p.gen.name,PNAMLEN));
QString command = QString::fromUtf8(p.gen.cmdline, qstrnlen(p.gen.cmdline,CMDLEN));
//cmdline separates parameters with the NULL character
if(!command.isEmpty()) {
if(command.startsWith(name)) {
int index = command.indexOf(QChar('\0'));
name = command.left(index);
}
command.replace('\0', ' ');
}
process->setName(name);
process->setCommand(command);
/* Fill in state */
switch(p.gen.state) {
case 'E':
process->setStatus(Process::Ended);
break;
case 'R':
process->setStatus(Process::Running);
break;
case 'S':
process->setStatus(Process::Sleeping);
break;
case 'D':
process->setStatus(Process::DiskSleep);
break;
case 'Z':
process->setStatus(Process::Zombie);
break;
case 'T':
process->setStatus(Process::Stopped);
break;
case 'W':
process->setStatus(Process::Paging);
break;
default:
process->setStatus(Process::OtherStatus);
break;
}
return true;
}
QDateTime ProcessesATop::viewingTime() const
{
if(!d->ready)
return QDateTime();
return d->historyTimes.at(d->currentlySelectedIndex).first;
}
bool ProcessesATop::setViewingTime(const QDateTime &when)
{
QPair<QDateTime, uint> tmpWhen(when, 0);
QList< QPair<QDateTime,uint> >::iterator i = qUpperBound(d->historyTimes.begin(), d->historyTimes.end(), tmpWhen);
if(i->first == when || (i->first > when && i->first.addSecs(-i->second) <= when)) {
//We found the time :)
d->currentlySelectedIndex = i - d->historyTimes.begin();
bool success = d->loadDataForHistory(d->currentlySelectedIndex);
if(!success)
qWarning() << d->lastError;
return success;
}
return false;
}
QList< QPair<QDateTime, uint> > ProcessesATop::historiesAvailable() const
{
return d->historyTimes;
}
QSet<long> ProcessesATop::getAllPids( )
{
return d->pids.toSet();
}
bool ProcessesATop::sendSignal(long pid, int sig) {
Q_UNUSED(pid);
Q_UNUSED(sig);
errorCode = Processes::NotSupported;
return false;
}
bool ProcessesATop::setNiceness(long pid, int priority) {
Q_UNUSED(pid);
Q_UNUSED(priority);
errorCode = Processes::NotSupported;
return false;
}
bool ProcessesATop::setScheduler(long pid, int priorityClass, int priority) {
Q_UNUSED(pid);
Q_UNUSED(priorityClass);
Q_UNUSED(priority);
errorCode = Processes::NotSupported;
return false;
}
long long ProcessesATop::totalPhysicalMemory() {
return 0;
}
ProcessesATop::~ProcessesATop()
{
delete d;
}
}

View file

@ -1,77 +0,0 @@
/* This file is part of the KDE project
Copyright (C) 2007 John Tapsell <tapsell@kde.org>
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 PROCESSES_ATOP_H_
#define PROCESSES_ATOP_H_
#include "processes_base_p.h"
#include <unistd.h> //For sysconf
#include <QSet>
#include <QDateTime>
namespace KSysGuard
{
class Process;
/**
* This is the ATOP specific code to get process information for the local host.
*/
class ProcessesATop : public AbstractProcesses {
public:
ProcessesATop(bool loadDefaultFile = true);
virtual ~ProcessesATop();
virtual QSet<long> getAllPids();
virtual long getParentPid(long pid);
virtual bool updateProcessInfo(long pid, Process *process);
virtual bool sendSignal(long pid, int sig);
virtual bool setNiceness(long pid, int priority);
virtual bool setScheduler(long pid, int priorityClass, int priority);
virtual long long totalPhysicalMemory();
virtual long numberProcessorCores()
#ifdef _SC_NPROCESSORS_ONLN
{ return sysconf(_SC_NPROCESSORS_ONLN); } // Should work on any recent posix system
#else
;
#endif
virtual void updateAllProcesses(Processes::UpdateFlags updateFlags) { mUpdateFlags = updateFlags; emit processesUpdated(); } //For local machine, there is no delay
bool isHistoryAvailable() const;
QDateTime viewingTime() const;
bool setViewingTime(const QDateTime &when);
QList< QPair<QDateTime, uint> > historiesAvailable() const;
bool loadHistoryFile(const QString &filename);
QString historyFileName() const;
private:
/**
* You can use this for whatever data you want.
* Be careful about preserving state in between getParentPid and updateProcessInfo calls
* if you chose to do that. getParentPid may be called several times
* for different pids before the relevant updateProcessInfo calls are made.
* This is because the tree structure has to be sorted out first.
*/
class Private;
Private *d;
Processes::UpdateFlags mUpdateFlags;
};
}
#endif

View file

@ -128,6 +128,7 @@ void testProcess::testTimeToUpdateAllProcesses() {
processController->updateAllProcesses();
}
}
void testProcess::testTimeToUpdateModel() {
KSysGuardProcessList *processList = new KSysGuardProcessList;
processList->treeView()->setColumnHidden(13, false);
@ -141,54 +142,6 @@ void testProcess::testTimeToUpdateModel() {
delete processList;
}
void testProcess::testHistories() {
KSysGuard::Processes *processController = new KSysGuard::Processes();
QBENCHMARK_ONCE {
if(!processController->isHistoryAvailable()) {
qWarning("History was not available");
delete processController;
return;
}
}
QCOMPARE(processController->historyFileName(), QString("/var/log/atop.log"));
QList< QPair<QDateTime, uint> > history = processController->historiesAvailable();
bool success = processController->setViewingTime(history[0].first);
QVERIFY(success);
QVERIFY(processController->viewingTime() == history[0].first);
success = processController->setViewingTime(history[0].first.addSecs(-1));
QVERIFY(success);
QVERIFY(processController->viewingTime() == history[0].first);
success = processController->setViewingTime(history[0].first.addSecs(-history[0].second -1));
QVERIFY(!success);
QVERIFY(processController->viewingTime() == history[0].first);
QCOMPARE(processController->historyFileName(), QString("/var/log/atop.log"));
//Test the tree structure
processController->updateAllProcesses();
QList<KSysGuard::Process *> processes = processController->getAllProcesses();
Q_FOREACH( KSysGuard::Process *process, processes) {
QCOMPARE(countNumChildren(process), process->numChildren);
for(int i =0; i < process->children.size(); i++) {
QVERIFY(process->children[i]->parent);
QCOMPARE(process->children[i]->parent, process);
}
}
//test all the pids are unique
QSet<long> pids;
Q_FOREACH( KSysGuard::Process *process, processes) {
if(process->pid == 0) continue;
QVERIFY(process->pid > 0);
QVERIFY(!process->name.isEmpty());
QVERIFY(!pids.contains(process->pid));
pids.insert(process->pid);
}
delete processController;
}
void testProcess::testUpdateOrAddProcess() {
KSysGuard::Processes *processController = new KSysGuard::Processes();
processController->updateAllProcesses();
@ -204,25 +157,7 @@ void testProcess::testUpdateOrAddProcess() {
processController->updateOrAddProcess(0);
processController->updateOrAddProcess(-1);
}
void testProcess::testHistoriesWithWidget() {
KSysGuardProcessList *processList = new KSysGuardProcessList;
processList->treeView()->setColumnHidden(13, false);
processList->show();
QTest::qWaitForWindowShown(processList);
KSysGuard::Processes *processController = processList->processModel()->processController();
QList< QPair<QDateTime, uint> > history = processController->historiesAvailable();
for(int i = 0; i < history.size(); i++) {
qDebug() << "Viewing time" << history[i].first;
bool success = processController->setViewingTime(history[i].first);
QVERIFY(success);
QCOMPARE(processController->viewingTime(), history[i].first);
processList->updateList();
QTest::qWait(100);
}
delete processList;
}
QTEST_KDEMAIN(testProcess,GUI)
#include "moc_processtest.cpp"

View file

@ -36,8 +36,6 @@ class testProcess : public QObject
void testProcesses();
void testProcessesTreeStructure();
void testProcessesModification();
void testHistories();
void testHistoriesWithWidget();
void testUpdateOrAddProcess();
};
#endif