Commit dd7998f7 authored by Daniel Smith's avatar Daniel Smith

Change benchmark method to reset the timer after frameswap

parent 9667add0
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.8.0, 2018-12-19T14:40:11. -->
<!-- Written by QtCreator 4.8.0, 2018-12-27T11:42:56. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......@@ -548,6 +548,7 @@
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes">
<value type="QString">QT_LOGGING_RULES=qt.scenegraph.time.glyph=true</value>
<value type="QString">QSG_RENDER_LOOP=basic</value>
</valuelist>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Heavy_QML_example</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
......@@ -562,7 +563,7 @@
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/home/dan/projects/build-Heavy_QML_example-Desktop_Qt_5_6_3_GCC_64bit3-Debug</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default"></value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
......@@ -816,7 +817,7 @@
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">/home/dan/projects/build-Heavy_QML_example-Desktop_Qt_5_11_3_GCC_64bit2-Debug</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default"></value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
......
......@@ -8,6 +8,7 @@
#include <unistd.h>
#include <cmath>
#include <iomanip>
#include <algorithm>
void Benchmark::startTimer(){
......@@ -25,6 +26,7 @@ void Benchmark::countFrame(){
} catch (int e){
//No need to handle this. We probably just rendered extra frames before finished() completed.
}
qDebug() << thisframe; //Turn this off, except the slot doesn't seem to execute at the correct time if we don't output anything.
// qDebug() << "frame " << frame << ": " << thisframe << " ms"; //Turn this off for real runs.
frame+=1;
if (frame >= maxframes){
......@@ -32,6 +34,12 @@ void Benchmark::countFrame(){
}
}
void Benchmark::resetFrameTimer(){
//restart the timer at the end of the render loop, before the next set of render actions.
timer.restart();
qDebug() << "Restart Timer."; //Turn this off, except the slot doesn't seem to execute at the correct time if we don't output anything.
}
void Benchmark::measureMem(){
//Uses OS-specific method to pull memory for this process
#ifdef _WIN32
......@@ -53,13 +61,22 @@ void Benchmark::measureMem(){
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;
int page_size_kb = static_cast<int>(sysconf(_SC_PAGE_SIZE) / 1024); // in case x86-64 is configured to use 2MB pages
int rss = static_cast<int>(resident * page_size_kb);
int shared_memKB = (share * page_size_kb);
#else
# error "Unknown compiler"
#endif
qDebug() << "Virtual Memory (KB): " << shared_mem << " RSS (KB): " << rss << " Private Bytes (KB): " << (rss - shared_mem);
if (beforeFirstFrame) { //Write to the 0 element for our initial measurement.
virtualMem[frame / 10] = shared_memKB;
privateMem[frame / 10] = rss - shared_memKB;
beforeFirstFrame = false;
}else {
virtualMem[(frame / 10) + 1] = shared_memKB;
privateMem[(frame / 10) + 1] = rss - shared_memKB;
}
qDebug() << frame << (frame / 10) << "Virtual Memory (KB): " << shared_memKB << " RSS (KB): " << rss << " Private Bytes (KB): " << (rss - shared_memKB);
}
float Benchmark::calculateSD(float data[]){
......@@ -84,6 +101,17 @@ float Benchmark::calculateSD(float data[]){
void Benchmark::finished(){
qDebug() << "\n-------- FINISHED TEST RUN --------\n";
//int averageVMem = std::accumulate(virtualMem, virtualMem+sizeof(virtualMem)/sizeof(virtualMem[0]), 0) / (maxframes / 10);
int maxVMem = *std::max_element(virtualMem, virtualMem + (maxframes / 10) + 1);
//int averagePMem = std::accumulate(privateMem, privateMem+sizeof(privateMem)/sizeof(privateMem[0]), 0) / (maxframes / 10);
int maxPMem = *std::max_element(privateMem, privateMem + (maxframes / 10) + 1 );
qDebug() << "Max private memory (KB)" << maxPMem;
qDebug() << "Max Virtual memory (KB)" << maxVMem;
qDebug() << "Max QML application private memory (KB)" << maxPMem - privateMem[0];
qDebug() << "Max QML application Virtual memory (KB)" << maxVMem - virtualMem[0];
qDebug() << "";
QString frametimesCS;
for (int i = 0; i < maxframes; i++){
frametimesCS += QString::number(static_cast<double>(frametimes[i]), 'f', 2) + ((i < maxframes - 1) ? ",": "");
......@@ -100,6 +128,8 @@ void Benchmark::finished(){
float meanFrametime = (static_cast<float>(runtime) - startuptime) / static_cast<float>(maxframes);
qDebug() << "Average Frame time:" << QString::number(static_cast<double>(meanFrametime), 'f', 2).toFloat() << "ms";
qDebug() << "";
frametimes[0] = frametimes[1]; // hack to omit start-up time from our standard deviation calcuation.
float runtimeStdDev = calculateSD(frametimes);
qDebug() << "Standard Deviation:" << runtimeStdDev; // << "over" << maxframes << "frames";
......@@ -115,14 +145,22 @@ int Benchmark::runBenchmark(QGuiApplication &app){
qDebug() << "Started timer.";
this->timer.start();
QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
if (engine.rootObjects().size() != 1)
return -1;
QQuickWindow *window = qobject_cast<QQuickWindow*>(engine.rootObjects().first());
//Finish timing after the first frame is ready.
QObject::connect(window, &QQuickWindow::frameSwapped,
// Take our measurement when rendering is complete, but before the framebuffer is swapped.
// If rendering is faster than 16ms, we won't be able to measure by taking the measurement at
// QQuickWindow::frameSwapped
QObject::connect(window, &QQuickWindow::afterRendering,
this, &Benchmark::countFrame);
// Reset the timer when the frame is finally displayed so we can count sync events as well as render
// events starting at the beginning of the next loop.
QObject::connect(window, &QQuickWindow::frameSwapped,
this, &Benchmark::resetFrameTimer);
if (app.exec() != 0)
return -1;
}
......@@ -19,13 +19,18 @@ class Benchmark: public QObject{
public slots:
void countFrame();
void measureMem();
void resetFrameTimer();
private:
QElapsedTimer timer;
bool beforeFirstFrame = true;
int frame = 0;
int lastframetotal;
static const int maxframes = 100;
static const int maxframes = 150;
float frametimes [maxframes];
//add 1 to allow space for the measurement taken before the QML application starts.
int virtualMem [(maxframes / 10) + 1];
int privateMem [(maxframes / 10) + 1];
void finished();
void startTimer();
//void measureMem();
......
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