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:
committed by
Facebook GitHub Bot
parent
7fdcbdcd59
commit
8b75e81da5
@@ -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 (
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user