Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop: add plugin resources monitor #10629

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5544fed
feat: add os process id to plugin, declare functions for resource mon…
DarkFalc0n Jun 17, 2024
16c4bb5
Merge branch 'plugin-monitor-dev' of https://github.com/DarkFalc0n/jo…
DarkFalc0n Jun 17, 2024
4dc6cbe
Merge branch 'laurent22:dev' into plugin-monitor-dev
DarkFalc0n Jun 22, 2024
99d9640
Merge branch 'laurent22:dev' into plugin-monitor-dev
DarkFalc0n Jun 24, 2024
d5cccdb
Merge branch 'laurent22:dev' into plugin-monitor-dev
DarkFalc0n Jun 25, 2024
255a7ef
feat: create resource monitor instance at app root, add class definit…
DarkFalc0n Jun 25, 2024
cabe41c
Merge branch 'laurent22:dev' into plugin-monitor-dev
DarkFalc0n Jun 27, 2024
30db10f
Merge branch 'laurent22:dev' into plugin-monitor-dev
DarkFalc0n Jul 1, 2024
d7172aa
feat: add Plugin Monitor to menu
DarkFalc0n Jul 7, 2024
1e4b74b
Merge branch 'laurent22:dev' into plugin-monitor-dev
DarkFalc0n Jul 7, 2024
adedc09
Merge branch 'plugin-monitor-dev' of https://github.com/DarkFalc0n/jo…
DarkFalc0n Jul 7, 2024
d58e6ac
feat: add monitor window using reactportal
DarkFalc0n Jul 10, 2024
903878b
Merge branch 'laurent22:dev' into plugin-monitor-dev
DarkFalc0n Jul 10, 2024
558ea55
Merge pull request #1 from DarkFalc0n/plugin-monitor-ui
DarkFalc0n Jul 10, 2024
3d524fc
chore: remove unused deps
DarkFalc0n Jul 10, 2024
446ebf8
Merge branch 'laurent22:dev' into plugin-monitor-dev
DarkFalc0n Jul 13, 2024
b1c7521
feat: add ui changes and scss
DarkFalc0n Jul 13, 2024
3232997
feat: add accelerator
DarkFalc0n Jul 13, 2024
e653996
Merge branch 'plugin-monitor-dev' of https://github.com/DarkFalc0n/jo…
DarkFalc0n Jul 13, 2024
951b999
Merge branch 'laurent22:dev' into plugin-monitor-dev
DarkFalc0n Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add Plugin Monitor to menu
  • Loading branch information
DarkFalc0n committed Jul 7, 2024
commit d7172aad080ad4ee3c1febaf501bf3231cade2bf
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ packages/app-desktop/gui/NotyfContext.js
packages/app-desktop/gui/OneDriveLoginScreen.js
packages/app-desktop/gui/PasswordInput/PasswordInput.js
packages/app-desktop/gui/PdfViewer.js
packages/app-desktop/gui/PluginMonitorScreen.js
packages/app-desktop/gui/PromptDialog.js
packages/app-desktop/gui/ResizableLayout/MoveButtons.js
packages/app-desktop/gui/ResizableLayout/ResizableLayout.js
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ packages/app-desktop/gui/NotyfContext.js
packages/app-desktop/gui/OneDriveLoginScreen.js
packages/app-desktop/gui/PasswordInput/PasswordInput.js
packages/app-desktop/gui/PdfViewer.js
packages/app-desktop/gui/PluginMonitorScreen.js
packages/app-desktop/gui/PromptDialog.js
packages/app-desktop/gui/ResizableLayout/MoveButtons.js
packages/app-desktop/gui/ResizableLayout/ResizableLayout.js
Expand Down
18 changes: 18 additions & 0 deletions packages/app-desktop/app.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface AppState extends State {
mainLayout: LayoutItem;
dialogs: AppStateDialog[];
isResettingLayout: boolean;
isPluginMonitorOpen: boolean;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
Expand All @@ -76,6 +77,7 @@ export function createAppDefaultState(windowContentSize: any, resourceEditWatche
startupPluginsLoaded: false,
dialogs: [],
isResettingLayout: false,
isPluginMonitorOpen: false,
...resourceEditWatcherDefaultState,
};
}
Expand Down Expand Up @@ -344,6 +346,22 @@ export default function(state: AppState, action: any) {
};
break;

case 'PLUGIN_MONITOR_OPEN':
case 'PLUGIN_MONITOR_CLOSE':
{
if (action.type === 'PLUGIN_MONITOR_OPEN') {
newState = {
...state,
isPluginMonitorOpen: true,
};
} else {
newState = {
...state,
isPluginMonitorOpen: false,
};
}
}
break;
}

} catch (error) {
Expand Down
12 changes: 11 additions & 1 deletion packages/app-desktop/gui/MenuBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,16 @@ function useMenu(props: Props) {
});
},
},
separator(),
{
label: _('Plugin Monitor'),
// todo: add accelerator
click: () => {
props.dispatch({
type: 'NAV_GO',
routeName: 'PluginMonitor',
});
},
},
];

