Commit 68dad6f4 authored by Daniel Smith's avatar Daniel Smith

Add memory reporting slot

parent f92240a8
#include <QObject>
#include <benchmark.h>
#include <QtDebug>
#include <QString>
#include <QElapsedTimer>
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include <QGuiApplication>
#include <iostream>
#include <fstream>
#include <unistd.h>
void Benchmark::startTimer(){
......@@ -13,6 +15,8 @@ void Benchmark::startTimer(){
void Benchmark::countFrame(){
qint64 frametime = timer.restart();
if (frame % 10 == 0)
emit measureMemory();
int thisframe = static_cast<int>(frametime);
try{
frametimes[frame] = thisframe;
......@@ -42,10 +46,18 @@ void Benchmark::measureMem(){
# error "Unknown Apple platform"
#endif
#elif __linux__
// linux
int tSize = 0, resident = 0, share = 0;
std::ifstream buffer("/proc/self/statm");
buffer >> tSize >> resident >> share;
buffer.close();
long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
double rss = resident * page_size_kb;
double shared_mem = share * page_size_kb;
#else
# error "Unknown compiler"
#endif
qDebug() << "Virtual Memory (KB): " << shared_mem << " RSS (KB): " << rss << " Private Bytes (KB): " << (rss - shared_mem);
}
void Benchmark::finished(){
......@@ -53,6 +65,10 @@ void Benchmark::finished(){
}
int Benchmark::runBenchmark(QGuiApplication &app){
measureMem();
QObject::connect(this, &Benchmark::measureMemory,
this, &Benchmark::measureMem);
this->timer.start();
QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
if (engine.rootObjects().size() != 1)
......@@ -61,6 +77,7 @@ int Benchmark::runBenchmark(QGuiApplication &app){
//Finish timing after the first frame is ready.
QObject::connect(window, &QQuickWindow::frameSwapped,
this, &Benchmark::countFrame);
//QCoreApplication::instance(), &QCoreApplication::quit);
if (app.exec() != 0)
return -1;
......
......@@ -8,23 +8,28 @@
class Benchmark: public QObject{
Q_OBJECT
public:
int runBenchmark(QGuiApplication &);
signals:
void measureMemory();
public slots:
void countFrame();
void countMemory(int value);
void measureMem();
private:
QElapsedTimer timer;
int frame = 0;
int lastframetotal;
static const int maxframes = 300;
static const int maxframes = 120;
int frametimes [maxframes];
void finished();
void startTimer();
void measureMem();
const int processID = static_cast<int>(QCoreApplication::applicationPid());
//void measureMem();
const int processID = static_cast<int>(QCoreApplication::applicationPid());
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment