Skip to content

Commit

Permalink
server: cpuUsage not available on deno
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Aug 3, 2024
1 parent be21702 commit 3cd3208
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions server/src/plugin/plugin-remote-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,28 @@ export interface PluginStats {

export function startStatsUpdater(allMemoryStats: Map<NodeThreadWorker, NodeJS.MemoryUsage>, updateStats: (stats: PluginStats) => void) {
setInterval(() => {
const cpuUsage = process.cpuUsage();
allMemoryStats.set(undefined, process.memoryUsage());
let cpuUsage: NodeJS.CpuUsage;
let memoryUsage: NodeJS.MemoryUsage;
if (process.cpuUsage) {
cpuUsage = process.cpuUsage();
allMemoryStats.set(undefined, process.memoryUsage());

const memoryUsage: NodeJS.MemoryUsage = {
rss: 0,
heapTotal: 0,
heapUsed: 0,
external: 0,
arrayBuffers: 0,
}
memoryUsage = {
rss: 0,
heapTotal: 0,
heapUsed: 0,
external: 0,
arrayBuffers: 0,
}

for (const mu of allMemoryStats.values()) {
memoryUsage.rss += mu.rss;
memoryUsage.heapTotal += mu.heapTotal;
memoryUsage.heapUsed += mu.heapUsed;
memoryUsage.external += mu.external;
memoryUsage.arrayBuffers += mu.arrayBuffers;
}

for (const mu of allMemoryStats.values()) {
memoryUsage.rss += mu.rss;
memoryUsage.heapTotal += mu.heapTotal;
memoryUsage.heapUsed += mu.heapUsed;
memoryUsage.external += mu.external;
memoryUsage.arrayBuffers += mu.arrayBuffers;
}

updateStats({
Expand Down

0 comments on commit 3cd3208

Please sign in to comment.