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

Fixes 100% cpu usage on windows platform. #943

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions apps/server/src/data/gpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ const normalizeGpuModel = (model: string) => {
return model ? model.replace(/\[.*\]/gi, '').trim() : undefined;
};

const isValidController = (controller: si.Systeminformation.GraphicsControllerData) => {
const blacklist = ['monitor'];
const model = controller.model.toLowerCase();
return blacklist.every( w => ! model.includes(w) );
};

export default {
dynamic: async (): Promise<GpuLoad> => {
const gpuInfo = await si.graphics();

return {
layout: gpuInfo.controllers.map(controller => ({
layout: gpuInfo.controllers.filter(isValidController).map(controller => ({
load: controller.utilizationGpu ?? 0,
memory: controller.utilizationMemory ?? 0,
})),
Expand All @@ -28,7 +34,7 @@ export default {
const gpuInfo = await si.graphics();

return {
layout: gpuInfo.controllers.map(controller => ({
layout: gpuInfo.controllers.filter(isValidController).map(controller => ({
brand: normalizeGpuBrand(controller.vendor),
model:
normalizeGpuName(controller.name) ??
Expand Down
5 changes: 4 additions & 1 deletion apps/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CONFIG } from './config';
import getNetworkInfo from './data/network';
import { getDynamicServerInfo } from './dynamic-info';
import { environment } from './environments/environment';
import { setupNetworking, setupOsVersion } from './setup';
import { setupNetworking, setupOsVersion, setupHostSpecific, tearDownHostSpecific } from './setup';
import {
getStaticServerInfo,
getStaticServerInfoObs,
Expand Down Expand Up @@ -91,6 +91,7 @@ if (!CONFIG.disable_integrations) {
server.listen(CONFIG.port, async () => {
console.log('listening on *:' + CONFIG.port);

await setupHostSpecific();
await setupNetworking();
await setupOsVersion();
await loadStaticServerInfo();
Expand Down Expand Up @@ -190,10 +191,12 @@ server.on('error', console.error);

process.on('uncaughtException', e => {
console.error(e);
tearDownHostSpecific();
process.exit(1);
});

process.on('unhandledRejection', e => {
console.error(e);
tearDownHostSpecific();
process.exit(1);
});
16 changes: 16 additions & 0 deletions apps/server/src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { exec as exaca } from 'child_process';
import * as fs from 'fs';
import * as si from 'systeminformation';
import { promisify } from 'util';
import { CONFIG } from './config';
import { platformIsWindows } from './utils';

const exec = promisify(exaca);

Expand Down Expand Up @@ -100,3 +102,17 @@ export const setupOsVersion = async () => {
console.warn(e);
}
};

export const setupHostSpecific = async () => {
if (platformIsWindows) {
console.log('Acquiring Windows Persistent Powershell')
si.powerShellStart()
}
};

export const tearDownHostSpecific = () => {
if (platformIsWindows) {
console.log('Releasing Windows Persistent Powershell')
si.powerShellRelease()
}
};