From 99fe70bbd629148654b49c0522510776d14df54c Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Mon, 28 Sep 2020 14:37:19 +0300 Subject: [PATCH] Add a debug-level print on the last ~second's maximum encoding time --- common/rfb/EncodeManager.cxx | 21 +++++++++++++++++++-- common/rfb/EncodeManager.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index 99c871f..a32e08c 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -155,7 +155,9 @@ static void updateMaxVideoRes(uint16_t *x, uint16_t *y) { EncodeManager::EncodeManager(SConnection* conn_, EncCache *encCache_) : conn(conn_), dynamicQualityMin(-1), dynamicQualityOff(-1), - areaCur(0), videoDetected(false), videoTimer(this), encCache(encCache_) + areaCur(0), videoDetected(false), videoTimer(this), + maxEncodingTime(0), framesSinceEncPrint(0), + encCache(encCache_) { StatsVector::iterator iter; @@ -1136,9 +1138,24 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb, checkWebpFallback(start); } - if (start) + if (start) { encodingTime = msSince(start); + if (vlog.getLevel() >= vlog.LEVEL_DEBUG) { + framesSinceEncPrint++; + if (maxEncodingTime < encodingTime) + maxEncodingTime = encodingTime; + + if (framesSinceEncPrint >= rfb::Server::frameRate) { + vlog.info("Max encoding time during the last %u frames: %u ms (limit %u, near limit %.0f)", + framesSinceEncPrint, maxEncodingTime, 1000/rfb::Server::frameRate, + 1000/rfb::Server::frameRate * 0.8f); + maxEncodingTime = 0; + framesSinceEncPrint = 0; + } + } + } + if (webpTookTooLong) activeEncoders[encoderFullColour] = encoderTightJPEG; diff --git a/common/rfb/EncodeManager.h b/common/rfb/EncodeManager.h index 5453bc8..9ed5b65 100644 --- a/common/rfb/EncodeManager.h +++ b/common/rfb/EncodeManager.h @@ -182,6 +182,7 @@ namespace rfb { unsigned webpBenchResult; bool webpTookTooLong; unsigned encodingTime; + unsigned maxEncodingTime, framesSinceEncPrint; EncCache *encCache;