KASM-2152 fps added to stats (#25)

Co-authored-by: matt <matt@kasmweb.com>
This commit is contained in:
mmcclaskey 2022-01-11 15:31:39 -05:00 committed by GitHub
parent 9383783efd
commit ad1fc1f06d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 16 deletions

View File

@ -1185,9 +1185,16 @@ const UI = {
//recieved bottleneck stats //recieved bottleneck stats
bottleneckStatsRecieve(e) { bottleneckStatsRecieve(e) {
var obj = JSON.parse(e.detail.text); if (UI.rfb) {
document.getElementById("noVNC_connection_stats").innerHTML = "CPU: " + obj[0] + "/" + obj[1] + " | Network: " + obj[2] + "/" + obj[3]; try {
let obj = JSON.parse(e.detail.text);
let fps = UI.rfb.statsFps;
document.getElementById("noVNC_connection_stats").innerHTML = "CPU: " + obj[0] + "/" + obj[1] + " | Network: " + obj[2] + "/" + obj[3] + " | FPS: " + fps;
console.log(e.detail.text); console.log(e.detail.text);
} catch (err) {
console.log('Invalid bottleneck stats recieved from server.')
}
}
}, },
popupMessage: function(msg, secs) { popupMessage: function(msg, secs) {

View File

@ -57,6 +57,19 @@ export default class Display {
Log.Debug("User Agent: " + navigator.userAgent); Log.Debug("User Agent: " + navigator.userAgent);
// performance metrics, try to calc a fps equivelant
this._flipCnt = 0;
this._currentFrameDamages = [];
this._lastFlip = Date.now();
setInterval(function() {
let delta = Date.now() - this._lastFlip;
if (delta > 0) {
this._fps = (this._flipCnt / (delta / 1000)).toFixed(2);
}
this._lastFlip = Date.now();
this._flipCnt = 0;
}.bind(this), 5000);
Log.Debug("<< Display.constructor"); Log.Debug("<< Display.constructor");
// ===== PROPERTIES ===== // ===== PROPERTIES =====
@ -64,10 +77,11 @@ export default class Display {
this._scale = 1.0; this._scale = 1.0;
this._clipViewport = false; this._clipViewport = false;
this._antiAliasing = 0; this._antiAliasing = 0;
this._fps = 0;
// ===== EVENT HANDLERS ===== // ===== EVENT HANDLERS =====
this.onflush = () => {}; // A flush request has finished this.onflush = () => { }; // A flush request has finished
} }
// ===== PROPERTIES ===== // ===== PROPERTIES =====
@ -107,6 +121,8 @@ export default class Display {
this._renderMs = val; this._renderMs = val;
} }
get fps() { return this._fps; }
// ===== PUBLIC METHODS ===== // ===== PUBLIC METHODS =====
viewportChangePos(deltaX, deltaY) { viewportChangePos(deltaX, deltaY) {
@ -256,6 +272,21 @@ export default class Display {
} }
} }
// Attempt to determine when updates overlap an area and thus indicate a new frame
isNewFrame(x, y, w, h) {
for (var i = 0; i < this._currentFrameDamages.length; i++) {
let area = this._currentFrameDamages[i];
if (x >= area.x && x <= (area.x + area.w) && y >= area.y && y <= (area.y + area.h)) {
this._currentFrameDamages = [];
return true;
}
}
var new_area = { x: x, y: y, w: w, h: h }
this._currentFrameDamages.push(new_area);
return false;
}
// Update the visible canvas with the contents of the // Update the visible canvas with the contents of the
// rendering canvas // rendering canvas
flip(fromQueue) { flip(fromQueue) {
@ -297,6 +328,10 @@ export default class Display {
this._targetCtx.drawImage(this._backbuffer, this._targetCtx.drawImage(this._backbuffer,
x, y, w, h, x, y, w, h,
vx, vy, w, h); vx, vy, w, h);
if (this.isNewFrame(x, y, h, w)) {
this._flipCnt += 1;
}
} }
this._damageBounds.left = this._damageBounds.top = 65535; this._damageBounds.left = this._damageBounds.top = 65535;

View File

@ -108,23 +108,16 @@ export default class RFB extends EventTargetMixin {
this._rfbTightVNC = false; this._rfbTightVNC = false;
this._rfbVeNCryptState = 0; this._rfbVeNCryptState = 0;
this._rfbXvpVer = 0; this._rfbXvpVer = 0;
this._fbWidth = 0; this._fbWidth = 0;
this._fbHeight = 0; this._fbHeight = 0;
this._fbName = ""; this._fbName = "";
this._capabilities = { power: false }; this._capabilities = { power: false };
this._supportsFence = false; this._supportsFence = false;
this._supportsContinuousUpdates = false; this._supportsContinuousUpdates = false;
this._enabledContinuousUpdates = false; this._enabledContinuousUpdates = false;
this._supportsSetDesktopSize = false; this._supportsSetDesktopSize = false;
this._screenID = 0; this._screenID = 0;
this._screenFlags = 0; this._screenFlags = 0;
this._qemuExtKeyEventSupported = false; this._qemuExtKeyEventSupported = false;
// kasm defaults // kasm defaults
@ -655,6 +648,8 @@ export default class RFB extends EventTargetMixin {
} }
} }
get statsFps() { return this._display.fps; }
// ===== PUBLIC METHODS ===== // ===== PUBLIC METHODS =====
/* /*
@ -2666,18 +2661,17 @@ export default class RFB extends EventTargetMixin {
let first, ret; let first, ret;
switch (msgType) { switch (msgType) {
case 0: // FramebufferUpdate case 0: // FramebufferUpdate
let before = performance.now();
this._display.renderMs = 0; this._display.renderMs = 0;
ret = this._framebufferUpdate(); ret = this._framebufferUpdate();
if (ret && !this._enabledContinuousUpdates) { if (ret && !this._enabledContinuousUpdates) {
RFB.messages.fbUpdateRequest(this._sock, true, 0, 0, RFB.messages.fbUpdateRequest(this._sock, true, 0, 0,
this._fbWidth, this._fbHeight); this._fbWidth, this._fbHeight);
} }
let elapsed = performance.now() - before;
if (this._trackFrameStats) { if (this._trackFrameStats) {
RFB.messages.sendFrameStats(this._sock, elapsed, this._display.renderMs); RFB.messages.sendFrameStats(this._sock, this._display.fps, this._display.renderMs);
this._trackFrameStats = false; this._trackFrameStats = false;
} }
return ret; return ret;
case 1: // SetColorMapEntries case 1: // SetColorMapEntries