@ohos-perf/cli 0.19.0 → 0.20.0

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.
Files changed (2) hide show
  1. package/dist/index.js +80 -0
  2. package/package.json +49 -49
package/dist/index.js CHANGED
@@ -449,6 +449,66 @@ function packagePathError(packagePath) {
449
449
  }
450
450
  return void 0;
451
451
  }
452
+ function binaryPathError(packagePath) {
453
+ let stats;
454
+ try {
455
+ stats = statSync(packagePath);
456
+ } catch {
457
+ return `no such package: ${packagePath}`;
458
+ }
459
+ if (!stats.isFile()) return `not a file: ${packagePath}`;
460
+ const dot = packagePath.lastIndexOf(".");
461
+ const extension = dot <= 0 ? "" : packagePath.slice(dot + 1).toLowerCase();
462
+ if (extension === "a") {
463
+ return `an .a archive is not read: pass the .so files, or the package that holds them`;
464
+ }
465
+ if (extension !== "hap" && extension !== "hsp" && extension !== "zip" && extension !== "so") {
466
+ return `not a package or library (expected .hap, .hsp, .zip or .so): ${packagePath}`;
467
+ }
468
+ return void 0;
469
+ }
470
+ var LTO_WORD = {
471
+ present: "LTO",
472
+ absent: "no LTO",
473
+ unknown: "LTO unknown"
474
+ };
475
+ async function runOptimization(deps2, req, opts) {
476
+ const pathError = binaryPathError(req.packagePath);
477
+ if (pathError !== void 0) return { stdout: "", stderr: `${pathError}
478
+ `, exitCode: 1 };
479
+ try {
480
+ const result = await deps2.opt(req);
481
+ if (opts.json) {
482
+ return {
483
+ stdout: json({ analysis: result.analysis, capabilities: result.capabilities }),
484
+ stderr: "",
485
+ exitCode: 0
486
+ };
487
+ }
488
+ const analysis = result.analysis;
489
+ let stdout = `package ${analysis.package}
490
+ `;
491
+ stdout += `binaries ${analysis.totals.binaries}, ${analysis.totals.lto} with LTO${analysis.totals.debug === 0 ? "" : `, ${analysis.totals.debug} with debug info`}${analysis.totals.stripped === 0 ? "" : `, ${analysis.totals.stripped} stripped`}
492
+ `;
493
+ for (const binary of analysis.binaries) {
494
+ const facts = binary.facts;
495
+ const verdict = binary.verdict;
496
+ const basis = verdict.basis === "none" ? "" : ` (${verdict.basis})`;
497
+ stdout += `binary ${binary.path} ${verdict.level}${basis}
498
+ `;
499
+ stdout += ` ${LTO_WORD[facts.lto]}${facts.ltoMarkers.length === 0 ? "" : ` via ${facts.ltoMarkers[0]}`}, ${facts.instructions.total} instructions, ${facts.symbols.functions} functions${facts.debug ? ", debug info" : ""}
500
+ `;
501
+ if (verdict.signals.length > 0) {
502
+ stdout += ` signals ${verdict.signals.join(", ")}
503
+ `;
504
+ }
505
+ }
506
+ return { stdout, stderr: "", exitCode: 0 };
507
+ } catch (err) {
508
+ return { stdout: "", stderr: `${failureLine(err)}
509
+ `, exitCode: 1 };
510
+ }
511
+ }
452
512
  async function runScenarioCommand(deps2, input, opts) {
453
513
  if (input.casesDir !== void 0) {
454
514
  if (input.scenarioPath !== "") {
@@ -737,6 +797,8 @@ import {
737
797
  renderFlamegraphHtml,
738
798
  renderFlamegraphSvg,
739
799
  hapSection,
800
+ analyzeBinaries,
801
+ extractBinaries,
740
802
  readSceneMetadata,
741
803
  readUiTree,
742
804
  resolveAppIdentity,
@@ -1327,6 +1389,19 @@ function realDeps(version = packageVersion(), overrides = {}) {
1327
1389
  }
1328
1390
  return { analysis, capabilities, outDir, artifacts: artifacts.map(([name]) => name) };
1329
1391
  },
1392
+ async opt(req) {
1393
+ const bytes = readFileSync2(req.packagePath);
1394
+ const name = basename(req.packagePath);
1395
+ const analysis = analyzeBinaries(extractBinaries({ path: name, bytes }), name);
1396
+ const capabilities = [{
1397
+ id: "static.hap",
1398
+ available: true,
1399
+ collector: "offline",
1400
+ fidelity: "exact",
1401
+ probe: { command: "", stdout: "", stderr: "", code: 0 }
1402
+ }];
1403
+ return { analysis, capabilities };
1404
+ },
1330
1405
  tools() {
1331
1406
  return queryDefinitions().map((definition) => ({
1332
1407
  name: definition.name,
@@ -1761,6 +1836,11 @@ function buildProgram(deps2, io, opts = {}) {
1761
1836
  )
1762
1837
  );
1763
1838
  });
1839
+ program2.command("opt").description(
1840
+ "inspect a package's arm64 libraries: optimization level, LTO, debug info"
1841
+ ).argument("<package>", "path to a .hap, .hsp, .zip or .so file").option("--json", "print the analysis as JSON").action(async (packagePath, opts2) => {
1842
+ io.emit(await runOptimization(deps2, { packagePath }, { json: opts2.json }));
1843
+ });
1764
1844
  program2.command("run").description("run a declarative scenario, capturing one scene per step").argument("[scenario]", "scenario JSON file (omit when using --cases)").requiredOption("--out <dir>", "run output directory (one scene per step)").option("--cases <dir>", "run every *.scenario.json in this directory as one suite").option("--filter <regex>", "anchored regex over case ids; only with --cases").option("--target <id>", "run against this hdc target instead of the first connected one").option("--rounds <n>", "repeat every step this many times (overrides the scenario)").option("--only <ids>", "comma-separated step ids to run, in scenario order").option("--keep-going", "continue after a failed step instead of stopping").option("--json", "print the run result as JSON").action(async (scenarioPath, opts2) => {
1765
1845
  let rounds;
1766
1846
  let only;
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
- {
2
- "name": "@ohos-perf/cli",
3
- "version": "0.19.0",
4
- "description": "Command-line interface for HarmonyOS performance analysis: doctor, caps, collect, analyze, query, tools, compare, report, gesture, emulator and selector-driven scenarios",
5
- "keywords": [
6
- "harmonyos",
7
- "openharmony",
8
- "ohos",
9
- "performance",
10
- "profiling",
11
- "cli",
12
- "hapray"
13
- ],
14
- "type": "module",
15
- "bin": {
16
- "ohos-perf": "./dist/index.js"
17
- },
18
- "files": [
19
- "dist"
20
- ],
21
- "engines": {
22
- "node": "^22.13.0 || >=23.4.0"
23
- },
24
- "license": "MIT",
25
- "author": "growvv",
26
- "homepage": "https://growvv.github.io/ohos-perf/",
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/growvv/ohos-perf.git",
30
- "directory": "packages/cli"
31
- },
32
- "bugs": {
33
- "url": "https://github.com/growvv/ohos-perf/issues"
34
- },
35
- "publishConfig": {
36
- "access": "public"
37
- },
38
- "dependencies": {
39
- "@ohos-perf/core": "0.19.0",
40
- "commander": "^12.1.0"
41
- },
42
- "scripts": {
43
- "build": "tsup src/index.ts --format esm --target node22",
44
- "typecheck": "tsc --noEmit -p tsconfig.test.json",
45
- "pretest": "npm run build -w @ohos-perf/core",
46
- "test": "vitest run",
47
- "prepublishOnly": "npm run build"
48
- }
49
- }
1
+ {
2
+ "name": "@ohos-perf/cli",
3
+ "version": "0.20.0",
4
+ "description": "Command-line interface for HarmonyOS performance analysis: doctor, caps, collect, analyze, query, tools, compare, report, gesture, emulator and selector-driven scenarios",
5
+ "keywords": [
6
+ "harmonyos",
7
+ "openharmony",
8
+ "ohos",
9
+ "performance",
10
+ "profiling",
11
+ "cli",
12
+ "hapray"
13
+ ],
14
+ "type": "module",
15
+ "bin": {
16
+ "ohos-perf": "./dist/index.js"
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "engines": {
22
+ "node": "^22.13.0 || >=23.4.0"
23
+ },
24
+ "license": "MIT",
25
+ "author": "growvv",
26
+ "homepage": "https://growvv.github.io/ohos-perf/",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/growvv/ohos-perf.git",
30
+ "directory": "packages/cli"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/growvv/ohos-perf/issues"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "dependencies": {
39
+ "@ohos-perf/core": "0.20.0",
40
+ "commander": "^12.1.0"
41
+ },
42
+ "scripts": {
43
+ "build": "tsup src/index.ts --format esm --target node22",
44
+ "typecheck": "tsc --noEmit -p tsconfig.test.json",
45
+ "pretest": "npm run build -w @ohos-perf/core",
46
+ "test": "vitest run",
47
+ "prepublishOnly": "npm run build"
48
+ }
49
+ }