// the following menu items will be available for all OS under Tools
Expand All @@ -574,6 +583,7 @@ function useMenu(props: Props) {

toolsItems.push(SpellCheckerService.instance().spellCheckerConfigMenuItem(props['spellChecker.languages'], props['spellChecker.enabled']));


function _checkForUpdates() {
void checkForUpdates(false, bridge().window(), { includePreReleases: Setting.value('autoUpdate.includePreReleases') });
}
Expand Down
1 change: 1 addition & 0 deletions packages/app-desktop/gui/Navigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class NavigatorComponent extends React.Component<Props> {
const Navigator = connect((state: AppState) => {
return {
route: state.route,
isPluginMonitorOpen: state.isPluginMonitorOpen,
};
})(NavigatorComponent);

Expand Down
74 changes: 74 additions & 0 deletions packages/app-desktop/gui/PluginMonitorScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as React from 'react';

const { connect } = require('react-redux');
import { PluginResourceData, PluginResourceMonitor } from '../services/plugins/PluginResourceMonitor';
import { AppState } from '../app.reducer';
const { themeStyle } = require('@joplin/lib/theme');
import PluginService from '@joplin/lib/services/plugins/PluginService';

interface Props {
themeId: string;
}

interface PluginData {
osPid: number;
name: string;
memory: number;
peakMemory: number;
cpu: number;
runningStatus: boolean;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
class PluginMonitorScreen extends React.Component<any, any> {
public constructor(props: Props) {
super(props);

this.state = {
pluginData: [],
};
}

public async componentDidMount() {
PluginResourceMonitor.instance().ResourceMonitorGUIUpdate = this.updatePluginData.bind(this);
}

public updatePluginData(pluginData: PluginResourceData) {
const plugins = PluginService.instance().plugins;
const data: PluginData[] = [];
for (const plugin in plugins) {
const osPid = plugins[plugin].osPid;
data.push({
osPid,
name: plugins[plugin].manifest.name,
memory: pluginData[osPid].memory,
peakMemory: pluginData[osPid].peakMemory,
cpu: pluginData[osPid].cpu,
runningStatus: plugins[plugin].running,
});
}

this.setState({ pluginData: data });
}

public render() {
const theme = themeStyle(this.props.themeId);

return (
<div style={{ display: 'flex', flexDirection: 'column', height: '100%', backgroundColor: theme.backgroundColor }}>
<div style={{ padding: theme.configScreenPadding, flex: 1, color: theme.color }}>
{JSON.stringify(this.state.pluginData)}
</div>
</div>
);
}
}

const mapStateToProps = (state: AppState) => {
return {
themeId: state.settings.theme,
};
};

export default connect(mapStateToProps)(PluginMonitorScreen);

2 changes: 2 additions & 0 deletions packages/app-desktop/gui/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const { ResourceScreen } = require('./ResourceScreen.js');
import Navigator from './Navigator';
import WelcomeUtils from '@joplin/lib/WelcomeUtils';
import JoplinCloudLoginScreen from './JoplinCloudLoginScreen';
import PluginMonitorScreen from './PluginMonitorScreen';
const { ThemeProvider, StyleSheetManager, createGlobalStyle } = require('styled-components');
const bridge = require('@electron/remote').require('./bridge').default;

Expand Down Expand Up @@ -232,6 +233,7 @@ class RootComponent extends React.Component<Props, any> {
Config: { screen: ConfigScreen, title: () => _('Options') },
Resources: { screen: ResourceScreen, title: () => _('Note attachments') },
Status: { screen: StatusScreen, title: () => _('Synchronisation Status') },
PluginMonitor: { screen: PluginMonitorScreen, title: () => _('Plugin Monitor') },
};

return (
Expand Down
15 changes: 13 additions & 2 deletions packages/app-desktop/services/plugins/PluginResourceMonitor.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import bridge from '../bridge';

export interface ResourceMetric {
export interface PluginResourceMetric {
memory: number;
peakMemory: number;
cpu: number;
}

export interface PluginResourceData {
[key: string]: PluginResourceMetric;
}

export class PluginResourceMonitor {

private static instance_: PluginResourceMonitor = null;
Expand All @@ -19,13 +23,15 @@ export class PluginResourceMonitor {
}

private intervalId_: ReturnType<typeof setTimeout>;
private resourceMetrics_: { [key: string]: ResourceMetric };
private resourceMetrics_: PluginResourceData;

public constructor() {
this.intervalId_ = null;
this.resourceMetrics_ = {};
}

public ResourceMonitorGUIUpdate: (resourceMetrics: PluginResourceData)=> void | null = null;

private startResourceMonitor() {
this.intervalId_ = setInterval(() => {

Expand All @@ -38,6 +44,10 @@ export class PluginResourceMonitor {
cpu: metric.cpu.percentCPUUsage,
};
}

if (this.ResourceMonitorGUIUpdate) {
this.ResourceMonitorGUIUpdate(this.resourceMetrics_);
}
}, 5000);
}

Expand All @@ -58,4 +68,5 @@ export class PluginResourceMonitor {
public async stop() {
this.stopResourceMonitor();
}

}