UNPKG

@remotion/renderer

Version:

Render Remotion videos using Node.js or Bun

45 lines (44 loc) 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFreeMemoryFromProcMeminfo = void 0; const node_fs_1 = require("node:fs"); const logger_1 = require("../logger"); const getFreeMemoryFromProcMeminfo = (logLevel) => { if (!(0, node_fs_1.existsSync)('/proc/meminfo')) { return null; } try { const data = (0, node_fs_1.readFileSync)('/proc/meminfo', 'utf-8'); // Split the file by lines and find the line with MemFree const lines = data.split('\n'); const memAvailableLine = lines.find((line) => line.startsWith('MemAvailable')); // If we couldn't find MemAvailable, return an error if (!memAvailableLine) { throw new Error('MemAvailable not found in /proc/meminfo'); } // Extract the value and unit from the line const matches = memAvailableLine.match(/(\d+)\s+(\w+)/); if (!matches || matches.length !== 3) { throw new Error('Failed to parse MemAvailable value'); } const value = parseInt(matches[1], 10); const unit = matches[2].toLowerCase(); // Convert the value to bytes based on its unit switch (unit) { case 'kb': return value * 1024; case 'mb': return value * 1024 * 1024; case 'gb': return value * 1024 * 1024 * 1024; default: throw new Error(`Unknown unit: ${unit}`); } } catch (err) { logger_1.Log.warn({ indent: false, logLevel }, '/proc/meminfo exists but failed to get memory info. Error:'); logger_1.Log.warn({ indent: false, logLevel }, err); return null; } }; exports.getFreeMemoryFromProcMeminfo = getFreeMemoryFromProcMeminfo;