Skip to content

Commit

Permalink
Merge pull request #1742 from weaveworks/profile-websocket-render
Browse files Browse the repository at this point in the history
Add browser console logging for websocket to render times
  • Loading branch information
davkal authored Aug 5, 2016
2 parents 74efec8 + c4154bc commit cbb1350
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions client/app/scripts/utils/web-api-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const log = debug('scope:web-api-utils');

const reconnectTimerInterval = 5000;
const updateFrequency = '5s';
const FIRST_RENDER_TOO_LONG_THRESHOLD = 100; // ms

let socket;
let reconnectTimer = 0;
Expand All @@ -21,6 +22,8 @@ let currentOptions = null;
let topologyTimer = 0;
let apiDetailsTimer = 0;
let controlErrorTimer = 0;
let createWebsocketAt = 0;
let firstMessageOnWebsocketAt = 0;

function buildOptionsQuery(options) {
if (options) {
Expand Down Expand Up @@ -66,6 +69,10 @@ function createWebsocket(topologyUrl, optionsQuery, dispatch) {
// right away
}

// profiling
createWebsocketAt = new Date();
firstMessageOnWebsocketAt = 0;

socket = new WebSocket(`${wsUrl}${topologyUrl}/ws?t=${updateFrequency}&${optionsQuery}`);

socket.onopen = () => {
Expand All @@ -91,6 +98,16 @@ function createWebsocket(topologyUrl, optionsQuery, dispatch) {
socket.onmessage = (event) => {
const msg = JSON.parse(event.data);
dispatch(receiveNodesDelta(msg));

// profiling (receiveNodesDelta triggers synchronous render)
if (!firstMessageOnWebsocketAt) {
firstMessageOnWebsocketAt = new Date();
const timeToFirstMessage = firstMessageOnWebsocketAt - createWebsocketAt;
if (timeToFirstMessage > FIRST_RENDER_TOO_LONG_THRESHOLD) {
log('Time (ms) to first nodes render after websocket was created',
firstMessageOnWebsocketAt - createWebsocketAt);
}
}
};
}

Expand Down

0 comments on commit cbb1350

Please sign in to comment.