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
This commit is contained in:
Michel Weststrate
2020-04-16 03:19:04 -07:00
committed by Facebook GitHub Bot
parent 7fdcbdcd59
commit 8b75e81da5
2 changed files with 21 additions and 3 deletions

View File

@@ -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(); resetPluginBackgroundStatsDelta();
if ( if (

View File

@@ -54,12 +54,15 @@ onBytesReceived((plugin: string, bytes: number) => {
export function getPluginBackgroundStats(): { export function getPluginBackgroundStats(): {
cpuTime: number; // amount of ms cpu used since the last stats (typically every minute) cpuTime: number; // amount of ms cpu used since the last stats (typically every minute)
bytesReceived: number;
byPlugin: {[plugin: string]: StatEntry}; byPlugin: {[plugin: string]: StatEntry};
} { } {
let cpuTime: number = 0; let cpuTime: number = 0;
let bytesReceived: number = 0;
const byPlugin = Array.from(pluginBackgroundStats.entries()).reduce( const byPlugin = Array.from(pluginBackgroundStats.entries()).reduce(
(aggregated, [pluginName, data]) => { (aggregated, [pluginName, data]) => {
cpuTime += data.cpuTimeDelta; cpuTime += data.cpuTimeDelta;
bytesReceived += data.bytesReceivedDelta;
aggregated[pluginName] = data; aggregated[pluginName] = data;
return aggregated; return aggregated;
}, },
@@ -67,6 +70,7 @@ export function getPluginBackgroundStats(): {
); );
return { return {
cpuTime, cpuTime,
bytesReceived,
byPlugin, byPlugin,
}; };
} }
@@ -140,7 +144,6 @@ function processMessage(
}, },
message: {method: string; params?: any}, message: {method: string; params?: any},
): State { ): State {
const statName = `${plugin.id}.${message.method}`;
const reducerStartTime = Date.now(); const reducerStartTime = Date.now();
flipperRecorderAddEvent(pluginKey, message.method, message.params); flipperRecorderAddEvent(pluginKey, message.method, message.params);
try { try {
@@ -149,7 +152,7 @@ function processMessage(
message.method, message.method,
message.params, message.params,
); );
addBackgroundStat(statName, Date.now() - reducerStartTime); addBackgroundStat(plugin.id, Date.now() - reducerStartTime);
return newPluginState; return newPluginState;
} catch (e) { } catch (e) {
console.error(`Failed to process event for plugin ${plugin.id}`, e); console.error(`Failed to process event for plugin ${plugin.id}`, e);