@ohos-perf/cli 0.17.2 → 0.18.1
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.
- package/dist/index.js +114 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -350,6 +350,27 @@ series ${result.series} metrics \xB7 ${result.improved} improved, ${result.regr
|
|
|
350
350
|
`, exitCode: 1 };
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
|
+
async function runExplore(deps2, req, opts) {
|
|
354
|
+
try {
|
|
355
|
+
const result = await deps2.explore(req);
|
|
356
|
+
if (opts.json) return { stdout: json(result), stderr: "", exitCode: 0 };
|
|
357
|
+
const order = result.strategy === "random" ? `random (seed ${result.seed ?? 0})` : result.strategy;
|
|
358
|
+
const stopped = result.exhausted ? "the screen had no unvisited clickable left" : `the step cap (${req.maxSteps}) was reached`;
|
|
359
|
+
return {
|
|
360
|
+
stdout: `explore ${result.app} on ${result.device.id} (${result.device.kind})
|
|
361
|
+
states ${result.statesReached} reached \xB7 ${result.steps} taps (${result.navigated} navigated, ${result.noChange} no change)
|
|
362
|
+
order ${order}
|
|
363
|
+
stopped ${stopped}
|
|
364
|
+
` + (result.screens.length === 0 ? "" : `screens ${result.screens.join(" ")}
|
|
365
|
+
`),
|
|
366
|
+
stderr: "",
|
|
367
|
+
exitCode: 0
|
|
368
|
+
};
|
|
369
|
+
} catch (err) {
|
|
370
|
+
return { stdout: "", stderr: `${failureLine(err)}
|
|
371
|
+
`, exitCode: 1 };
|
|
372
|
+
}
|
|
373
|
+
}
|
|
353
374
|
async function runRender(deps2, req, opts) {
|
|
354
375
|
try {
|
|
355
376
|
const result = await deps2.render(req);
|
|
@@ -686,6 +707,8 @@ import {
|
|
|
686
707
|
ThreadStateQuery,
|
|
687
708
|
connect,
|
|
688
709
|
createSceneLayout,
|
|
710
|
+
deviceExplorationHost,
|
|
711
|
+
explore,
|
|
689
712
|
decodePng,
|
|
690
713
|
defaultAnalyzers,
|
|
691
714
|
ingestScene,
|
|
@@ -936,6 +959,7 @@ function realDeps(version = packageVersion(), overrides = {}) {
|
|
|
936
959
|
const ingest = overrides.ingest ?? ingestScene;
|
|
937
960
|
const collectDevice = overrides.collectDevice ?? ((target) => connect(target === void 0 ? {} : { target }));
|
|
938
961
|
const gestureDevice = overrides.gestureDevice ?? ((target) => connect(target === void 0 ? {} : { target }));
|
|
962
|
+
const exploreDevice = overrides.exploreDevice ?? ((target) => connect(target === void 0 ? {} : { target }));
|
|
939
963
|
const doctor = {
|
|
940
964
|
resolveHdc,
|
|
941
965
|
async resolveStreamer() {
|
|
@@ -1308,6 +1332,35 @@ function realDeps(version = packageVersion(), overrides = {}) {
|
|
|
1308
1332
|
returns: definition.returns
|
|
1309
1333
|
}));
|
|
1310
1334
|
},
|
|
1335
|
+
async explore(req) {
|
|
1336
|
+
const device = await exploreDevice(req.target);
|
|
1337
|
+
const host = deviceExplorationHost(device, {
|
|
1338
|
+
...req.settleMs === void 0 ? {} : { settleMs: req.settleMs },
|
|
1339
|
+
...overrides.exploreClock === void 0 ? {} : { clock: overrides.exploreClock }
|
|
1340
|
+
});
|
|
1341
|
+
const result = await explore(host, {
|
|
1342
|
+
maxSteps: req.maxSteps,
|
|
1343
|
+
strategy: req.strategy,
|
|
1344
|
+
...req.seed === void 0 ? {} : { seed: req.seed }
|
|
1345
|
+
});
|
|
1346
|
+
return {
|
|
1347
|
+
app: req.app,
|
|
1348
|
+
device: { id: device.id, kind: device.kind },
|
|
1349
|
+
strategy: result.strategy,
|
|
1350
|
+
...result.seed === void 0 ? {} : { seed: result.seed },
|
|
1351
|
+
steps: result.steps.length,
|
|
1352
|
+
navigated: result.steps.filter((step) => step.outcome === "navigated").length,
|
|
1353
|
+
noChange: result.steps.filter((step) => step.outcome === "no_change").length,
|
|
1354
|
+
statesReached: result.statesReached,
|
|
1355
|
+
exhausted: result.exhausted,
|
|
1356
|
+
// First-reach order: the sequence of hashes as the walk saw them, which
|
|
1357
|
+
// is what a reader follows to see where it went.
|
|
1358
|
+
screens: [.../* @__PURE__ */ new Set([
|
|
1359
|
+
...result.steps[0] === void 0 ? [] : [result.steps[0].before],
|
|
1360
|
+
...result.steps.map((step) => step.after)
|
|
1361
|
+
])]
|
|
1362
|
+
};
|
|
1363
|
+
},
|
|
1311
1364
|
async run(req) {
|
|
1312
1365
|
const device = await connect(req.target === void 0 ? {} : { target: req.target });
|
|
1313
1366
|
const runner = new ScenarioRunner(device, {
|
|
@@ -1426,6 +1479,30 @@ function parsePluginList(raw) {
|
|
|
1426
1479
|
return plugins;
|
|
1427
1480
|
}
|
|
1428
1481
|
|
|
1482
|
+
// src/explore.ts
|
|
1483
|
+
import { OhosPerfError as OhosPerfError5 } from "@ohos-perf/core";
|
|
1484
|
+
var STRATEGIES = ["depth_first", "breadth_first", "random"];
|
|
1485
|
+
function parseStrategy(raw) {
|
|
1486
|
+
const found = STRATEGIES.find((strategy) => strategy === raw);
|
|
1487
|
+
if (found === void 0) {
|
|
1488
|
+
throw new OhosPerfError5(
|
|
1489
|
+
`explore: unknown strategy ${JSON.stringify(raw)}; use one of ${STRATEGIES.join(", ")}`,
|
|
1490
|
+
{ code: "SCENARIO_BAD_STRATEGY" }
|
|
1491
|
+
);
|
|
1492
|
+
}
|
|
1493
|
+
return found;
|
|
1494
|
+
}
|
|
1495
|
+
function parseMaxSteps(raw) {
|
|
1496
|
+
const value = Number(raw);
|
|
1497
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
1498
|
+
throw new OhosPerfError5(
|
|
1499
|
+
`explore: --max-steps must be a positive integer (got ${JSON.stringify(raw)})`,
|
|
1500
|
+
{ code: "SCENARIO_BAD_STEPS" }
|
|
1501
|
+
);
|
|
1502
|
+
}
|
|
1503
|
+
return value;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1429
1506
|
// src/gesture.ts
|
|
1430
1507
|
var COORDINATE = /^\d+$/;
|
|
1431
1508
|
var CONTROL_CHARS = /[\u0000-\u001f\u007f]/;
|
|
@@ -1468,22 +1545,22 @@ function parseText(raw) {
|
|
|
1468
1545
|
}
|
|
1469
1546
|
|
|
1470
1547
|
// src/query.ts
|
|
1471
|
-
import { MAX_QUERY_LIMIT, OhosPerfError as
|
|
1548
|
+
import { MAX_QUERY_LIMIT, OhosPerfError as OhosPerfError6, resolveQueryLimit as resolveQueryLimit2 } from "@ohos-perf/core";
|
|
1472
1549
|
function parseQueryArgs(raw) {
|
|
1473
1550
|
let value;
|
|
1474
1551
|
try {
|
|
1475
1552
|
value = JSON.parse(raw);
|
|
1476
1553
|
} catch {
|
|
1477
|
-
throw new
|
|
1554
|
+
throw new OhosPerfError6("invalid --args: not valid JSON", { code: "QUERY_BAD_ARGS" });
|
|
1478
1555
|
}
|
|
1479
1556
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
1480
|
-
throw new
|
|
1557
|
+
throw new OhosPerfError6("invalid --args: expected a JSON object", { code: "QUERY_BAD_ARGS" });
|
|
1481
1558
|
}
|
|
1482
1559
|
return value;
|
|
1483
1560
|
}
|
|
1484
1561
|
function parseLimit(raw) {
|
|
1485
1562
|
const text = raw.trim();
|
|
1486
|
-
const bad = () => new
|
|
1563
|
+
const bad = () => new OhosPerfError6(
|
|
1487
1564
|
`limit must be an integer between 1 and ${MAX_QUERY_LIMIT}, got ${JSON.stringify(raw)}`,
|
|
1488
1565
|
{ code: "QUERY_BAD_LIMIT" }
|
|
1489
1566
|
);
|
|
@@ -1710,6 +1787,39 @@ function buildProgram(deps2, io, opts = {}) {
|
|
|
1710
1787
|
...opts2.keepGoing === true ? { keepGoing: true } : {}
|
|
1711
1788
|
}, { json: opts2.json }));
|
|
1712
1789
|
});
|
|
1790
|
+
program2.command("explore").description("walk an app's UI, tapping unvisited elements, and report the screens reached").argument("<app>", "bundle name to explore, e.g. com.example.app").option("--max-steps <n>", "stop after this many taps", "30").option(
|
|
1791
|
+
"--strategy <name>",
|
|
1792
|
+
"depth_first, breadth_first or random",
|
|
1793
|
+
"depth_first"
|
|
1794
|
+
).option("--seed <n>", "make --strategy random reproducible").option("--target <id>", "walk this hdc target instead of the first connected one").option("--json", "print the walk result as JSON").action(async (app, opts2) => {
|
|
1795
|
+
let maxSteps;
|
|
1796
|
+
let strategy;
|
|
1797
|
+
let seed;
|
|
1798
|
+
try {
|
|
1799
|
+
maxSteps = parseMaxSteps(opts2.maxSteps);
|
|
1800
|
+
strategy = parseStrategy(opts2.strategy);
|
|
1801
|
+
if (opts2.seed !== void 0) {
|
|
1802
|
+
seed = parseMaxSteps(opts2.seed);
|
|
1803
|
+
}
|
|
1804
|
+
} catch (err) {
|
|
1805
|
+
io.emit({ stdout: "", stderr: `${failureLine(err)}
|
|
1806
|
+
`, exitCode: 1 });
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
io.emit(
|
|
1810
|
+
await runExplore(
|
|
1811
|
+
deps2,
|
|
1812
|
+
{
|
|
1813
|
+
app,
|
|
1814
|
+
maxSteps,
|
|
1815
|
+
strategy,
|
|
1816
|
+
...seed === void 0 ? {} : { seed },
|
|
1817
|
+
...opts2.target === void 0 ? {} : { target: opts2.target }
|
|
1818
|
+
},
|
|
1819
|
+
{ json: opts2.json }
|
|
1820
|
+
)
|
|
1821
|
+
);
|
|
1822
|
+
});
|
|
1713
1823
|
program2.command("tools").description("list the named drill-down queries an agent can call").option("--json", "print the query definitions as JSON").action((opts2) => {
|
|
1714
1824
|
io.emit(runTools(deps2, opts2));
|
|
1715
1825
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-perf/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "Command-line interface for HarmonyOS performance analysis: doctor, caps, collect, analyze, query, tools, compare, report, gesture, emulator and selector-driven scenarios",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"harmonyos",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@ohos-perf/core": "0.
|
|
39
|
+
"@ohos-perf/core": "0.18.1",
|
|
40
40
|
"commander": "^12.1.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|