Fix background plugin stats

Summary: Discovered that all gathered plugin stats where empty due to mis-using Object.entries. Fixed that. Also added a accumulated cpuTime metric, which should be great for a uniform trend line.

Reviewed By: jknoxville

Differential Revision: D19517279

fbshipit-source-id: a6df83eea000a5d59fe692a3795fd58ae6457821
This commit is contained in:
Michel Weststrate
2020-01-23 01:41:13 -08:00
committed by Facebook Github Bot
parent d31ea742f5
commit a9f2b67874

View File

@@ -38,14 +38,23 @@ export function resetPluginBackgroundStatsDelta() {
}); });
} }
export function getPluginBackgroundStats(): {[plugin: string]: StatEntry} { export function getPluginBackgroundStats(): {
return Array.from(Object.entries(pluginBackgroundStats)).reduce( cpuTime: number; // amount of ms cpu used since the last stats (typically every minute)
byPlugin: {[plugin: string]: StatEntry};
} {
let cpuTime: number = 0;
const byPlugin = Array.from(pluginBackgroundStats.entries()).reduce(
(aggregated, [pluginName, data]) => { (aggregated, [pluginName, data]) => {
cpuTime += data.cpuTimeDelta;
aggregated[pluginName] = data; aggregated[pluginName] = data;
return aggregated; return aggregated;
}, },
{} as {[plugin: string]: StatEntry}, {} as {[plugin: string]: StatEntry},
); );
return {
cpuTime,
byPlugin,
};
} }
if (window) { if (window) {