This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 954
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Added a warning on top of plugin list when queued message consumption passes a threshold. This is designed to make users aware of the resource use of background plugins Reviewed By: antonk52 Differential Revision: D57904618 fbshipit-source-id: b5514826c53c477407f1b1f13350c874d884d267
- Loading branch information
1 parent
4c79bc8
commit 173134d
Showing
6 changed files
with
85 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
desktop/flipper-ui/src/sandy-chrome/appinspect/PluginMemoryWarning.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
*/ | ||
|
||
import {WarningOutlined} from '@ant-design/icons'; | ||
import {Button} from 'antd'; | ||
import {Layout, theme} from 'flipper-plugin'; | ||
import {getStore} from 'flipper-ui/src/store'; | ||
import React, {useEffect, useState} from 'react'; | ||
|
||
const PluginQueueMemoryUsageScanInterval = 2500; | ||
|
||
export function PluginMemoryWarning() { | ||
const [_, rerender] = useState(0); | ||
|
||
useEffect(() => { | ||
const handle = setInterval(() => { | ||
rerender((x) => x + 1); | ||
}, PluginQueueMemoryUsageScanInterval); | ||
|
||
return () => { | ||
clearInterval(handle); | ||
}; | ||
}, []); | ||
|
||
const totalSizeMb = getQueuedMessagedConsumption(); | ||
|
||
if (totalSizeMb < 50) { | ||
return null; | ||
} | ||
|
||
const color = totalSizeMb < 150 ? theme.warningColor : theme.errorColor; | ||
|
||
return ( | ||
<Layout.Container pad="small"> | ||
<Button | ||
style={{padding: 4}} | ||
type="ghost" | ||
icon={ | ||
<WarningOutlined style={{color, fontSize: theme.fontSize.large}} /> | ||
}> | ||
{totalSizeMb.toFixed(0)}Mb queued messages | ||
</Button> | ||
</Layout.Container> | ||
); | ||
} | ||
|
||
function getQueuedMessagedConsumption() { | ||
const messageQueues = getStore().getState().pluginMessageQueue; | ||
let totalSize = 0; | ||
for (const queue of Object.values(messageQueues)) { | ||
for (const message of queue) { | ||
totalSize += message.rawSize; | ||
} | ||
} | ||
|
||
const totalSizeMb = totalSize / 1000000; | ||
return totalSizeMb; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters