Files
flipper/src/dispatcher/tracking.js
Daniel Büchele eb316be4e4 fixing tracking metrics
Summary:
- fixing dropped frames calculation
- fixing plugin activation time

Reviewed By: passy

Differential Revision: D9301759

fbshipit-source-id: 872e4d2edcafdbc67668f3d0b713dfbf55f068f5
2018-08-13 15:27:29 -07:00

63 lines
1.5 KiB
JavaScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
import {ipcRenderer} from 'electron';
import type {Store} from '../reducers/index.js';
import type Logger from '../fb-stubs/Logger.js';
export default (store: Store, logger: Logger) => {
let droppedFrames: number = 0;
function droppedFrameDetection(
past: DOMHighResTimeStamp,
isWindowFocused: () => boolean,
) {
const now = performance.now();
requestAnimationFrame(() => droppedFrameDetection(now, isWindowFocused));
const dropped = Math.round((now - past) / (1000 / 60) - 1);
if (dropped > 0 && isWindowFocused()) {
droppedFrames += dropped;
}
}
droppedFrameDetection(
performance.now(),
() => store.getState().application.windowIsFocused,
);
ipcRenderer.on('trackUsage', () => {
const {
selectedDevice,
selectedPlugin,
selectedApp,
clients,
} = store.getState().connections;
if (!selectedDevice || !selectedPlugin) {
return;
}
const info = {
droppedFrames,
os: selectedDevice.os,
device: selectedDevice.title,
plugin: selectedPlugin,
};
// reset dropped frames counter
droppedFrames = 0;
if (selectedApp) {
const client = clients.find((c: Client) => c.id === selectedApp);
if (client) {
// $FlowFixMe
info.app = client.query.app;
}
}
logger.track('usage', 'ping', info);
});
};