@ohos-perf/cli 0.21.0 → 0.22.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.
Files changed (2) hide show
  1. package/dist/index.js +90 -0
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -411,6 +411,43 @@ function describeStep(step) {
411
411
  if (step.action === void 0) return step.status;
412
412
  return describeDecision({ action: step.action, reason: step.reason });
413
413
  }
414
+ async function runSymbolRecovery(deps2, req, opts) {
415
+ if (!existsSync(req.library)) {
416
+ return { stdout: "", stderr: `symbols: no such library: ${req.library}
417
+ `, exitCode: 1 };
418
+ }
419
+ try {
420
+ const result = await deps2.symbols(req);
421
+ if (opts.json) return { stdout: json(result), stderr: "", exitCode: 0 };
422
+ const lines = [
423
+ `library ${result.library}`,
424
+ `result ${result.recovered.length} recovered, ${result.unresolved.length} unresolved`
425
+ ];
426
+ for (const entry of result.recovered) {
427
+ lines.push(` ${entry.address} ${entry.name} (0x${entry.start.toString(16)}..0x${entry.end.toString(16)})`);
428
+ }
429
+ for (const entry of result.unresolved) {
430
+ lines.push(` ${entry.address} ${entry.reason}`);
431
+ }
432
+ if (result.naming !== void 0) {
433
+ const naming = result.naming;
434
+ if (naming.accuracy === void 0) {
435
+ lines.push("naming no nameable function in this file to hold out");
436
+ } else {
437
+ const percent = (naming.accuracy * 100).toFixed(1);
438
+ lines.push(`naming ${naming.correct} of ${naming.heldOut} named correctly (${percent}%)`);
439
+ for (const entry of naming.cases.filter((item) => !item.correct)) {
440
+ lines.push(` ${entry.truth} answered ${JSON.stringify(entry.answer)}`);
441
+ }
442
+ }
443
+ }
444
+ return { stdout: `${lines.join("\n")}
445
+ `, stderr: "", exitCode: 0 };
446
+ } catch (err) {
447
+ return { stdout: "", stderr: `${failureLine(err)}
448
+ `, exitCode: 1 };
449
+ }
450
+ }
414
451
  async function runRender(deps2, req, opts) {
415
452
  try {
416
453
  const result = await deps2.render(req);
@@ -842,6 +879,8 @@ import {
842
879
  httpAgentModel,
843
880
  readAgentConfig,
844
881
  runAgent,
882
+ recoverSymbols,
883
+ measureNaming,
845
884
  readSceneMetadata,
846
885
  readUiTree,
847
886
  resolveAppIdentity,
@@ -863,6 +902,17 @@ function packageVersion(path = manifestPath) {
863
902
  return "0.0.0";
864
903
  }
865
904
  }
905
+ var HEX_DUMP_LIMIT = 512;
906
+ function hexDump(bytes) {
907
+ if (bytes.length === 0) return "(the symbol points outside .text, so no bytes are available)";
908
+ const lines = [];
909
+ for (let at = 0; at + 4 <= Math.min(bytes.length, HEX_DUMP_LIMIT); at += 4) {
910
+ const word = new DataView(bytes.buffer, bytes.byteOffset + at, 4).getUint32(0, true);
911
+ lines.push(`+${at.toString(16).padStart(4, "0")} ${word.toString(16).padStart(8, "0")}`);
912
+ }
913
+ if (bytes.length > HEX_DUMP_LIMIT) lines.push(`(${bytes.length - HEX_DUMP_LIMIT} more bytes)`);
914
+ return lines.join("\n");
915
+ }
866
916
  var OFFLINE_PROBE = () => ({ command: "", stdout: "", stderr: "", code: 0 });
867
917
  function offlineState(id, collector) {
868
918
  return {
@@ -1508,6 +1558,32 @@ function realDeps(version = packageVersion(), overrides = {}) {
1508
1558
  });
1509
1559
  return { transcript, device: { id: device.id, kind: device.kind } };
1510
1560
  },
1561
+ async symbols(req) {
1562
+ const bytes = readFileSync2(req.library);
1563
+ const library = basename(req.library);
1564
+ let result;
1565
+ try {
1566
+ result = recoverSymbols(bytes, req.addresses);
1567
+ } catch (err) {
1568
+ throw new OhosPerfError3(`${library}: ${err.message}`, { cause: err });
1569
+ }
1570
+ if (req.measure !== true) return { library, ...result };
1571
+ const model = agentModel(req.model);
1572
+ const naming = await measureNaming(bytes, async (question) => {
1573
+ const counts = Object.entries(question.counts).filter(([name, value]) => name !== "total" && value > 0).map(([name, value]) => `${name}=${String(value)}`).join(" ");
1574
+ const request = {
1575
+ task: `Name the function at 0x${question.start.toString(16)} in ${library} (${question.size} bytes; instruction mix: ${counts || "none"}).`,
1576
+ app: library,
1577
+ step: 0,
1578
+ maxSteps: 1,
1579
+ screen: hexDump(question.body),
1580
+ history: []
1581
+ };
1582
+ const decision = await model.decide(request);
1583
+ return "done" in decision ? decision.reason : decision.reason;
1584
+ });
1585
+ return { library, ...result, naming };
1586
+ },
1511
1587
  async run(req) {
1512
1588
  const device = await connect(req.target === void 0 ? {} : { target: req.target });
1513
1589
  const runner = new ScenarioRunner(device, {
@@ -1995,6 +2071,20 @@ function buildProgram(deps2, io, opts = {}) {
1995
2071
  )
1996
2072
  );
1997
2073
  });
2074
+ program2.command("symbols").description("name the addresses a capture could not, from the libraries it ran").command("recover").description("name unresolved addresses from a library's own symbol table").argument("<library>", "shared object to read, e.g. libs/arm64/libapp.so").argument("[addresses...]", "libfoo.so+0xoffset references, as a capture writes them").option("--measure", "ask the model to name held-out functions and report its accuracy").option("--model <name>", "model name to send when --measure is used").option("--json", "print the recovery as JSON").action(async (library, addresses, opts2) => {
2075
+ io.emit(
2076
+ await runSymbolRecovery(
2077
+ deps2,
2078
+ {
2079
+ library,
2080
+ addresses,
2081
+ ...opts2.measure === true ? { measure: true } : {},
2082
+ ...opts2.model === void 0 ? {} : { model: opts2.model }
2083
+ },
2084
+ { json: opts2.json }
2085
+ )
2086
+ );
2087
+ });
1998
2088
  program2.command("tools").description("list the named drill-down queries an agent can call").option("--json", "print the query definitions as JSON").action((opts2) => {
1999
2089
  io.emit(runTools(deps2, opts2));
2000
2090
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohos-perf/cli",
3
- "version": "0.21.0",
3
+ "version": "0.22.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.21.0",
39
+ "@ohos-perf/core": "0.22.1",
40
40
  "commander": "^12.1.0"
41
41
  },
42
42
  "scripts": {