@lanternajs/android 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"collector.d.ts","sourceRoot":"","sources":["../src/collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,kBAAkB,EAAgB,MAAM,kBAAkB,CAAC;AAMhG;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAC1C,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC,kBAAkB,CAAC,CA4D7B"}
1
+ {"version":3,"file":"collector.d.ts","sourceRoot":"","sources":["../src/collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,kBAAkB,EAAgB,MAAM,kBAAkB,CAAC;AAwBhG;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAC1C,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC,kBAAkB,CAAC,CA4D7B"}
package/dist/collector.js CHANGED
@@ -2,6 +2,23 @@ import { parseGfxinfoOutput } from "./parsers/gfxinfo";
2
2
  import { parseMeminfoOutput } from "./parsers/meminfo";
3
3
  import { parseTopOutput } from "./parsers/top";
4
4
  import { findAndroidPid } from "./process";
5
+ const PID_POLL_INTERVAL_MS = 500;
6
+ const PID_MAX_ATTEMPTS = 10;
7
+ /**
8
+ * Poll for a PID with retries. Gives the app up to 5 seconds to appear
9
+ * in the process list after launch.
10
+ */
11
+ async function waitForPid(findPid) {
12
+ for (let attempt = 0; attempt < PID_MAX_ATTEMPTS; attempt++) {
13
+ const pid = await findPid();
14
+ if (pid !== null)
15
+ return pid;
16
+ if (attempt < PID_MAX_ATTEMPTS - 1) {
17
+ await new Promise((resolve) => setTimeout(resolve, PID_POLL_INTERVAL_MS));
18
+ }
19
+ }
20
+ return null;
21
+ }
5
22
  /**
6
23
  * Collect Android performance metrics for a given device and package.
7
24
  *
@@ -10,7 +27,7 @@ import { findAndroidPid } from "./process";
10
27
  * a single MeasurementSession.
11
28
  */
12
29
  export async function collectAndroidMetrics(runner, device, packageName, duration) {
13
- const pid = await findAndroidPid(runner, device.id, packageName);
30
+ const pid = await waitForPid(() => findAndroidPid(runner, device.id, packageName));
14
31
  if (pid === null) {
15
32
  throw new Error(`Process not found: "${packageName}" is not running on device "${device.name}" (${device.id}). ` +
16
33
  "Make sure the app is launched before profiling.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lanternajs/android",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,7 +19,7 @@
19
19
  "access": "public"
20
20
  },
21
21
  "dependencies": {
22
- "@lanternajs/core": "workspace:*"
22
+ "@lanternajs/core": "^0.0.3"
23
23
  },
24
24
  "scripts": {
25
25
  "build": "tsc --project tsconfig.build.json",
package/src/collector.ts CHANGED
@@ -4,6 +4,24 @@ import { parseMeminfoOutput } from "./parsers/meminfo";
4
4
  import { parseTopOutput } from "./parsers/top";
5
5
  import { findAndroidPid } from "./process";
6
6
 
7
+ const PID_POLL_INTERVAL_MS = 500;
8
+ const PID_MAX_ATTEMPTS = 10;
9
+
10
+ /**
11
+ * Poll for a PID with retries. Gives the app up to 5 seconds to appear
12
+ * in the process list after launch.
13
+ */
14
+ async function waitForPid(findPid: () => Promise<number | null>): Promise<number | null> {
15
+ for (let attempt = 0; attempt < PID_MAX_ATTEMPTS; attempt++) {
16
+ const pid = await findPid();
17
+ if (pid !== null) return pid;
18
+ if (attempt < PID_MAX_ATTEMPTS - 1) {
19
+ await new Promise((resolve) => setTimeout(resolve, PID_POLL_INTERVAL_MS));
20
+ }
21
+ }
22
+ return null;
23
+ }
24
+
7
25
  /**
8
26
  * Collect Android performance metrics for a given device and package.
9
27
  *
@@ -17,7 +35,7 @@ export async function collectAndroidMetrics(
17
35
  packageName: string,
18
36
  duration: number,
19
37
  ): Promise<MeasurementSession> {
20
- const pid = await findAndroidPid(runner, device.id, packageName);
38
+ const pid = await waitForPid(() => findAndroidPid(runner, device.id, packageName));
21
39
  if (pid === null) {
22
40
  throw new Error(
23
41
  `Process not found: "${packageName}" is not running on device "${device.name}" (${device.id}). ` +