mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
add statistics logging
Signed-off-by: Vishwas Shashidhar <vishwas.shashidhar@symphony.com> # Conflicts: # src/app/config-handler.ts
This commit is contained in:
parent
2743d1ba96
commit
e7f1afd499
@ -3,7 +3,9 @@ import * as path from 'path';
|
||||
import * as shellPath from 'shell-path';
|
||||
|
||||
import { isDevEnv, isMac } from '../common/env';
|
||||
import { logger } from '../common/logger';
|
||||
import { getCommandLineArgs } from '../common/utils';
|
||||
import { appStats } from './stats';
|
||||
|
||||
// Handle custom user data path from process.argv
|
||||
const userDataPathArg: string | null = getCommandLineArgs(process.argv, '--userDataPath=', false);
|
||||
@ -12,13 +14,18 @@ const userDataPath = userDataPathArg && userDataPathArg.substring(userDataPathAr
|
||||
// Set user data path before app ready event
|
||||
if (isDevEnv) {
|
||||
const appDataPath = app.getPath('appData');
|
||||
logger.info(`init: Setting app data path to ${appDataPath}`);
|
||||
app.setPath('userData', path.join(appDataPath, 'Symphony-dev'));
|
||||
}
|
||||
|
||||
if (userDataPath) {
|
||||
logger.info(`init: Setting user data path to ${userDataPath}`);
|
||||
app.setPath('userData', userDataPath);
|
||||
}
|
||||
|
||||
// Log app statistics
|
||||
appStats.logStats();
|
||||
|
||||
// Setting the env path child_process issue https://github.com/electron/electron/issues/7688
|
||||
(async () => {
|
||||
try {
|
||||
|
120
src/app/stats.ts
Normal file
120
src/app/stats.ts
Normal file
@ -0,0 +1,120 @@
|
||||
import { app } from 'electron';
|
||||
import * as os from 'os';
|
||||
import { logger } from '../common/logger';
|
||||
import { config } from './config-handler';
|
||||
|
||||
export class AppStats {
|
||||
|
||||
private MB_IN_BYTES = 1048576;
|
||||
|
||||
/**
|
||||
* Logs all statistics of the app
|
||||
*/
|
||||
public logStats() {
|
||||
this.logSystemStats();
|
||||
this.logProcessInfo();
|
||||
this.logGPUStats();
|
||||
this.logAppMetrics();
|
||||
this.logConfigurationData();
|
||||
this.logAppEvents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs system related statistics
|
||||
*/
|
||||
private logSystemStats() {
|
||||
logger.info(`stats: -----------------Gathering system information-----------------`);
|
||||
logger.info( `Network Info -> ${JSON.stringify(os.networkInterfaces())}`);
|
||||
logger.info( `CPU Info -> ${JSON.stringify(os.cpus())}`);
|
||||
logger.info( `Operating System -> ${JSON.stringify(os.type())}`);
|
||||
logger.info( `Platform -> ${JSON.stringify(os.platform())}`);
|
||||
logger.info( `Architecture -> ${JSON.stringify(os.arch())}`);
|
||||
logger.info( `Hostname -> ${JSON.stringify(os.hostname())}`);
|
||||
logger.info( `Temp Directory -> ${JSON.stringify(os.tmpdir())}`);
|
||||
logger.info( `Home Directory -> ${JSON.stringify(os.homedir())}`);
|
||||
logger.info( `Total Memory (MB) -> ${JSON.stringify(os.totalmem() / this.MB_IN_BYTES)}`);
|
||||
logger.info( `Free Memory (MB) -> ${JSON.stringify(os.freemem() / this.MB_IN_BYTES)}`);
|
||||
logger.info( `Load Average -> ${JSON.stringify(os.loadavg())}`);
|
||||
logger.info( `Uptime -> ${JSON.stringify(os.uptime())}`);
|
||||
logger.info( `User Info (OS Returned) -> ${JSON.stringify(os.userInfo())}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs GPU Statistics
|
||||
*/
|
||||
private logGPUStats() {
|
||||
logger.info( `-----------------Gathering GPU information-----------------`);
|
||||
logger.info( `GPU Feature Status -> ${JSON.stringify(app.getGPUFeatureStatus())}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs Configuration Data
|
||||
*/
|
||||
private logConfigurationData() {
|
||||
const configItems = [
|
||||
'url', 'minimizeOnClose', 'launchOnStartup', 'alwaysOnTop', 'bringToFront', 'whitelistUrl',
|
||||
'isCustomTitleBar', 'memoryRefresh', 'devToolsEnabled', 'ctWhitelist', 'configVersion',
|
||||
'buildNumber', 'autoLaunchPath', 'notificationSettings', 'permissions', 'customFlags',
|
||||
'crashReporter', 'mainWinPos',
|
||||
];
|
||||
|
||||
logger.info(`stats: -----------------App Configuration Information-----------------`);
|
||||
logger.info(`stats: Is app packaged? ${app.isPackaged}`);
|
||||
|
||||
const globalConfiguration = config.getGlobalConfigFields(configItems);
|
||||
logger.info(`stats: Global configuration: ${JSON.stringify(globalConfiguration)}`);
|
||||
|
||||
const userConfiguration = config.getUserConfigFields(configItems);
|
||||
logger.info(`stats: -----------------Gathering User Configuration Information-----------------`);
|
||||
logger.info(`stats: User configuration: ${JSON.stringify(userConfiguration)}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs App metrics
|
||||
*/
|
||||
private logAppMetrics() {
|
||||
logger.info(`stats: -----------------Gathering App Metrics-----------------`);
|
||||
const metrics = app.getAppMetrics();
|
||||
metrics.forEach((metric) => {
|
||||
logger.info(`stats: PID -> ${metric.pid}, Type -> ${metric.type}, CPU Usage -> ${JSON.stringify(metric.cpu)}`);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs App events as they occur dynamically
|
||||
*/
|
||||
private logAppEvents() {
|
||||
const events = [
|
||||
'will-finish-launching', 'ready', 'window-all-closed', 'before-quit', 'will-quit', 'quit',
|
||||
'open-file', 'open-url', 'activate',
|
||||
'browser-window-created', 'web-contents-created', 'certificate-error', 'login', 'gpu-process-crashed',
|
||||
'accessibility-support-changed', 'session-created', 'second-instance',
|
||||
];
|
||||
|
||||
events.forEach((appEvent: any) => {
|
||||
app.on(appEvent, () => {
|
||||
logger.info(`stats: App Event Occurred: ${appEvent}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs process info
|
||||
*/
|
||||
private logProcessInfo() {
|
||||
logger.info(`stats: Is default app? ${process.defaultApp}`);
|
||||
logger.info(`stats: Is Mac Store app? ${process.mas}`);
|
||||
logger.info(`stats: Is Windows Store app? ${process.windowsStore}`);
|
||||
logger.info(`stats: Resources Path? ${process.resourcesPath}`);
|
||||
logger.info(`stats: Sandboxed? ${process.sandboxed}`);
|
||||
logger.info(`stats: Chrome Version? ${process.versions.chrome}`);
|
||||
logger.info(`stats: Electron Version? ${process.versions.electron}`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const appStats = new AppStats();
|
||||
|
||||
export {
|
||||
appStats,
|
||||
};
|
5
types/shell-path.d.ts
vendored
Normal file
5
types/shell-path.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
export = index;
|
||||
declare function index(): void;
|
||||
declare namespace index {
|
||||
function sync(): void;
|
||||
}
|
Loading…
Reference in New Issue
Block a user