()
| 259 | } |
| 260 | |
| 261 | protected async readMemory(): Promise<number | null> { |
| 262 | let usageContent: string; |
| 263 | let limitContent: string; |
| 264 | try { |
| 265 | [usageContent, limitContent] = await Promise.all([ |
| 266 | readWithTimeout( |
| 267 | '/sys/fs/cgroup/memory/memory.usage_in_bytes', |
| 268 | this.readFile, |
| 269 | ), |
| 270 | readWithTimeout( |
| 271 | '/sys/fs/cgroup/memory/memory.limit_in_bytes', |
| 272 | this.readFile, |
| 273 | ), |
| 274 | ]); |
| 275 | } catch (err) { |
| 276 | this.logOnce('memory-read', err); |
| 277 | return null; |
| 278 | } |
| 279 | |
| 280 | const usage = Number(usageContent.trim()); |
| 281 | const limit = parseMemoryV1Limit(limitContent); |
| 282 | if (!Number.isFinite(usage) || limit === null || limit <= 0) { |
| 283 | this.logOnce('memory-parse', new Error('cgroup v1 memory parse failed')); |
| 284 | return null; |
| 285 | } |
| 286 | return usage / limit; |
| 287 | } |
| 288 | |
| 289 | protected logOnce(category: string, err: unknown) { |
| 290 | if (this.loggedFailure.has(category)) return; |
no test coverage detected