Professional Documents
Culture Documents
Message
Message
Message
h"
#include "ui_mainwindow.h"
#include <QSharedPointer>
#include <QLabel>
#include <QTimer>
#include <fstream>
#include <vector>
#include <string>
#include <QStringList>
#include <QProcess>
#include <QTime>
#include <sstream>
#include <windows.h>
#include <psapi.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString MainWindow::mesure(int n)
{
QString e;
int gb = (n / 1024) / 1024;
int mb = (n - gb * 1024 * 1024) / 1024;
int kb = (n - (gb * 1024 * 1024 + mb * 1024));
if (gb > 0)
e = QString::number(gb) + QString(" Gb ");
else
e = QString("");
if (mb > 0)
e += QString::number(mb) + QString(" Mb ");
if (kb > 0)
e += QString::number(kb) + QString(" Kb ");
return e;
}
return memoryLoad;
}
void MainWindow::realtimeDataSlot()
{
static QTime time(QTime::currentTime());
// визначенню двох нових точок для вибірки даних
double key = QTime::currentTime().msecsSinceStartOfDay() / 1000.0;
// час, що пройшов з моменту запуску – перша точка
static double lastPointKey = 0; //друга точка
if (key - lastPointKey > 0.002) // оновлення кожні 2 мс
{
// виведення даних
int cpu_persent = getCpuLoad(1);
customPlot->graph(0)->addData(key, cpu_persent);
cpu->setText(QString::number(cpu_persent) + '%');
lastPointKey = key;
QString total, used;
int memory_persent = getMemoryLoad(total, used);
customPlot->graph(1)->addData(key, memory_persent);
memory->setText(QString::number(memory_persent) + '%');
memoryTotal->setText(total);
memoryUsed->setText(used);
k++;
}
if (k > 4) //прокрутка графіку буде відбуватись після 4 секунд.
customPlot->xAxis->setRange(key, 4, Qt::AlignRight); //зсув (прокрутка)
графіку з константою 4
customPlot->replot();
}
GetSystemInfo(&sysInfo);
numProcessors = sysInfo.dwNumberOfProcessors;
GetSystemTimeAsFileTime(&ftime);
memcpy(&now, &ftime, sizeof(FILETIME));
self = GetCurrentProcess();
GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser);
memcpy(&sys, &fsys, sizeof(FILETIME));
memcpy(&user, &fuser, sizeof(FILETIME));
percent = (sys.QuadPart - lastSysCPU.QuadPart) +
(user.QuadPart - lastUserCPU.QuadPart);
percent /= (now.QuadPart - lastCPU.QuadPart);
percent /= numProcessors;
lastCPU = now;
lastUserCPU = user;
lastSysCPU = sys;
MainWindow::~MainWindow()
{
delete ui;
}