agent-device
Version:
Open source device layer for AI coding agents: a CLI, MCP server, and typed Node.js API to control mobile, web, TV, and desktop apps on devices and simulators, locally or in the cloud.
1 lines • 1.19 kB
JavaScript
import{v as e}from"./sdk-contracts.js";import{r as t}from"./hdc.js";function n(e){let t=e.trim().split(/\s+/)[0];if(!t||!/^\d+$/.test(t))return;let n=Number.parseInt(t,10);return n>0?n:void 0}function r(e){let t=o(e,`VmRSS`);if(t===void 0)return;let n=o(e,`VmHWM`);return{totalRssKb:t,...n===void 0?{}:{peakRssKb:n}}}async function i(n,i){let o=await a(n,i),s=r((await t(n,[`cat`,`/proc/${o}/status`],{timeoutMs:15e3})).stdout);if(!s)throw new e(`COMMAND_FAILED`,`Could not read resident memory for ${i}`,{hint:`Verify the app is still running, then retry perf memory sample.`,details:{bundleName:i,pid:o}});return{...s,measuredAt:new Date().toISOString(),method:`hdc-shell-proc-status`,pid:o}}async function a(r,i){let a=await t(r,[`pidof`,i],{allowFailure:!0,timeoutMs:15e3}),o=a.exitCode===0?n(a.stdout):void 0;if(o!==void 0)return o;throw new e(`COMMAND_FAILED`,`Could not find a running process for ${i}`,{hint:`Open the app in this session, then retry perf memory sample.`,details:{bundleName:i}})}function o(e,t){let n=e.match(RegExp(`^${t}:\\s+(\\d+)\\s+kB$`,`m`));if(!n?.[1])return;let r=Number.parseInt(n[1],10);return Number.isFinite(r)?r:void 0}export{i as sampleHarmonyMemoryPerf};