Merge pull request #6 from kasmtech/apistats

Apistats
This commit is contained in:
mmcclaskey 2021-08-05 11:01:03 -04:00 committed by GitHub
commit 519a40213b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 0 deletions

View File

@ -21,6 +21,8 @@ export default class Display {
this._fbWidth = 0; this._fbWidth = 0;
this._fbHeight = 0; this._fbHeight = 0;
this._renderMs = 0;
this._prevDrawStyle = ""; this._prevDrawStyle = "";
Log.Debug(">> Display.constructor"); Log.Debug(">> Display.constructor");
@ -91,6 +93,13 @@ export default class Display {
return this._fbHeight; return this._fbHeight;
} }
get renderMs() {
return this._renderMs;
}
set renderMs(val) {
this._renderMs = val;
}
// ===== PUBLIC METHODS ===== // ===== PUBLIC METHODS =====
viewportChangePos(deltaX, deltaY) { viewportChangePos(deltaX, deltaY) {
@ -470,6 +479,7 @@ export default class Display {
_scanRenderQ() { _scanRenderQ() {
let ready = true; let ready = true;
let before = Date.now();
while (ready && this._renderQ.length > 0) { while (ready && this._renderQ.length > 0) {
const a = this._renderQ[0]; const a = this._renderQ[0];
switch (a.type) { switch (a.type) {
@ -513,5 +523,8 @@ export default class Display {
this._flushing = false; this._flushing = false;
this.onflush(); this.onflush();
} }
let elapsed = Date.now() - before;
this._renderMs += elapsed;
} }
} }

View File

@ -142,6 +142,8 @@ export default class RFB extends EventTargetMixin {
this._maxVideoResolutionX = 960; this._maxVideoResolutionX = 960;
this._maxVideoResolutionY = 540; this._maxVideoResolutionY = 540;
this._trackFrameStats = false;
this._clipboardText = null; this._clipboardText = null;
this._clipboardServerCapabilitiesActions = {}; this._clipboardServerCapabilitiesActions = {};
this._clipboardServerCapabilitiesFormats = {}; this._clipboardServerCapabilitiesFormats = {};
@ -2451,11 +2453,18 @@ 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;
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) {
RFB.messages.sendFrameStats(this._sock, elapsed, this._display.renderMs);
this._trackFrameStats = false;
}
return ret; return ret;
case 1: // SetColorMapEntries case 1: // SetColorMapEntries
@ -2488,6 +2497,10 @@ export default class RFB extends EventTargetMixin {
case 178: // KASM bottleneck stats case 178: // KASM bottleneck stats
return this._handle_server_stats_msg(); return this._handle_server_stats_msg();
case 179: // KASM requesting frame stats
this._trackFrameStats = true;
return true;
case 248: // ServerFence case 248: // ServerFence
return this._handleServerFenceMsg(); return this._handleServerFenceMsg();
@ -3236,6 +3249,32 @@ RFB.messages = {
sock.flush(); sock.flush();
}, },
sendFrameStats(sock, allMs, renderMs) {
const buff = sock._sQ;
const offset = sock._sQlen;
if (buff == null) { return; }
buff[offset] = 179; // msg-type
buff[offset + 1] = 0; // padding
buff[offset + 2] = 0; // padding
buff[offset + 3] = 0; // padding
buff[offset + 4] = allMs >> 24;
buff[offset + 5] = allMs >> 16;
buff[offset + 6] = allMs >> 8;
buff[offset + 7] = allMs;
buff[offset + 8] = renderMs >> 24;
buff[offset + 9] = renderMs >> 16;
buff[offset + 10] = renderMs >> 8;
buff[offset + 11] = renderMs;
sock._sQlen += 12;
sock.flush();
},
enableContinuousUpdates(sock, enable, x, y, width, height) { enableContinuousUpdates(sock, enable, x, y, width, height) {
const buff = sock._sQ; const buff = sock._sQ;