Commit 35e9ddc2 authored by Laszlo Agocs's avatar Laszlo Agocs

prof: expose min/max/avg times in the api as well

parent a4844d82
......@@ -60,6 +60,7 @@
#include <QBakedShader>
#include <QFile>
#include <QRhiProfiler>
#ifndef QT_NO_OPENGL
#include <QRhiGles2InitParams>
......@@ -383,7 +384,22 @@ void Window::render()
m_frameCount += 1;
if (m_timer.elapsed() > 1000) {
qDebug("%d", m_frameCount);
if (rhiFlags.testFlag(QRhi::EnableProfiling)) {
const QRhiProfiler::CpuTime ff = m_r->profiler()->frameToFrameTimes(m_sc);
const QRhiProfiler::CpuTime be = m_r->profiler()->frameBuildTimes(m_sc);
const QRhiProfiler::GpuTime gp = m_r->profiler()->gpuFrameTimes(m_sc);
qDebug("ca. %d fps. "
"frame-to-frame: min %lld max %lld avg %f. "
"frame build: min %lld max %lld avg %f. "
"gpu frame time: min %f max %f avg %f",
m_frameCount,
ff.minTime, ff.maxTime, ff.avgTime,
be.minTime, be.maxTime, be.avgTime,
gp.minTime, gp.maxTime, gp.avgTime);
} else {
qDebug("ca. %d fps", m_frameCount);
}
m_timer.restart();
m_frameCount = 0;
}
......
......@@ -72,6 +72,33 @@ void QRhiProfiler::setFrameTimingWriteInterval(int frameCount)
d->frameTimingWriteInterval = frameCount;
}
QRhiProfiler::CpuTime QRhiProfiler::frameToFrameTimes(QRhiSwapChain *sc) const
{
auto it = d->swapchains.constFind(sc);
if (it != d->swapchains.constEnd())
return it->frameToFrameTime;
return QRhiProfiler::CpuTime();
}
QRhiProfiler::CpuTime QRhiProfiler::frameBuildTimes(QRhiSwapChain *sc) const
{
auto it = d->swapchains.constFind(sc);
if (it != d->swapchains.constEnd())
return it->beginToEndFrameTime;
return QRhiProfiler::CpuTime();
}
QRhiProfiler::GpuTime QRhiProfiler::gpuFrameTimes(QRhiSwapChain *sc) const
{
auto it = d->swapchains.constFind(sc);
if (it != d->swapchains.constEnd())
return it->gpuFrameTime;
return QRhiProfiler::GpuTime();
}
void QRhiProfilerPrivate::startEntry(QRhiProfiler::StreamOp op, qint64 timestamp, QRhiResource *res)
{
buf.clear();
......@@ -301,34 +328,30 @@ void QRhiProfilerPrivate::endSwapChainFrame(QRhiSwapChain *sc, int frameCount)
return;
}
scd.frameToFrameDelta.append(scd.frameToFrameTimer.restart());
if (scd.frameToFrameDelta.count() >= frameTimingWriteInterval) {
qint64 minDelta;
qint64 maxDelta;
float avgDelta = 0;
calcTiming(&scd.frameToFrameDelta, &minDelta, &maxDelta, &avgDelta);
scd.frameToFrameSamples.append(scd.frameToFrameTimer.restart());
if (scd.frameToFrameSamples.count() >= frameTimingWriteInterval) {
calcTiming(&scd.frameToFrameSamples,
&scd.frameToFrameTime.minTime, &scd.frameToFrameTime.maxTime, &scd.frameToFrameTime.avgTime);
if (outputDevice) {
startEntry(QRhiProfiler::FrameToFrameTime, ts.elapsed(), sc);
writeInt("frames_since_resize", frameCount);
writeInt("min_ms_frame_delta", minDelta);
writeInt("max_ms_frame_delta", maxDelta);
writeFloat("Favg_ms_frame_delta", avgDelta);
writeInt("min_ms_frame_delta", scd.frameToFrameTime.minTime);
writeInt("max_ms_frame_delta", scd.frameToFrameTime.maxTime);
writeFloat("Favg_ms_frame_delta", scd.frameToFrameTime.avgTime);
endEntry();
}
}
scd.beginToEndDelta.append(scd.beginToEndTimer.elapsed());
if (scd.beginToEndDelta.count() >= frameTimingWriteInterval) {
qint64 minDelta;
qint64 maxDelta;
float avgDelta = 0;
calcTiming(&scd.beginToEndDelta, &minDelta, &maxDelta, &avgDelta);
scd.beginToEndSamples.append(scd.beginToEndTimer.elapsed());
if (scd.beginToEndSamples.count() >= frameTimingWriteInterval) {
calcTiming(&scd.beginToEndSamples,
&scd.beginToEndFrameTime.minTime, &scd.beginToEndFrameTime.maxTime, &scd.beginToEndFrameTime.avgTime);
if (outputDevice) {
startEntry(QRhiProfiler::FrameBuildTime, ts.elapsed(), sc);
writeInt("frames_since_resize", frameCount);
writeInt("min_ms_frame_build", minDelta);
writeInt("max_ms_frame_build", maxDelta);
writeFloat("Favg_ms_frame_build", avgDelta);
writeInt("min_ms_frame_build", scd.beginToEndFrameTime.minTime);
writeInt("max_ms_frame_build", scd.beginToEndFrameTime.maxTime);
writeFloat("Favg_ms_frame_build", scd.beginToEndFrameTime.avgTime);
endEntry();
}
}
......@@ -337,18 +360,17 @@ void QRhiProfilerPrivate::endSwapChainFrame(QRhiSwapChain *sc, int frameCount)
void QRhiProfilerPrivate::swapChainFrameGpuTime(QRhiSwapChain *sc, float gpuTime)
{
Sc &scd(swapchains[sc]);
scd.gpuFrameTime.append(gpuTime);
if (scd.gpuFrameTime.count() >= frameTimingWriteInterval) {
float minDelta;
float maxDelta;
float avgDelta = 0;
calcTiming(&scd.gpuFrameTime, &minDelta, &maxDelta, &avgDelta);
scd.gpuFrameSamples.append(gpuTime);
if (scd.gpuFrameSamples.count() >= frameTimingWriteInterval) {
calcTiming(&scd.gpuFrameSamples,
&scd.gpuFrameTime.minTime, &scd.gpuFrameTime.maxTime, &scd.gpuFrameTime.avgTime);
if (outputDevice) {
startEntry(QRhiProfiler::GpuFrameTime, ts.elapsed(), sc);
writeFloat("Fmin_ms_gpu_frame_time", minDelta);
writeFloat("Fmax_ms_gpu_frame_time", maxDelta);
writeFloat("Favg_ms_gpu_frame_time", avgDelta);
endEntry(); }
writeFloat("Fmin_ms_gpu_frame_time", scd.gpuFrameTime.minTime);
writeFloat("Fmax_ms_gpu_frame_time", scd.gpuFrameTime.maxTime);
writeFloat("Favg_ms_gpu_frame_time", scd.gpuFrameTime.avgTime);
endEntry();
}
}
}
......
......@@ -77,6 +77,22 @@ public:
int frameTimingWriteInterval() const;
void setFrameTimingWriteInterval(int frameCount);
struct CpuTime {
qint64 minTime = 0;
qint64 maxTime = 0;
float avgTime = 0;
};
struct GpuTime {
float minTime = 0;
float maxTime = 0;
float avgTime = 0;
};
CpuTime frameToFrameTimes(QRhiSwapChain *sc) const;
CpuTime frameBuildTimes(QRhiSwapChain *sc) const; // beginFrame - endFrame
GpuTime gpuFrameTimes(QRhiSwapChain *sc) const;
private:
Q_DISABLE_COPY(QRhiProfiler)
QRhiProfiler();
......@@ -85,6 +101,9 @@ private:
friend class QRhiProfilerPrivate;
};
Q_DECLARE_TYPEINFO(QRhiProfiler::CpuTime, Q_MOVABLE_TYPE);
Q_DECLARE_TYPEINFO(QRhiProfiler::GpuTime, Q_MOVABLE_TYPE);
QT_END_NAMESPACE
#endif
......@@ -92,16 +92,19 @@ public:
int frameTimingWriteInterval = DEFAULT_FRAME_TIMING_WRITE_INTERVAL;
struct Sc {
Sc() {
frameToFrameDelta.reserve(DEFAULT_FRAME_TIMING_WRITE_INTERVAL);
beginToEndDelta.reserve(DEFAULT_FRAME_TIMING_WRITE_INTERVAL);
gpuFrameTime.reserve(DEFAULT_FRAME_TIMING_WRITE_INTERVAL);
frameToFrameSamples.reserve(DEFAULT_FRAME_TIMING_WRITE_INTERVAL);
beginToEndSamples.reserve(DEFAULT_FRAME_TIMING_WRITE_INTERVAL);
gpuFrameSamples.reserve(DEFAULT_FRAME_TIMING_WRITE_INTERVAL);
}
QElapsedTimer frameToFrameTimer;
bool frameToFrameRunning = false;
QElapsedTimer beginToEndTimer;
QVector<qint64> frameToFrameDelta;
QVector<qint64> beginToEndDelta;
QVector<float> gpuFrameTime;
QVector<qint64> frameToFrameSamples;
QVector<qint64> beginToEndSamples;
QVector<float> gpuFrameSamples;
QRhiProfiler::CpuTime frameToFrameTime;
QRhiProfiler::CpuTime beginToEndFrameTime;
QRhiProfiler::GpuTime gpuFrameTime;
};
QHash<QRhiSwapChain *, Sc> swapchains;
};
......
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