mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-01-05 21:54:05 -06:00
feat: Measure cpu (#960)
* Add get-cpu-usage * Fixed indent * . * fixed spelling Co-authored-by: Vishwas Shashidhar <VishwasShashidhar@users.noreply.github.com>
This commit is contained in:
parent
dda87597f1
commit
08c2a3d6c8
@ -36,6 +36,7 @@ export enum apiCmds {
|
||||
getConfigUrl = 'get-config-url',
|
||||
registerRestartFloater = 'register-restart-floater',
|
||||
setCloudConfig = 'set-cloud-config',
|
||||
getCPUUsage = 'get-cpu-usage',
|
||||
checkMediaPermission = 'check-media-permission',
|
||||
}
|
||||
|
||||
@ -145,6 +146,11 @@ export interface IVersionInfo {
|
||||
searchApiVer: string;
|
||||
}
|
||||
|
||||
export interface ICPUUsage {
|
||||
percentCPUUsage: number;
|
||||
idleWakeupsPerSecond: number;
|
||||
}
|
||||
|
||||
export interface IMediaPermission {
|
||||
camera: string;
|
||||
microphone: string;
|
||||
|
@ -143,6 +143,11 @@
|
||||
<button id='bring-to-front'>bring window to front</button>
|
||||
<button id='bring-to-front-without-focus'>bring to front without focus</button>
|
||||
|
||||
<hr>
|
||||
<p>Measure cpu usage:</p>
|
||||
<button id='button-get-cpu-usage'>Get CPU usage</button>
|
||||
<input type="text" id='text-cpu-usage' />
|
||||
|
||||
<hr>
|
||||
<p>Check Media Permission:</p>
|
||||
<button id='check-media-permission'>Check media permission</button>
|
||||
@ -226,6 +231,7 @@
|
||||
notification: 'notification',
|
||||
closeNotification: 'close-notification',
|
||||
registerRestartFloater: 'register-restart-floater',
|
||||
getCPUUsage: 'get-cpu-usage',
|
||||
checkMediaPermission: 'check-media-permission',
|
||||
};
|
||||
let requestId = 0;
|
||||
@ -525,6 +531,10 @@
|
||||
case 'restart-floater-callback':
|
||||
onRestartFloater(data);
|
||||
break;
|
||||
case 'get-cpu-usage-callback':
|
||||
handleResponse(data);
|
||||
console.log(event.data);
|
||||
break;
|
||||
case 'check-media-permission-callback':
|
||||
handleResponse(data);
|
||||
console.log(event.data);
|
||||
@ -628,6 +638,29 @@
|
||||
activityTimer = startActivityInterval();
|
||||
};
|
||||
|
||||
/**
|
||||
* Get CPU usage
|
||||
*/
|
||||
const cpuMeasurement = document.getElementById('button-get-cpu-usage');
|
||||
|
||||
cpuMeasurement.addEventListener('click', () => {
|
||||
console.log('Start measure CPU !!!');
|
||||
|
||||
if (window.ssf) {
|
||||
ssf.getCPUUsage.then((cpuUsage) => {
|
||||
console.log('get-cpu-usage, cpuUsage: ' + JSON.stringify(cpuUsage));
|
||||
document.getElementById('text-cpu-usage').value = cpuUsage.percentCPUUsage;
|
||||
});
|
||||
} else {
|
||||
postRequest(apiCmds.getCPUUsage, null, {
|
||||
successCallback: (cpuUsage) => {
|
||||
console.log('get-cpu-usage, cpuUsage: ' + JSON.stringify(cpuUsage));
|
||||
document.getElementById('text-cpu-usage').value = cpuUsage.percentCPUUsage;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Check media permission
|
||||
*/
|
||||
|
@ -174,6 +174,13 @@ export class AppBridge {
|
||||
ssInstance.handleMessageEvents(data);
|
||||
}
|
||||
break;
|
||||
case apiCmds.getCPUUsage:
|
||||
const cpuUsage = await ssf.getCPUUsage();
|
||||
this.broadcastMessage('get-cpu-usage-callback', {
|
||||
requestId: data.requestId,
|
||||
response: cpuUsage,
|
||||
});
|
||||
break;
|
||||
case apiCmds.checkMediaPermission:
|
||||
const mediaPermission = await ssf.checkMediaPermission();
|
||||
this.broadcastMessage('check-media-permission-callback', {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { ipcRenderer, remote } from 'electron';
|
||||
const os = remote.require('os');
|
||||
|
||||
import { buildNumber, searchAPIVersion } from '../../package.json';
|
||||
import { ICustomBrowserWindow } from '../app/window-handler';
|
||||
import {
|
||||
@ -8,6 +7,7 @@ import {
|
||||
apiName,
|
||||
IBadgeCount,
|
||||
IBoundsChange,
|
||||
ICPUUsage,
|
||||
ILogMsg,
|
||||
IMediaPermission,
|
||||
IRestartFloaterData,
|
||||
@ -487,6 +487,15 @@ export class SSFApi {
|
||||
throttledSetCloudConfig(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* get CPU usage
|
||||
*/
|
||||
public async getCPUUsage(): Promise<ICPUUsage> {
|
||||
return Promise.resolve(
|
||||
await process.getCPUUsage(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check media permission
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user