Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add browser console logging for websocket to render times #1742

Merged
merged 1 commit into from
Aug 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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