mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -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',
|
getConfigUrl = 'get-config-url',
|
||||||
registerRestartFloater = 'register-restart-floater',
|
registerRestartFloater = 'register-restart-floater',
|
||||||
setCloudConfig = 'set-cloud-config',
|
setCloudConfig = 'set-cloud-config',
|
||||||
|
getCPUUsage = 'get-cpu-usage',
|
||||||
checkMediaPermission = 'check-media-permission',
|
checkMediaPermission = 'check-media-permission',
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,6 +146,11 @@ export interface IVersionInfo {
|
|||||||
searchApiVer: string;
|
searchApiVer: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ICPUUsage {
|
||||||
|
percentCPUUsage: number;
|
||||||
|
idleWakeupsPerSecond: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IMediaPermission {
|
export interface IMediaPermission {
|
||||||
camera: string;
|
camera: string;
|
||||||
microphone: string;
|
microphone: string;
|
||||||
|
@ -143,6 +143,11 @@
|
|||||||
<button id='bring-to-front'>bring window to front</button>
|
<button id='bring-to-front'>bring window to front</button>
|
||||||
<button id='bring-to-front-without-focus'>bring to front without focus</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>
|
<hr>
|
||||||
<p>Check Media Permission:</p>
|
<p>Check Media Permission:</p>
|
||||||
<button id='check-media-permission'>Check media permission</button>
|
<button id='check-media-permission'>Check media permission</button>
|
||||||
@ -226,6 +231,7 @@
|
|||||||
notification: 'notification',
|
notification: 'notification',
|
||||||
closeNotification: 'close-notification',
|
closeNotification: 'close-notification',
|
||||||
registerRestartFloater: 'register-restart-floater',
|
registerRestartFloater: 'register-restart-floater',
|
||||||
|
getCPUUsage: 'get-cpu-usage',
|
||||||
checkMediaPermission: 'check-media-permission',
|
checkMediaPermission: 'check-media-permission',
|
||||||
};
|
};
|
||||||
let requestId = 0;
|
let requestId = 0;
|
||||||
@ -525,6 +531,10 @@
|
|||||||
case 'restart-floater-callback':
|
case 'restart-floater-callback':
|
||||||
onRestartFloater(data);
|
onRestartFloater(data);
|
||||||
break;
|
break;
|
||||||
|
case 'get-cpu-usage-callback':
|
||||||
|
handleResponse(data);
|
||||||
|
console.log(event.data);
|
||||||
|
break;
|
||||||
case 'check-media-permission-callback':
|
case 'check-media-permission-callback':
|
||||||
handleResponse(data);
|
handleResponse(data);
|
||||||
console.log(event.data);
|
console.log(event.data);
|
||||||
@ -628,6 +638,29 @@
|
|||||||
activityTimer = startActivityInterval();
|
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
|
* Check media permission
|
||||||
*/
|
*/
|
||||||
|
@ -174,6 +174,13 @@ export class AppBridge {
|
|||||||
ssInstance.handleMessageEvents(data);
|
ssInstance.handleMessageEvents(data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case apiCmds.getCPUUsage:
|
||||||
|
const cpuUsage = await ssf.getCPUUsage();
|
||||||
|
this.broadcastMessage('get-cpu-usage-callback', {
|
||||||
|
requestId: data.requestId,
|
||||||
|
response: cpuUsage,
|
||||||
|
});
|
||||||
|
break;
|
||||||
case apiCmds.checkMediaPermission:
|
case apiCmds.checkMediaPermission:
|
||||||
const mediaPermission = await ssf.checkMediaPermission();
|
const mediaPermission = await ssf.checkMediaPermission();
|
||||||
this.broadcastMessage('check-media-permission-callback', {
|
this.broadcastMessage('check-media-permission-callback', {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { ipcRenderer, remote } from 'electron';
|
import { ipcRenderer, remote } from 'electron';
|
||||||
const os = remote.require('os');
|
const os = remote.require('os');
|
||||||
|
|
||||||
import { buildNumber, searchAPIVersion } from '../../package.json';
|
import { buildNumber, searchAPIVersion } from '../../package.json';
|
||||||
import { ICustomBrowserWindow } from '../app/window-handler';
|
import { ICustomBrowserWindow } from '../app/window-handler';
|
||||||
import {
|
import {
|
||||||
@ -8,6 +7,7 @@ import {
|
|||||||
apiName,
|
apiName,
|
||||||
IBadgeCount,
|
IBadgeCount,
|
||||||
IBoundsChange,
|
IBoundsChange,
|
||||||
|
ICPUUsage,
|
||||||
ILogMsg,
|
ILogMsg,
|
||||||
IMediaPermission,
|
IMediaPermission,
|
||||||
IRestartFloaterData,
|
IRestartFloaterData,
|
||||||
@ -487,6 +487,15 @@ export class SSFApi {
|
|||||||
throttledSetCloudConfig(data);
|
throttledSetCloudConfig(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get CPU usage
|
||||||
|
*/
|
||||||
|
public async getCPUUsage(): Promise<ICPUUsage> {
|
||||||
|
return Promise.resolve(
|
||||||
|
await process.getCPUUsage(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check media permission
|
* Check media permission
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user