From 1dd3c7e8ba039b01c497894ef865b89bb535196e Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 28 Apr 2020 10:39:09 +0300 Subject: [PATCH] [effects/showfps] Calculate "correct" FPS Summary: cca0e15b455ba6 broke code that calculates the value of the fps counter. The frames field stores timestamps of previous frames, not time between each two consecutive frames. This change doesn't attempt to make the show fps compute more accurate performance metrics, e.g. how much times it takes to execute rendering commands on the GPU, etc. Test Plan: The Show FPS effect displays more sensible values. Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: davidedmundson, broulik, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D29247 --- effects/showfps/showfps.cpp | 9 +++++++-- effects/showfps/showfps.h | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/effects/showfps/showfps.cpp b/effects/showfps/showfps.cpp index abfb0852b8..4d58337f83 100644 --- a/effects/showfps/showfps.cpp +++ b/effects/showfps/showfps.cpp @@ -123,13 +123,14 @@ void ShowFpsEffect::reconfigure(ReconfigureFlags) void ShowFpsEffect::prePaintScreen(ScreenPrePaintData& data, int time) { - frames[ frames_pos ] = t.restart(); + frames[ frames_pos ] = QDateTime::currentMSecsSinceEpoch(); if (++frames_pos == MAX_FPS) frames_pos = 0; effects->prePaintScreen(data, time); data.paint += fps_rect; paint_size[ paints_pos ] = 0; + t.restart(); } void ShowFpsEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) @@ -150,11 +151,15 @@ void ShowFpsEffect::paintWindow(EffectWindow* w, int mask, QRegion region, Windo void ShowFpsEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData& data) { effects->paintScreen(mask, region, data); + int lastFrame = frames_pos - 1; + if (lastFrame < 0) + lastFrame = MAX_FPS - 1; + const qint64 lastTimestamp = frames[lastFrame]; int fps = 0; for (int i = 0; i < MAX_FPS; ++i) - if (abs(t.elapsed() - frames[ i ]) < 1000) + if (abs(lastTimestamp - frames[ i ]) < 1000) ++fps; // count all frames in the last second if (fps > MAX_TIME) fps = MAX_TIME; // keep it the same height diff --git a/effects/showfps/showfps.h b/effects/showfps/showfps.h index 69e5ff144b..b10b4b5e8c 100644 --- a/effects/showfps/showfps.h +++ b/effects/showfps/showfps.h @@ -89,7 +89,7 @@ private: int paint_size[ NUM_PAINTS ]; // number of pixels painted int paints_pos; // position in the queue enum { MAX_FPS = 200 }; - int frames[ MAX_FPS ]; // (sec*1000+msec) of the time the frame was done + qint64 frames[ MAX_FPS ]; // the time when the frame was done int frames_pos; // position in the queue double alpha; int x;