From 5043484d85c1207b79ad52ae20d25d85dce73d6d Mon Sep 17 00:00:00 2001 From: million1156 Date: Fri, 17 Jan 2025 08:32:38 -0600 Subject: [PATCH 01/10] tweak(core): use get-wmi for memory usage --- core/components/StatsManager/svRuntime/perfUtils.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/components/StatsManager/svRuntime/perfUtils.ts b/core/components/StatsManager/svRuntime/perfUtils.ts index 4b302f90d..d344c83b6 100644 --- a/core/components/StatsManager/svRuntime/perfUtils.ts +++ b/core/components/StatsManager/svRuntime/perfUtils.ts @@ -5,6 +5,7 @@ import got from '@core/extras/got.js'; import { parseRawPerf } from './perfParser'; import { PERF_DATA_BUCKET_COUNT } from './config'; import { txEnv } from '@core/globalData'; +import { exec } from 'child_process'; //Consts @@ -108,14 +109,23 @@ export const fetchRawPerfData = async (fxServerHost: string) => { /** * Get the fxserver memory usage - * FIXME: migrate to use gwmi on windows by default */ export const fetchFxsMemory = async (fxsPid?: number) => { if (!fxsPid) return; try { + if (txEnv.isWindows) { + // TODO: Create a way that doesn't involve `exec` + const { stdout } = await exec(`Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE ProcessId = ${fxsPid}" | Select-Object WorkingSetSize`); + if (stdout) { + const stdoutString = stdout.toString(); + const memoryMb = parseInt(stdoutString.split('\n')[1]) / 1024 / 1024; + return parseFloat((memoryMb).toFixed(2)); + } + } else { /* Not running Windows so we can use the normal method */ const pidUsage = await pidusage(fxsPid); const memoryMb = pidUsage.memory / 1024 / 1024; return parseFloat((memoryMb).toFixed(2)); + } } catch (error) { if ((error as any).code = 'ENOENT') { console.error('Failed to get processes tree usage data.'); From 2b1c362d169938685ca75edff93ba074b84bbbc1 Mon Sep 17 00:00:00 2001 From: million1156 Date: Fri, 17 Jan 2025 08:41:01 -0600 Subject: [PATCH 02/10] fix(core): use powershell instead of command prompt --- core/components/StatsManager/svRuntime/perfUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/components/StatsManager/svRuntime/perfUtils.ts b/core/components/StatsManager/svRuntime/perfUtils.ts index d344c83b6..8a864a025 100644 --- a/core/components/StatsManager/svRuntime/perfUtils.ts +++ b/core/components/StatsManager/svRuntime/perfUtils.ts @@ -115,7 +115,7 @@ export const fetchFxsMemory = async (fxsPid?: number) => { try { if (txEnv.isWindows) { // TODO: Create a way that doesn't involve `exec` - const { stdout } = await exec(`Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE ProcessId = ${fxsPid}" | Select-Object WorkingSetSize`); + const { stdout } = await exec(`Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE ProcessId = ${fxsPid}" | Select-Object WorkingSetSize`, { shell: 'powershell.exe' }); if (stdout) { const stdoutString = stdout.toString(); const memoryMb = parseInt(stdoutString.split('\n')[1]) / 1024 / 1024; From bc08812f88a387c8820ba49ad2c4c29696c5406e Mon Sep 17 00:00:00 2001 From: million1156 Date: Fri, 17 Jan 2025 08:41:32 -0600 Subject: [PATCH 03/10] fix(core): revert change for security reasons --- core/components/StatsManager/svRuntime/perfUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/components/StatsManager/svRuntime/perfUtils.ts b/core/components/StatsManager/svRuntime/perfUtils.ts index 8a864a025..89af6325b 100644 --- a/core/components/StatsManager/svRuntime/perfUtils.ts +++ b/core/components/StatsManager/svRuntime/perfUtils.ts @@ -115,7 +115,7 @@ export const fetchFxsMemory = async (fxsPid?: number) => { try { if (txEnv.isWindows) { // TODO: Create a way that doesn't involve `exec` - const { stdout } = await exec(`Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE ProcessId = ${fxsPid}" | Select-Object WorkingSetSize`, { shell: 'powershell.exe' }); + const { stdout } = await exec(`Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE ProcessId = ${fxsPid}" | Select-Object WorkingSetSize`, { shell: 'powershell' }); if (stdout) { const stdoutString = stdout.toString(); const memoryMb = parseInt(stdoutString.split('\n')[1]) / 1024 / 1024; From f381c9287ba63e36e7250767a9275c9cf237dadb Mon Sep 17 00:00:00 2001 From: million1156 Date: Fri, 17 Jan 2025 09:39:54 -0600 Subject: [PATCH 04/10] wip: commit changes --- core/components/StatsManager/svRuntime/obj.ps1 | 4 ++++ core/components/StatsManager/svRuntime/perfUtils.ts | 6 +++--- scripts/main-builder.js | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 core/components/StatsManager/svRuntime/obj.ps1 diff --git a/core/components/StatsManager/svRuntime/obj.ps1 b/core/components/StatsManager/svRuntime/obj.ps1 new file mode 100644 index 000000000..5ecc6f415 --- /dev/null +++ b/core/components/StatsManager/svRuntime/obj.ps1 @@ -0,0 +1,4 @@ + +object = Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE ProcessId = 1196" | Select-Object WorkingSetSize + +object.split = object.WorkingSetSize / 1MB \ No newline at end of file diff --git a/core/components/StatsManager/svRuntime/perfUtils.ts b/core/components/StatsManager/svRuntime/perfUtils.ts index 89af6325b..b6ab5eb8a 100644 --- a/core/components/StatsManager/svRuntime/perfUtils.ts +++ b/core/components/StatsManager/svRuntime/perfUtils.ts @@ -114,11 +114,11 @@ export const fetchFxsMemory = async (fxsPid?: number) => { if (!fxsPid) return; try { if (txEnv.isWindows) { - // TODO: Create a way that doesn't involve `exec` - const { stdout } = await exec(`Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE ProcessId = ${fxsPid}" | Select-Object WorkingSetSize`, { shell: 'powershell' }); + //TODO: Is there a way we don't have to use exec? + const { stdout } = await exec(`Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE ProcessId = ${fxsPid}" | Select-Object -ExpandProperty WorkingSetSize`, { shell: 'powershell' }); if (stdout) { const stdoutString = stdout.toString(); - const memoryMb = parseInt(stdoutString.split('\n')[1]) / 1024 / 1024; + const memoryMb = parseInt(stdoutString) / 1024 / 1024; return parseFloat((memoryMb).toFixed(2)); } } else { /* Not running Windows so we can use the normal method */ diff --git a/scripts/main-builder.js b/scripts/main-builder.js index d1b1b0bc8..912d78ba0 100644 --- a/scripts/main-builder.js +++ b/scripts/main-builder.js @@ -193,6 +193,7 @@ class txAdminRunner { */ const runDevTask = async (txVersion, preReleaseExpiration) => { //Extract paths and validate them + console.log(process.env) if (typeof process.env.TXADMIN_DEV_FXSERVER_PATH !== 'string') { console.error('process.env.TXADMIN_DEV_FXSERVER_PATH is not defined.'); process.exit(1); From 3e8690b7c29db97a8fcbe06016db629a8f87890c Mon Sep 17 00:00:00 2001 From: million1156 Date: Thu, 23 Jan 2025 08:15:26 -0600 Subject: [PATCH 05/10] fix: remove debug thing --- scripts/main-builder.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/main-builder.js b/scripts/main-builder.js index 912d78ba0..d1b1b0bc8 100644 --- a/scripts/main-builder.js +++ b/scripts/main-builder.js @@ -193,7 +193,6 @@ class txAdminRunner { */ const runDevTask = async (txVersion, preReleaseExpiration) => { //Extract paths and validate them - console.log(process.env) if (typeof process.env.TXADMIN_DEV_FXSERVER_PATH !== 'string') { console.error('process.env.TXADMIN_DEV_FXSERVER_PATH is not defined.'); process.exit(1); From eb26d143c0af42545834b4834443913f4996584f Mon Sep 17 00:00:00 2001 From: million1156 Date: Thu, 23 Jan 2025 08:25:34 -0600 Subject: [PATCH 06/10] remove useless file --- core/components/StatsManager/svRuntime/obj.ps1 | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 core/components/StatsManager/svRuntime/obj.ps1 diff --git a/core/components/StatsManager/svRuntime/obj.ps1 b/core/components/StatsManager/svRuntime/obj.ps1 deleted file mode 100644 index 5ecc6f415..000000000 --- a/core/components/StatsManager/svRuntime/obj.ps1 +++ /dev/null @@ -1,4 +0,0 @@ - -object = Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE ProcessId = 1196" | Select-Object WorkingSetSize - -object.split = object.WorkingSetSize / 1MB \ No newline at end of file From 4617b8010cb1fad83e97509666616e6d8690816b Mon Sep 17 00:00:00 2001 From: million1156 Date: Thu, 23 Jan 2025 08:40:01 -0600 Subject: [PATCH 07/10] move branch to develop --- core/modules/Metrics/svRuntime/perfUtils.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/modules/Metrics/svRuntime/perfUtils.ts b/core/modules/Metrics/svRuntime/perfUtils.ts index c9536aaa8..b6ab5eb8a 100644 --- a/core/modules/Metrics/svRuntime/perfUtils.ts +++ b/core/modules/Metrics/svRuntime/perfUtils.ts @@ -1,10 +1,11 @@ import pidusage from 'pidusage'; import { cloneDeep } from 'lodash-es'; import type { SvRtPerfCountsType } from "./perfSchemas"; -import got from '@lib/got'; +import got from '@core/extras/got.js'; import { parseRawPerf } from './perfParser'; import { PERF_DATA_BUCKET_COUNT } from './config'; import { txEnv } from '@core/globalData'; +import { exec } from 'child_process'; //Consts @@ -108,14 +109,23 @@ export const fetchRawPerfData = async (fxServerHost: string) => { /** * Get the fxserver memory usage - * FIXME: migrate to use gwmi on windows by default */ export const fetchFxsMemory = async (fxsPid?: number) => { if (!fxsPid) return; try { + if (txEnv.isWindows) { + //TODO: Is there a way we don't have to use exec? + const { stdout } = await exec(`Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE ProcessId = ${fxsPid}" | Select-Object -ExpandProperty WorkingSetSize`, { shell: 'powershell' }); + if (stdout) { + const stdoutString = stdout.toString(); + const memoryMb = parseInt(stdoutString) / 1024 / 1024; + return parseFloat((memoryMb).toFixed(2)); + } + } else { /* Not running Windows so we can use the normal method */ const pidUsage = await pidusage(fxsPid); const memoryMb = pidUsage.memory / 1024 / 1024; return parseFloat((memoryMb).toFixed(2)); + } } catch (error) { if ((error as any).code = 'ENOENT') { console.error('Failed to get processes tree usage data.'); From 9493ceeb21eace344220ba9568c0d02f53c66211 Mon Sep 17 00:00:00 2001 From: million1156 Date: Thu, 23 Jan 2025 08:49:31 -0600 Subject: [PATCH 08/10] fix: replace dep --- core/modules/Metrics/svRuntime/perfUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/Metrics/svRuntime/perfUtils.ts b/core/modules/Metrics/svRuntime/perfUtils.ts index b6ab5eb8a..fa47cf3c4 100644 --- a/core/modules/Metrics/svRuntime/perfUtils.ts +++ b/core/modules/Metrics/svRuntime/perfUtils.ts @@ -1,7 +1,7 @@ import pidusage from 'pidusage'; import { cloneDeep } from 'lodash-es'; import type { SvRtPerfCountsType } from "./perfSchemas"; -import got from '@core/extras/got.js'; +import got from '@lib/got'; import { parseRawPerf } from './perfParser'; import { PERF_DATA_BUCKET_COUNT } from './config'; import { txEnv } from '@core/globalData'; From 0e8f6d9939005a41dcf7b2d39ee6b79d20e0637a Mon Sep 17 00:00:00 2001 From: million1156 Date: Thu, 23 Jan 2025 09:25:58 -0600 Subject: [PATCH 09/10] fix: use si for process information instead --- core/modules/Metrics/svRuntime/perfUtils.ts | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/core/modules/Metrics/svRuntime/perfUtils.ts b/core/modules/Metrics/svRuntime/perfUtils.ts index fa47cf3c4..d99554f43 100644 --- a/core/modules/Metrics/svRuntime/perfUtils.ts +++ b/core/modules/Metrics/svRuntime/perfUtils.ts @@ -1,12 +1,10 @@ -import pidusage from 'pidusage'; +import si from 'systeminformation'; import { cloneDeep } from 'lodash-es'; import type { SvRtPerfCountsType } from "./perfSchemas"; import got from '@lib/got'; import { parseRawPerf } from './perfParser'; import { PERF_DATA_BUCKET_COUNT } from './config'; import { txEnv } from '@core/globalData'; -import { exec } from 'child_process'; - //Consts const perfDataRawThreadsTemplate: SvRtPerfCountsType = { @@ -113,19 +111,11 @@ export const fetchRawPerfData = async (fxServerHost: string) => { export const fetchFxsMemory = async (fxsPid?: number) => { if (!fxsPid) return; try { - if (txEnv.isWindows) { - //TODO: Is there a way we don't have to use exec? - const { stdout } = await exec(`Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE ProcessId = ${fxsPid}" | Select-Object -ExpandProperty WorkingSetSize`, { shell: 'powershell' }); - if (stdout) { - const stdoutString = stdout.toString(); - const memoryMb = parseInt(stdoutString) / 1024 / 1024; - return parseFloat((memoryMb).toFixed(2)); - } - } else { /* Not running Windows so we can use the normal method */ - const pidUsage = await pidusage(fxsPid); - const memoryMb = pidUsage.memory / 1024 / 1024; + const totalMem = (await si.mem()).total + const pidUsage = (await si.processLoad("fxServer.exe"))[0].mem /* Limitations only allow us to use process names to get memory */ + const memoryMb = (totalMem * (pidUsage / 100)) / (1024 * 1024); return parseFloat((memoryMb).toFixed(2)); - } + } catch (error) { if ((error as any).code = 'ENOENT') { console.error('Failed to get processes tree usage data.'); From cbf939ad1314210d40c6f501e7095cf8fb641714 Mon Sep 17 00:00:00 2001 From: million1156 Date: Thu, 23 Jan 2025 09:32:55 -0600 Subject: [PATCH 10/10] oops, forgot that linux exists --- core/modules/Metrics/svRuntime/perfUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/modules/Metrics/svRuntime/perfUtils.ts b/core/modules/Metrics/svRuntime/perfUtils.ts index d99554f43..aca7a1fb8 100644 --- a/core/modules/Metrics/svRuntime/perfUtils.ts +++ b/core/modules/Metrics/svRuntime/perfUtils.ts @@ -112,7 +112,7 @@ export const fetchFxsMemory = async (fxsPid?: number) => { if (!fxsPid) return; try { const totalMem = (await si.mem()).total - const pidUsage = (await si.processLoad("fxServer.exe"))[0].mem /* Limitations only allow us to use process names to get memory */ + const pidUsage = (await si.processLoad("fxServer"))[0].mem /* Limitations only allow us to use process names to get memory */ const memoryMb = (totalMem * (pidUsage / 100)) / (1024 * 1024); return parseFloat((memoryMb).toFixed(2));