()
| 144 | } |
| 145 | |
| 146 | protected async readMemory(): Promise<number | null> { |
| 147 | let currentContent: string; |
| 148 | let maxContent: string; |
| 149 | try { |
| 150 | [currentContent, maxContent] = await Promise.all([ |
| 151 | readWithTimeout('/sys/fs/cgroup/memory.current', this.readFile), |
| 152 | readWithTimeout('/sys/fs/cgroup/memory.max', this.readFile), |
| 153 | ]); |
| 154 | } catch (err) { |
| 155 | this.logOnce('memory-read', err); |
| 156 | return null; |
| 157 | } |
| 158 | |
| 159 | const current = Number(currentContent.trim()); |
| 160 | const max = parseMemoryMax(maxContent); |
| 161 | if (!Number.isFinite(current) || max === null || max <= 0) { |
| 162 | this.logOnce('memory-parse', new Error('cgroup v2 memory parse failed')); |
| 163 | return null; |
| 164 | } |
| 165 | return current / max; |
| 166 | } |
| 167 | |
| 168 | protected logOnce(category: string, err: unknown) { |
| 169 | if (this.loggedFailure.has(category)) return; |
no test coverage detected