MCPcopy Create free account
hub / github.com/ember-cli/ember-cli / memorySwapUsedBsd

Function memorySwapUsedBsd

lib/models/hardware-info.js:148–176  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

146}
147
148function memorySwapUsedBsd() {
149 try {
150 const { stdout } = execa.sync('pstat', ['-s']);
151 const devices = stdout.split('\n').filter(Boolean);
152 const header = devices.shift();
153 const match = /^Device\s+(\d+)(K?)-blocks\s+Used\b/.exec(header);
154
155 if (!match) {
156 throw new Error('Block size not found in output.');
157 }
158
159 const blockSize = parseInt(match[1], 10) * (match[2] === 'K' ? 1024 : 1);
160
161 return devices.reduce((total, line) => {
162 const match = /^\S+\s+\d+\s+(\d+)/.exec(line);
163
164 if (!match) {
165 throw new Error(`Unrecognized line in output: '${line}'`);
166 }
167
168 return total + parseInt(match[1], 10) * blockSize;
169 }, 0);
170 } catch (ex) {
171 logger.warn(`Could not get swap status from pstat: ${ex}`);
172 logger.warn(ex.stack);
173
174 return null;
175 }
176}
177
178function memorySwapUsedLinux() {
179 try {

Callers 1

memorySwapUsedFunction · 0.85

Calls 1

filterMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…