Enhance a warning about taking too much time to process plugin messages

Summary:
Without seeing the specific messages it might be hard to debug what is taking so long.

CHANGELOG: Enhance a warning about taking too much time to process plugin messages

Differential Revision: D40340272

fbshipit-source-id: a4dbd639cf389763a3cb00a190216c0e653c08e4
This commit is contained in:
Andrey Goncharov
2022-10-13 03:40:51 -07:00
committed by Facebook GitHub Bot
parent b5a750935d
commit 1f78da881e
2 changed files with 12 additions and 2 deletions

View File

@@ -29,7 +29,11 @@ function processMessagesImmediately(
const reducerStartTime = Date.now();
try {
plugin.receiveMessages(messages);
addBackgroundStat(plugin.definition.id, Date.now() - reducerStartTime);
addBackgroundStat(
plugin.definition.id,
messages,
Date.now() - reducerStartTime,
);
} catch (e) {
console.error(
`Failed to process event for plugin ${plugin.definition.id}`,

View File

@@ -8,6 +8,7 @@
*/
import {onBytesReceived} from '../dispatcher/tracking';
import {Message} from '../reducers/pluginMessageQueue';
type StatEntry = {
cpuTimeTotal: number; // Total time spend in persisted Reducer
@@ -105,7 +106,11 @@ function createEmptyStat(): StatEntry {
};
}
export function addBackgroundStat(plugin: string, cpuTime: number) {
export function addBackgroundStat(
plugin: string,
messages: Message[],
cpuTime: number,
) {
if (!pluginBackgroundStats.has(plugin)) {
pluginBackgroundStats.set(plugin, createEmptyStat());
}
@@ -118,6 +123,7 @@ export function addBackgroundStat(plugin: string, cpuTime: number) {
if (cpuTime > MAX_BACKGROUND_TASK_TIME) {
console.warn(
`Plugin ${plugin} took too much time while doing background: ${cpuTime}ms. Handling background messages should take less than ${MAX_BACKGROUND_TASK_TIME}ms.`,
messages,
);
}
}