|
| 1 | +// NOTE: This is a temporary script to check the runner CPU / memory usage |
| 2 | +/* eslint-disable spellcheck/spell-checker, no-console */ |
| 3 | +const os = require('os'); |
| 4 | + |
| 5 | +const BYTES_IN_MB = 1024 * 1024; |
| 6 | +const INTERVAL_MS = 10000; |
| 7 | + |
| 8 | +const printCpuUsage = () => { |
| 9 | + const cpus = os.cpus(); |
| 10 | + cpus.forEach((cpu, idx) => { |
| 11 | + let total = 0; |
| 12 | + const data = []; |
| 13 | + |
| 14 | + for(const type in cpu.times) { |
| 15 | + total += cpu.times[type]; |
| 16 | + } |
| 17 | + |
| 18 | + console.info(`--- CPU ${idx} ---`); |
| 19 | + for(const type in cpu.times) { |
| 20 | + data.push(`${type}: ${Math.round(100 * cpu.times[type] / total)}`); |
| 21 | + } |
| 22 | + |
| 23 | + console.log(data.join(' | ')); |
| 24 | + }); |
| 25 | +}; |
| 26 | + |
| 27 | +const printMemoryUsage = () => { |
| 28 | + const totalMemory = os.totalmem() / BYTES_IN_MB; |
| 29 | + const freeMemory = os.freemem() / BYTES_IN_MB; |
| 30 | + const usedMemory = totalMemory - freeMemory; |
| 31 | + const roundedTotalMemory = Math.round(totalMemory * 100) / 100; |
| 32 | + const roundedUsedMemory = Math.round(usedMemory * 100) / 100; |
| 33 | + const memoryUsagePercents = (roundedUsedMemory * 100) / roundedTotalMemory; |
| 34 | + const memoryUsagePercentsRounded = Math.round(memoryUsagePercents * 100) / 100; |
| 35 | + |
| 36 | + console.info(`--- Memory ---\nUsed: ${memoryUsagePercentsRounded}%`); |
| 37 | +}; |
| 38 | + |
| 39 | +const printPerformanceLog = () => { |
| 40 | + console.log('===== PERFORMANCE_LOG ====='); |
| 41 | + printCpuUsage(); |
| 42 | + printMemoryUsage(); |
| 43 | + console.log('==========================='); |
| 44 | +}; |
| 45 | + |
| 46 | +printPerformanceLog(); |
| 47 | +setInterval(() => { |
| 48 | + printPerformanceLog(); |
| 49 | +}, INTERVAL_MS); |
0 commit comments