From 8b75e81da502e6b710698783736fb494a07fefa5 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 16 Apr 2020 03:19:04 -0700 Subject: [PATCH] Make background plugin stats consumable from Scuba Summary: I was trying to plot some graphs based on our background plugin stats, grouped per plugin, but discovered that we can't exploded or group on json object keys, so separated the data into separate `plugin-stats-plugin` events, as is done with the `time-spent` event. Also fixed: * grouping stats per plugin, rather than per plugin method, which was to fine-grained * added `bytesReceived` field to the cumulative event `plugin-stats` Reviewed By: jknoxville Differential Revision: D21046016 fbshipit-source-id: 1043612064921cf6427d5b3bbee10b76776df39e --- desktop/app/src/dispatcher/tracking.tsx | 17 ++++++++++++++++- desktop/app/src/utils/messageQueue.tsx | 7 +++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/desktop/app/src/dispatcher/tracking.tsx b/desktop/app/src/dispatcher/tracking.tsx index 678ad361a..6af7763da 100644 --- a/desktop/app/src/dispatcher/tracking.tsx +++ b/desktop/app/src/dispatcher/tracking.tsx @@ -149,7 +149,22 @@ export default (store: Store, logger: Logger) => { }), ); - logger.track('usage', 'plugin-stats', getPluginBackgroundStats()); + const bgStats = getPluginBackgroundStats(); + logger.track('usage', 'plugin-stats', { + cpuTime: bgStats.cpuTime, + bytesReceived: bgStats.bytesReceived, + }); + for (const key of Object.keys(bgStats.byPlugin)) { + const { + cpuTimeTotal: _a, + messageCountTotal: _b, + bytesReceivedTotal: _c, + ...dataWithoutTotal + } = bgStats.byPlugin[key]; + if (Object.values(dataWithoutTotal).some((v) => v > 0)) { + logger.track('usage', 'plugin-stats-plugin', dataWithoutTotal, key); + } + } resetPluginBackgroundStatsDelta(); if ( diff --git a/desktop/app/src/utils/messageQueue.tsx b/desktop/app/src/utils/messageQueue.tsx index d04e01e74..0ec940bb7 100644 --- a/desktop/app/src/utils/messageQueue.tsx +++ b/desktop/app/src/utils/messageQueue.tsx @@ -54,12 +54,15 @@ onBytesReceived((plugin: string, bytes: number) => { export function getPluginBackgroundStats(): { cpuTime: number; // amount of ms cpu used since the last stats (typically every minute) + bytesReceived: number; byPlugin: {[plugin: string]: StatEntry}; } { let cpuTime: number = 0; + let bytesReceived: number = 0; const byPlugin = Array.from(pluginBackgroundStats.entries()).reduce( (aggregated, [pluginName, data]) => { cpuTime += data.cpuTimeDelta; + bytesReceived += data.bytesReceivedDelta; aggregated[pluginName] = data; return aggregated; }, @@ -67,6 +70,7 @@ export function getPluginBackgroundStats(): { ); return { cpuTime, + bytesReceived, byPlugin, }; } @@ -140,7 +144,6 @@ function processMessage( }, message: {method: string; params?: any}, ): State { - const statName = `${plugin.id}.${message.method}`; const reducerStartTime = Date.now(); flipperRecorderAddEvent(pluginKey, message.method, message.params); try { @@ -149,7 +152,7 @@ function processMessage( message.method, message.params, ); - addBackgroundStat(statName, Date.now() - reducerStartTime); + addBackgroundStat(plugin.id, Date.now() - reducerStartTime); return newPluginState; } catch (e) { console.error(`Failed to process event for plugin ${plugin.id}`, e);