Usage track now internal to tracking

Summary:
Usage tracking comes from Electron's `main.tsx`. There's a timer that dispatches an IPC event every 60 seconds.

This is all good for Electron builds.

For non-electron builds, there's no such thing as IPC.

So, react to the IPC event whenever necessary but also handle the interval internally such that usage is tracked independently of explicit callers.

Reviewed By: antonk52

Differential Revision: D47053404

fbshipit-source-id: f17694e65eed18678b45a2e815813bafab69c3f1
This commit is contained in:
Lorenzo Blasa
2023-06-27 07:17:06 -07:00
committed by Facebook GitHub Bot
parent fe12a908fb
commit dac8c5b213
2 changed files with 9 additions and 11 deletions

View File

@@ -71,7 +71,6 @@ export function emitBytesReceived(plugin: string, bytes: number) {
bytesReceivedEmitter.emit('bytesReceived', plugin, bytes);
}
}
export default (store: Store, logger: Logger) => {
const renderHost = getRenderHostInstance();
sideEffect(
@@ -142,12 +141,14 @@ export default (store: Store, logger: Logger) => {
);
}
renderHost.onIpcEvent('trackUsage', (...args: any[]) => {
const trackUsage = (...args: any[]) => {
let state: State;
try {
state = store.getState();
} catch (e) {
// if trackUsage is called (indirectly) through a reducer, this will utterly die Flipper. Let's prevent that and log an error instead
// If trackUsage is called (indirectly) through a reducer,
// this will utterly kill Flipper.
// Let's prevent that and log an error instead.
console.error(
'trackUsage triggered indirectly as side effect of a reducer',
e,
@@ -241,7 +242,11 @@ export default (store: Store, logger: Logger) => {
largeFrameDrops = 0;
logger.track('usage', 'ping', info);
});
};
renderHost.onIpcEvent('trackUsage', trackUsage);
setInterval(trackUsage, 60 * 1000);
};
export function computeUsageSummary(