Improve stats collection for plugins in the background
Summary: This diff improves two things: 1. Stats are now gathered on every `trackUsage` tick, rather than only when there is a selection 2. The stats now include a delta to compare it with the previous tick Reviewed By: passy Differential Revision: D19514231 fbshipit-source-id: 1854c1dc03c63a03db8c7040c185d2629e1b9ea2
This commit is contained in:
committed by
Facebook Github Bot
parent
c8b9dd949b
commit
a3a3db5363
@@ -13,7 +13,10 @@ import {performance} from 'perf_hooks';
|
|||||||
import {Store} from '../reducers/index';
|
import {Store} from '../reducers/index';
|
||||||
import {Logger} from '../fb-interfaces/Logger';
|
import {Logger} from '../fb-interfaces/Logger';
|
||||||
import Client from '../Client';
|
import Client from '../Client';
|
||||||
import {getPluginBackgroundStats} from '../utils/messageQueue';
|
import {
|
||||||
|
getPluginBackgroundStats,
|
||||||
|
resetPluginBackgroundStatsDelta,
|
||||||
|
} from '../utils/messageQueue';
|
||||||
import {
|
import {
|
||||||
clearTimeline,
|
clearTimeline,
|
||||||
TrackingEvent,
|
TrackingEvent,
|
||||||
@@ -90,6 +93,9 @@ export default (store: Store, logger: Logger) => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
logger.track('usage', 'plugin-stats', getPluginBackgroundStats());
|
||||||
|
resetPluginBackgroundStatsDelta();
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!state.application.windowIsFocused ||
|
!state.application.windowIsFocused ||
|
||||||
!selectedDevice ||
|
!selectedDevice ||
|
||||||
@@ -115,7 +121,6 @@ export default (store: Store, logger: Logger) => {
|
|||||||
os: selectedDevice.os,
|
os: selectedDevice.os,
|
||||||
device: selectedDevice.title,
|
device: selectedDevice.title,
|
||||||
plugin: selectedPlugin,
|
plugin: selectedPlugin,
|
||||||
pluginStats: getPluginBackgroundStats(),
|
|
||||||
app,
|
app,
|
||||||
sdkVersion,
|
sdkVersion,
|
||||||
isForeground: state.application.windowIsFocused,
|
isForeground: state.application.windowIsFocused,
|
||||||
|
|||||||
@@ -22,13 +22,22 @@ import {pluginIsStarred, getSelectedPluginKey} from '../reducers/connections';
|
|||||||
const MAX_BACKGROUND_TASK_TIME = 25;
|
const MAX_BACKGROUND_TASK_TIME = 25;
|
||||||
|
|
||||||
type StatEntry = {
|
type StatEntry = {
|
||||||
cpuTime: number; // Total time spend in persisted Reducer
|
cpuTimeTotal: number; // Total time spend in persisted Reducer
|
||||||
messages: number; // amount of message received for this plugin
|
cpuTimeDelta: number; // Time spend since previous tracking tick
|
||||||
|
messageCountTotal: number; // amount of message received for this plugin
|
||||||
|
messageCountDelta: number; // amout of messages received since previous tracking tick
|
||||||
maxTime: number; // maximum time spend in a single reducer call
|
maxTime: number; // maximum time spend in a single reducer call
|
||||||
};
|
};
|
||||||
|
|
||||||
const pluginBackgroundStats = new Map<string, StatEntry>();
|
const pluginBackgroundStats = new Map<string, StatEntry>();
|
||||||
|
|
||||||
|
export function resetPluginBackgroundStatsDelta() {
|
||||||
|
pluginBackgroundStats.forEach(stat => {
|
||||||
|
stat.cpuTimeDelta = 0;
|
||||||
|
stat.messageCountDelta = 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function getPluginBackgroundStats(): {[plugin: string]: StatEntry} {
|
export function getPluginBackgroundStats(): {[plugin: string]: StatEntry} {
|
||||||
return Array.from(Object.entries(pluginBackgroundStats)).reduce(
|
return Array.from(Object.entries(pluginBackgroundStats)).reduce(
|
||||||
(aggregated, [pluginName, data]) => {
|
(aggregated, [pluginName, data]) => {
|
||||||
@@ -44,10 +53,21 @@ if (window) {
|
|||||||
window.flipperPrintPluginBackgroundStats = () => {
|
window.flipperPrintPluginBackgroundStats = () => {
|
||||||
console.table(
|
console.table(
|
||||||
Array.from(pluginBackgroundStats.entries()).map(
|
Array.from(pluginBackgroundStats.entries()).map(
|
||||||
([plugin, {cpuTime, messages, maxTime}]) => ({
|
([
|
||||||
plugin,
|
plugin,
|
||||||
cpuTime,
|
{
|
||||||
messages,
|
cpuTimeDelta,
|
||||||
|
cpuTimeTotal,
|
||||||
|
messageCountDelta,
|
||||||
|
messageCountTotal,
|
||||||
|
maxTime,
|
||||||
|
},
|
||||||
|
]) => ({
|
||||||
|
plugin,
|
||||||
|
cpuTimeTotal,
|
||||||
|
messageCountTotal,
|
||||||
|
cpuTimeDelta,
|
||||||
|
messageCountDelta,
|
||||||
maxTime,
|
maxTime,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -57,11 +77,19 @@ if (window) {
|
|||||||
|
|
||||||
function addBackgroundStat(plugin: string, cpuTime: number) {
|
function addBackgroundStat(plugin: string, cpuTime: number) {
|
||||||
if (!pluginBackgroundStats.has(plugin)) {
|
if (!pluginBackgroundStats.has(plugin)) {
|
||||||
pluginBackgroundStats.set(plugin, {cpuTime: 0, messages: 0, maxTime: 0});
|
pluginBackgroundStats.set(plugin, {
|
||||||
|
cpuTimeDelta: 0,
|
||||||
|
cpuTimeTotal: 0,
|
||||||
|
messageCountDelta: 0,
|
||||||
|
messageCountTotal: 0,
|
||||||
|
maxTime: 0,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const stat = pluginBackgroundStats.get(plugin)!;
|
const stat = pluginBackgroundStats.get(plugin)!;
|
||||||
stat.cpuTime += cpuTime;
|
stat.cpuTimeDelta += cpuTime;
|
||||||
stat.messages += 1;
|
stat.cpuTimeTotal += cpuTime;
|
||||||
|
stat.messageCountDelta += 1;
|
||||||
|
stat.messageCountTotal += 1;
|
||||||
stat.maxTime = Math.max(stat.maxTime, cpuTime);
|
stat.maxTime = Math.max(stat.maxTime, cpuTime);
|
||||||
if (cpuTime > MAX_BACKGROUND_TASK_TIME) {
|
if (cpuTime > MAX_BACKGROUND_TASK_TIME) {
|
||||||
console.warn(
|
console.warn(
|
||||||
|
|||||||
Reference in New Issue
Block a user