From 1f78da881e9703c7f56eb041ebba5558738b9a59 Mon Sep 17 00:00:00 2001 From: Andrey Goncharov Date: Thu, 13 Oct 2022 03:40:51 -0700 Subject: [PATCH] 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 --- desktop/flipper-ui-core/src/utils/messageQueue.tsx | 6 +++++- desktop/flipper-ui-core/src/utils/pluginStats.tsx | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/desktop/flipper-ui-core/src/utils/messageQueue.tsx b/desktop/flipper-ui-core/src/utils/messageQueue.tsx index 0dcb03aa2..8c6470a06 100644 --- a/desktop/flipper-ui-core/src/utils/messageQueue.tsx +++ b/desktop/flipper-ui-core/src/utils/messageQueue.tsx @@ -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}`, diff --git a/desktop/flipper-ui-core/src/utils/pluginStats.tsx b/desktop/flipper-ui-core/src/utils/pluginStats.tsx index f5462426c..730b2869c 100644 --- a/desktop/flipper-ui-core/src/utils/pluginStats.tsx +++ b/desktop/flipper-ui-core/src/utils/pluginStats.tsx @@ -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, ); } }