()
| 146 | } |
| 147 | |
| 148 | function 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 | |
| 178 | function memorySwapUsedLinux() { |
| 179 | try { |
no test coverage detected
searching dependent graphs…