( stdout: string, packageName: string, measuredAt: string, )
| 242 | } |
| 243 | |
| 244 | export function parseAndroidMemInfoSample( |
| 245 | stdout: string, |
| 246 | packageName: string, |
| 247 | measuredAt: string, |
| 248 | ): AndroidMemoryPerfSample { |
| 249 | if (/no process found for:/i.test(stdout)) { |
| 250 | throw new AppError( |
| 251 | 'COMMAND_FAILED', |
| 252 | `Android meminfo did not find a running process for ${packageName}`, |
| 253 | { |
| 254 | metric: 'memory', |
| 255 | package: packageName, |
| 256 | hint: 'Run open <app> for this session again to ensure the Android app is active, then retry perf.', |
| 257 | }, |
| 258 | ); |
| 259 | } |
| 260 | |
| 261 | const totalPssKb = matchLabeledNumber(stdout, 'TOTAL PSS') ?? matchTotalRowPss(stdout); |
| 262 | if (totalPssKb === undefined) { |
| 263 | throw new AppError( |
| 264 | 'COMMAND_FAILED', |
| 265 | `Failed to parse Android meminfo output for ${packageName}`, |
| 266 | { |
| 267 | metric: 'memory', |
| 268 | package: packageName, |
| 269 | hint: 'Retry perf after reopening the app session. If the problem persists, capture adb shell dumpsys meminfo output for debugging.', |
| 270 | }, |
| 271 | ); |
| 272 | } |
| 273 | |
| 274 | return { |
| 275 | totalPssKb, |
| 276 | totalRssKb: matchLabeledNumber(stdout, 'TOTAL RSS'), |
| 277 | measuredAt, |
| 278 | method: ANDROID_MEMORY_SAMPLE_METHOD, |
| 279 | topConsumers: parseAndroidMemInfoTopConsumers(stdout), |
| 280 | }; |
| 281 | } |
| 282 | |
| 283 | async function resolveAndroidAppPid(adb: AndroidAdbExecutor, packageName: string): Promise<number> { |
| 284 | const result = await adb(['shell', 'pidof', packageName], { |
no test coverage detected