@ohos-perf/core 0.18.1 → 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 (3) hide show
  1. package/dist/index.d.ts +326 -2
  2. package/dist/index.js +735 -66
  3. package/package.json +48 -48
package/dist/index.js CHANGED
@@ -1836,8 +1836,8 @@ function readChunk(bytes, offset) {
1836
1836
  if (offset + 8 > bytes.length) {
1837
1837
  throw bad("PNG_TRUNCATED", `PNG is truncated at byte ${offset}: no chunk header`);
1838
1838
  }
1839
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
1840
- const length = view.getUint32(offset);
1839
+ const view2 = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
1840
+ const length = view2.getUint32(offset);
1841
1841
  const type = String.fromCharCode(
1842
1842
  bytes[offset + 4],
1843
1843
  bytes[offset + 5],
@@ -1944,13 +1944,13 @@ function decodePng(bytes) {
1944
1944
  if (chunk2.body.length !== 13) {
1945
1945
  throw bad("PNG_BAD_IHDR", `IHDR is ${chunk2.body.length} bytes, expected 13`);
1946
1946
  }
1947
- const view = new DataView(
1947
+ const view2 = new DataView(
1948
1948
  chunk2.body.buffer,
1949
1949
  chunk2.body.byteOffset,
1950
1950
  chunk2.body.byteLength
1951
1951
  );
1952
- width = view.getUint32(0);
1953
- height = view.getUint32(4);
1952
+ width = view2.getUint32(0);
1953
+ height = view2.getUint32(4);
1954
1954
  bitDepth = chunk2.body[8];
1955
1955
  colourType = chunk2.body[9];
1956
1956
  interlace = chunk2.body[12];
@@ -2571,9 +2571,9 @@ var CONTROL_CHARS = /[\u0000-\u001f\u007f]/;
2571
2571
  function badGesture(message3) {
2572
2572
  return new OhosPerfError(message3, { code: "UITEST_BAD_GESTURE" });
2573
2573
  }
2574
- function assertPosition(field, value) {
2574
+ function assertPosition(field2, value) {
2575
2575
  if (!Number.isSafeInteger(value) || value < 0) {
2576
- throw badGesture(`gesture ${field} must be a non-negative integer (got ${String(value)})`);
2576
+ throw badGesture(`gesture ${field2} must be a non-negative integer (got ${String(value)})`);
2577
2577
  }
2578
2578
  }
2579
2579
  function assertVelocity(velocity) {
@@ -2845,6 +2845,7 @@ function createSceneLayout(root) {
2845
2845
  hilogFile: join3(root, "hilog.log"),
2846
2846
  hilogJsonlFile: join3(root, "hilog.jsonl"),
2847
2847
  redundantFile: join3(root, "redundant_file.txt"),
2848
+ coverageFile: join3(root, "coverageReport.json"),
2848
2849
  jsheapFile: join3(root, "jsheap.heapsnapshot"),
2849
2850
  metadataFile: join3(root, "scene.json")
2850
2851
  };
@@ -4166,7 +4167,7 @@ function messageOf(err) {
4166
4167
  return err instanceof Error ? err.message : String(err);
4167
4168
  }
4168
4169
  function isConnectedTcp(target) {
4169
- const fields2 = target.raw.split(" ").filter((field) => field !== "");
4170
+ const fields2 = target.raw.split(" ").filter((field2) => field2 !== "");
4170
4171
  return target.connected && fields2[1] === "TCP";
4171
4172
  }
4172
4173
  function isLoopback(id) {
@@ -6302,8 +6303,8 @@ var PARITY_ROWS = [
6302
6303
  {
6303
6304
  row: 24,
6304
6305
  name: "Coverage",
6305
- status: "out",
6306
- reason: "Needs an instrumented build and the external `bjc` toolchain; the capability reports the measured `bjc_cov` probe result instead of a silent zero."
6306
+ status: "ported",
6307
+ reason: ""
6307
6308
  },
6308
6309
  {
6309
6310
  row: 25,
@@ -6315,8 +6316,8 @@ var PARITY_ROWS = [
6315
6316
  {
6316
6317
  row: 27,
6317
6318
  name: "Optimization detector (`opt-detector`)",
6318
- status: "out",
6319
- reason: "Requires a ~2 GB TensorFlow LSTM plus an sklearn classifier and is AArch64-only; it is a probabilistic guess, not a measurement."
6319
+ status: "ported",
6320
+ reason: ""
6320
6321
  },
6321
6322
  {
6322
6323
  row: 28,
@@ -7650,6 +7651,173 @@ function renderBundle(input) {
7650
7651
  ];
7651
7652
  }
7652
7653
 
7654
+ // src/analyze/coverage.ts
7655
+ function isRecord7(value) {
7656
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7657
+ }
7658
+ function percentOf(counts) {
7659
+ if (counts.total === 0) return 0;
7660
+ return Math.round(counts.covered / counts.total * 1e4) / 100;
7661
+ }
7662
+ function readCounts(value, section) {
7663
+ if (!isRecord7(value)) {
7664
+ throw new OhosPerfError(
7665
+ `coverageReport.json: ${section} is missing or not an object`,
7666
+ { code: "SCENARIO_BAD_INPUT" }
7667
+ );
7668
+ }
7669
+ const total = value["total"];
7670
+ const covered = value["covered"];
7671
+ for (const [name, count] of [["total", total], ["covered", covered]]) {
7672
+ if (typeof count !== "number" || !Number.isSafeInteger(count) || count < 0) {
7673
+ throw new OhosPerfError(
7674
+ `coverageReport.json: ${section}.${name} must be a non-negative integer (got ${JSON.stringify(count)})`,
7675
+ { code: "SCENARIO_BAD_INPUT" }
7676
+ );
7677
+ }
7678
+ }
7679
+ if (covered > total) {
7680
+ throw new OhosPerfError(
7681
+ `coverageReport.json: ${section}.covered (${String(covered)}) exceeds ${section}.total (${String(total)}); a report cannot cover more than exists`,
7682
+ { code: "SCENARIO_BAD_INPUT" }
7683
+ );
7684
+ }
7685
+ return { covered, total };
7686
+ }
7687
+ function readSummary(value, section) {
7688
+ if (!isRecord7(value)) {
7689
+ throw new OhosPerfError(
7690
+ `coverageReport.json: ${section} is missing or not an object`,
7691
+ { code: "SCENARIO_BAD_INPUT" }
7692
+ );
7693
+ }
7694
+ const ratio = (name) => {
7695
+ const counts = readCounts(value[name], `${section}.${name}`);
7696
+ return { ...counts, percent: percentOf(counts) };
7697
+ };
7698
+ return { lines: ratio("lines"), functions: ratio("functions"), branches: ratio("branches") };
7699
+ }
7700
+ function parseCoverageReport(text) {
7701
+ let document;
7702
+ try {
7703
+ document = JSON.parse(text);
7704
+ } catch (err) {
7705
+ throw new OhosPerfError(
7706
+ `coverageReport.json is not valid JSON: ${err.message}`,
7707
+ { code: "SCENARIO_BAD_INPUT", cause: err }
7708
+ );
7709
+ }
7710
+ if (!isRecord7(document) || !("summary" in document) || !("files" in document)) {
7711
+ throw new OhosPerfError(
7712
+ 'coverageReport.json is not a coverage report: it has no "summary" and "files"',
7713
+ { code: "SCENARIO_BAD_INPUT" }
7714
+ );
7715
+ }
7716
+ const summary = readSummary(document["summary"], "summary");
7717
+ const filesRaw = document["files"];
7718
+ if (!Array.isArray(filesRaw)) {
7719
+ throw new OhosPerfError('coverageReport.json: "files" is not an array', {
7720
+ code: "SCENARIO_BAD_INPUT"
7721
+ });
7722
+ }
7723
+ const files = filesRaw.map((entry, index) => {
7724
+ if (!isRecord7(entry) || typeof entry["path"] !== "string") {
7725
+ throw new OhosPerfError(
7726
+ `coverageReport.json: files[${index}] has no string "path"`,
7727
+ { code: "SCENARIO_BAD_INPUT" }
7728
+ );
7729
+ }
7730
+ const fileSummary = readSummary(entry["summary"], `files[${index}].summary`);
7731
+ return {
7732
+ path: entry["path"],
7733
+ lines: fileSummary.lines,
7734
+ functions: fileSummary.functions,
7735
+ branches: fileSummary.branches
7736
+ };
7737
+ });
7738
+ files.sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
7739
+ return {
7740
+ date: typeof document["date"] === "string" ? document["date"] : "",
7741
+ summary,
7742
+ files
7743
+ };
7744
+ }
7745
+ var CoverageAnalyzer = class {
7746
+ id = "coverage";
7747
+ requires = [];
7748
+ async run(ctx) {
7749
+ const text = ctx.coverage;
7750
+ if (text === void 0) {
7751
+ return {
7752
+ metrics: [],
7753
+ evidence: [
7754
+ evidence({
7755
+ kind: "no_data",
7756
+ severity: "info",
7757
+ subject: { process: ctx.app.packageName },
7758
+ window: ctx.window,
7759
+ signals: {},
7760
+ explain: "the scene carries no coverageReport.json; coverage was not measured. An instrumented build (ohos-test-coverage=true) plus the bjc toolchain produces one, and this analyzer reads it rather than running bjc",
7761
+ drillDown: [],
7762
+ key: "coverage:no-report"
7763
+ })
7764
+ ]
7765
+ };
7766
+ }
7767
+ const report = parseCoverageReport(text);
7768
+ const make = (id, value, unit) => metric({
7769
+ id,
7770
+ value,
7771
+ unit,
7772
+ fidelity: "approximate",
7773
+ provenance: {
7774
+ collector: "scene:coverageReport.json",
7775
+ table: "coverage",
7776
+ rows: report.files.length,
7777
+ device: ctx.deviceId
7778
+ }
7779
+ });
7780
+ const metrics = [
7781
+ make("coverage.lines.percent", report.summary.lines.percent, "%"),
7782
+ make("coverage.lines.covered", report.summary.lines.covered, "count"),
7783
+ make("coverage.lines.total", report.summary.lines.total, "count"),
7784
+ make("coverage.functions.percent", report.summary.functions.percent, "%"),
7785
+ make("coverage.branches.percent", report.summary.branches.percent, "%"),
7786
+ make("coverage.files.count", report.files.length, "count")
7787
+ ];
7788
+ const worst = report.files.reduce((low, file) => {
7789
+ if (low === void 0) return file;
7790
+ if (file.lines.percent !== low.lines.percent) {
7791
+ return file.lines.percent < low.lines.percent ? file : low;
7792
+ }
7793
+ return file.path < low.path ? file : low;
7794
+ }, void 0);
7795
+ const items = [];
7796
+ if (worst !== void 0) {
7797
+ items.push(
7798
+ evidence({
7799
+ kind: "coverage",
7800
+ severity: worst.lines.percent < 50 ? "warn" : "info",
7801
+ subject: { process: ctx.app.packageName },
7802
+ window: ctx.window,
7803
+ signals: {
7804
+ path: worst.path,
7805
+ linesPercent: worst.lines.percent,
7806
+ linesCovered: worst.lines.covered,
7807
+ linesTotal: worst.lines.total,
7808
+ functionsPercent: worst.functions.percent,
7809
+ branchesPercent: worst.branches.percent
7810
+ },
7811
+ explain: `${worst.path} is the least-covered file at ${worst.lines.percent}% of lines (${worst.lines.covered}/${worst.lines.total})`,
7812
+ drillDown: [],
7813
+ key: worst.path
7814
+ })
7815
+ );
7816
+ }
7817
+ return { metrics, evidence: items };
7818
+ }
7819
+ };
7820
+
7653
7821
  // src/scenario/actions.ts
7654
7822
  var MAX_SCROLLS = 5;
7655
7823
  var DEFAULT_DISTANCE = 40;
@@ -7893,7 +8061,7 @@ function canonical(tree) {
7893
8061
  node.clickable ? "1" : "0",
7894
8062
  node.enabled ? "1" : "0",
7895
8063
  node.scrollable ? "1" : "0"
7896
- ].map((field) => `${String(field).length}:${String(field)}`).join("");
8064
+ ].map((field2) => `${String(field2).length}:${String(field2)}`).join("");
7897
8065
  return tree.map(line).join("");
7898
8066
  }
7899
8067
  function hashTree(tree) {
@@ -15920,10 +16088,10 @@ function round2HalfEven(value) {
15920
16088
  return negative ? -result : result;
15921
16089
  }
15922
16090
  function decompose(value) {
15923
- const view = new DataView(new ArrayBuffer(8));
15924
- view.setFloat64(0, value);
15925
- const high = view.getUint32(0);
15926
- const low = view.getUint32(4);
16091
+ const view2 = new DataView(new ArrayBuffer(8));
16092
+ view2.setFloat64(0, value);
16093
+ const high = view2.getUint32(0);
16094
+ const low = view2.getUint32(4);
15927
16095
  const exponentBits = high >>> 20 & 2047;
15928
16096
  let mantissa = BigInt(high & 1048575) << 32n | BigInt(low);
15929
16097
  if (exponentBits === 0) return { mantissa, exponent: -1074 };
@@ -17462,7 +17630,8 @@ function defaultAnalyzers() {
17462
17630
  new ComponentReuseAnalyzer(),
17463
17631
  new HilogAnalyzer(),
17464
17632
  new UiAnalyzer(),
17465
- new RedundantFileAnalyzer()
17633
+ new RedundantFileAnalyzer(),
17634
+ new CoverageAnalyzer()
17466
17635
  ];
17467
17636
  }
17468
17637
 
@@ -17594,6 +17763,495 @@ function openZip(bytes) {
17594
17763
  };
17595
17764
  }
17596
17765
 
17766
+ // src/hap/elf.ts
17767
+ var EM_AARCH64 = 183;
17768
+ var SHT_SYMTAB = 2;
17769
+ var SHT_NOBITS = 8;
17770
+ var SHT_DYNSYM = 11;
17771
+ function fail2(message3, cause) {
17772
+ throw new OhosPerfError(message3, { code: "ELF_INVALID", ...cause === void 0 ? {} : { cause } });
17773
+ }
17774
+ function view(bytes) {
17775
+ return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
17776
+ }
17777
+ function field(dv, at, size, what) {
17778
+ if (at < 0 || at + size > dv.byteLength) {
17779
+ fail2(`ELF is truncated: ${what} at offset ${at} runs past the ${dv.byteLength}-byte file`);
17780
+ }
17781
+ if (size === 1) return dv.getUint8(at);
17782
+ if (size === 2) return dv.getUint16(at, true);
17783
+ if (size === 4) return dv.getUint32(at, true);
17784
+ return dv.getUint32(at, true) + dv.getUint32(at + 4, true) * 2 ** 32;
17785
+ }
17786
+ function readString(table, offset) {
17787
+ if (offset < 0 || offset >= table.length) return "";
17788
+ const end = table.indexOf(0, offset);
17789
+ return new TextDecoder("utf-8").decode(
17790
+ table.subarray(offset, end === -1 ? table.length : end)
17791
+ );
17792
+ }
17793
+ function bindOf(info) {
17794
+ const bind = info >> 4;
17795
+ if (bind === 0) return "local";
17796
+ if (bind === 1) return "global";
17797
+ if (bind === 2) return "weak";
17798
+ return "other";
17799
+ }
17800
+ function typeOf(info) {
17801
+ const type = info & 15;
17802
+ if (type === 0) return "notype";
17803
+ if (type === 1) return "object";
17804
+ if (type === 2) return "func";
17805
+ if (type === 3) return "section";
17806
+ if (type === 4) return "file";
17807
+ return "other";
17808
+ }
17809
+ function symbolTableOf(dv, sections, links, bytes, index) {
17810
+ const section = sections[index];
17811
+ const link = links[index];
17812
+ const strings = link >= 0 && link < sections.length ? bytes.subarray(sections[link].offset, sections[link].offset + sections[link].size) : new Uint8Array(0);
17813
+ const entrySize = section.entrySize === 0 ? 24 : section.entrySize;
17814
+ const count = Math.floor(section.size / entrySize);
17815
+ const symbols = [];
17816
+ for (let at = 0; at < count; at += 1) {
17817
+ const base = section.offset + at * entrySize;
17818
+ if (at === 0) continue;
17819
+ const nameOffset = field(dv, base, 4, "st_name");
17820
+ const info = field(dv, base + 4, 1, "st_info");
17821
+ const sectionIndex = field(dv, base + 6, 2, "st_shndx");
17822
+ const size = field(dv, base + 16, 8, "st_size");
17823
+ const name = readString(strings, nameOffset);
17824
+ symbols.push({ name, bind: bindOf(info), type: typeOf(info), size, sectionIndex });
17825
+ }
17826
+ return symbols;
17827
+ }
17828
+ function readElf(bytes) {
17829
+ if (bytes.length < 4) {
17830
+ fail2(`ELF is truncated: ${bytes.length} bytes is shorter than the 4-byte magic`);
17831
+ }
17832
+ if (bytes[0] !== 127 || bytes[1] !== 69 || bytes[2] !== 76 || bytes[3] !== 70) {
17833
+ fail2("not an ELF file: the first four bytes are not \\x7fELF");
17834
+ }
17835
+ if (bytes.length < 16) {
17836
+ fail2(`ELF is truncated: ${bytes.length} bytes is shorter than the 16-byte ident`);
17837
+ }
17838
+ const bits = bytes[4] === 2 ? 64 : bytes[4] === 1 ? 32 : 0;
17839
+ if (bits === 0) {
17840
+ fail2(`unsupported ELF class ${String(bytes[4])}: only 32-bit and 64-bit are defined`);
17841
+ }
17842
+ const endian = bytes[5] === 1 ? "little" : bytes[5] === 2 ? "big" : void 0;
17843
+ if (endian === void 0) {
17844
+ fail2(`unsupported ELF data encoding ${String(bytes[5])}: only little and big endian are defined`);
17845
+ }
17846
+ if (bits !== 64 || endian !== "little") {
17847
+ fail2(`unsupported ELF: ${String(bits)}-bit ${endian}-endian; OHOS ships 64-bit little-endian`);
17848
+ }
17849
+ const headerSize = 64;
17850
+ if (bytes.length < headerSize) {
17851
+ fail2(`ELF is truncated: ${bytes.length} bytes is shorter than the ${headerSize}-byte header`);
17852
+ }
17853
+ const dv = view(bytes);
17854
+ const machine = field(dv, 18, 2, "e_machine");
17855
+ const type = field(dv, 16, 2, "e_type");
17856
+ const shoff = field(dv, 40, 8, "e_shoff");
17857
+ const shentsize = field(dv, 58, 2, "e_shentsize");
17858
+ const shnum = field(dv, 60, 2, "e_shnum");
17859
+ const shstrndx = field(dv, 62, 2, "e_shstrndx");
17860
+ if (shnum === 0) {
17861
+ return {
17862
+ bits: 64,
17863
+ endian,
17864
+ machine,
17865
+ type,
17866
+ sections: [],
17867
+ symbols: [],
17868
+ section: () => void 0,
17869
+ bytesOf: () => new Uint8Array(0)
17870
+ };
17871
+ }
17872
+ if (shentsize !== 64) {
17873
+ fail2(`unsupported section header size ${shentsize}: a 64-bit ELF uses 64`);
17874
+ }
17875
+ if (shoff + shnum * shentsize > bytes.length) {
17876
+ fail2(
17877
+ `ELF is truncated: the section header table at offset ${shoff} with ${shnum} entries runs past the ${bytes.length}-byte file`
17878
+ );
17879
+ }
17880
+ if (shstrndx >= shnum) {
17881
+ fail2(`e_shstrndx ${shstrndx} names a section beyond the ${shnum} the file declares`);
17882
+ }
17883
+ const raw = [];
17884
+ const links = [];
17885
+ for (let index = 0; index < shnum; index += 1) {
17886
+ const at = shoff + index * shentsize;
17887
+ raw.push({
17888
+ nameOffset: field(dv, at, 4, `section[${index}].sh_name`),
17889
+ type: field(dv, at + 4, 4, `section[${index}].sh_type`),
17890
+ flags: field(dv, at + 8, 8, `section[${index}].sh_flags`),
17891
+ offset: field(dv, at + 24, 8, `section[${index}].sh_offset`),
17892
+ size: field(dv, at + 32, 8, `section[${index}].sh_size`),
17893
+ link: field(dv, at + 40, 4, `section[${index}].sh_link`),
17894
+ entrySize: field(dv, at + 56, 8, `section[${index}].sh_entsize`)
17895
+ });
17896
+ links.push(raw[index].link);
17897
+ }
17898
+ for (const [index, section] of raw.entries()) {
17899
+ if (section.type === SHT_NOBITS || section.type === 0) continue;
17900
+ if (section.offset + section.size > bytes.length) {
17901
+ fail2(
17902
+ `ELF is truncated: section ${index} at offset ${section.offset} with size ${section.size} runs past the ${bytes.length}-byte file`
17903
+ );
17904
+ }
17905
+ }
17906
+ const nameTable = raw[shstrndx];
17907
+ const strings = bytes.subarray(nameTable.offset, nameTable.offset + nameTable.size);
17908
+ const sections = raw.map((section) => ({
17909
+ name: readString(strings, section.nameOffset),
17910
+ type: section.type,
17911
+ flags: section.flags,
17912
+ offset: section.offset,
17913
+ size: section.size,
17914
+ entrySize: section.entrySize
17915
+ }));
17916
+ const symbols = [];
17917
+ for (const [index, section] of sections.entries()) {
17918
+ if (section.type !== SHT_SYMTAB && section.type !== SHT_DYNSYM) continue;
17919
+ symbols.push(...symbolTableOf(dv, sections, links, bytes, index));
17920
+ }
17921
+ const byName = new Map(sections.map((section) => [section.name, section]));
17922
+ return {
17923
+ bits: 64,
17924
+ endian,
17925
+ machine,
17926
+ type,
17927
+ sections,
17928
+ symbols,
17929
+ section: (name) => byName.get(name),
17930
+ bytesOf: (name) => {
17931
+ const section = byName.get(name);
17932
+ if (section === void 0 || section.type === SHT_NOBITS) return new Uint8Array(0);
17933
+ return bytes.subarray(section.offset, section.offset + section.size);
17934
+ }
17935
+ };
17936
+ }
17937
+ function classifyInstruction(word) {
17938
+ const masked = (mask) => (word & mask) >>> 0;
17939
+ if (masked(4294966303) === 3596550144) return "ret";
17940
+ if (masked(4294966303) === 3594452992) return "blr";
17941
+ if (masked(4294966303) === 3592355840) return "br";
17942
+ if (masked(4227858432) === 2483027968) return "bl";
17943
+ if (masked(4227858432) === 335544320) return "b";
17944
+ if (masked(4278190096) === 1409286144) return "bcond";
17945
+ if (masked(2113929216) === 872415232) return "cbz";
17946
+ if (masked(2113929216) === 905969664) return "tbz";
17947
+ if (masked(2667577344) === 2415919104) return "adrp";
17948
+ if (masked(2667577344) === 268435456) return "adr";
17949
+ if (masked(989855744) === 956301312) {
17950
+ return masked(4194304) === 0 ? "str" : "ldr";
17951
+ }
17952
+ if (masked(520093696) === 285212672) return "add";
17953
+ if (masked(167772160) === 167772160) return "vector";
17954
+ return "other";
17955
+ }
17956
+ function countInstructions(payload) {
17957
+ const counts = {
17958
+ total: 0,
17959
+ ret: 0,
17960
+ blr: 0,
17961
+ br: 0,
17962
+ bl: 0,
17963
+ b: 0,
17964
+ bcond: 0,
17965
+ cbz: 0,
17966
+ tbz: 0,
17967
+ adrp: 0,
17968
+ adr: 0,
17969
+ ldr: 0,
17970
+ str: 0,
17971
+ add: 0,
17972
+ vector: 0,
17973
+ other: 0
17974
+ };
17975
+ const dv = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
17976
+ const words = Math.floor(payload.length / 4);
17977
+ for (let index = 0; index < words; index += 1) {
17978
+ const cls = classifyInstruction(dv.getUint32(index * 4, true));
17979
+ counts[cls] += 1;
17980
+ counts.total += 1;
17981
+ }
17982
+ return counts;
17983
+ }
17984
+
17985
+ // src/hap/optimization.ts
17986
+ var OFFLINE_WINDOW = { startNs: 0, endNs: 0 };
17987
+ var LTO_PATTERNS = [
17988
+ { pattern: /^lto_priv\./, why: "lto_priv symbol" },
17989
+ { pattern: /^\.gnu\.lto_/, why: ".gnu.lto section" },
17990
+ { pattern: /^\.gnu\.lto$/, why: ".gnu.lto section" },
17991
+ { pattern: /^lto_[0-9]+\.[0-9]+$/, why: "lto_N.M symbol" }
17992
+ ];
17993
+ var RECORDED_FLAG = /^-(O[0-3s]|Oz|Ofast)$/;
17994
+ var LEVEL_OF_FLAG = {
17995
+ "-O0": "unoptimized",
17996
+ "-O1": "low",
17997
+ "-O2": "medium",
17998
+ "-O3": "high",
17999
+ "-Os": "medium",
18000
+ "-Oz": "medium",
18001
+ "-Ofast": "high"
18002
+ };
18003
+ var VECTOR_DENSITY_HIGH = 0.1;
18004
+ var VECTOR_DENSITY_NONE = 0.02;
18005
+ function byString6(a, b) {
18006
+ return a < b ? -1 : a > b ? 1 : 0;
18007
+ }
18008
+ function decode(bytes) {
18009
+ return new TextDecoder("utf-8").decode(bytes);
18010
+ }
18011
+ function commentStrings(bytes) {
18012
+ return decode(bytes).split("\0").map((part) => part.trim()).filter((part) => part !== "");
18013
+ }
18014
+ function inspectBinary(input) {
18015
+ let elf;
18016
+ try {
18017
+ elf = readElf(input.bytes);
18018
+ } catch (err) {
18019
+ throw new OhosPerfError(
18020
+ `${input.path}: ${err.message}`,
18021
+ { code: "ELF_INVALID", cause: err }
18022
+ );
18023
+ }
18024
+ const textSection = elf.section(".text");
18025
+ const textBytes = textSection?.size ?? 0;
18026
+ const instructions = countInstructions(elf.bytesOf(".text"));
18027
+ const symbolTablePresent = elf.sections.some(
18028
+ (section) => section.type === 2 || section.type === 11
18029
+ );
18030
+ const ltoMarkers = [];
18031
+ for (const section of elf.sections) {
18032
+ if (LTO_PATTERNS.some((entry) => entry.pattern.test(section.name))) {
18033
+ ltoMarkers.push(section.name);
18034
+ }
18035
+ }
18036
+ for (const symbol of elf.symbols) {
18037
+ if (LTO_PATTERNS.some((entry) => entry.pattern.test(symbol.name))) {
18038
+ ltoMarkers.push(symbol.name);
18039
+ }
18040
+ }
18041
+ const lto = ltoMarkers.length > 0 ? "present" : symbolTablePresent ? "absent" : "unknown";
18042
+ const debugSections = elf.sections.map((section) => section.name).filter((name) => name.startsWith(".debug_") || name === ".zdebug_info");
18043
+ const commentSection = elf.section(".comment");
18044
+ const compiler = commentSection === void 0 ? [] : commentStrings(elf.bytesOf(".comment"));
18045
+ const recordedFlags = [];
18046
+ for (const line of compiler) {
18047
+ for (const token of line.split(/\s+/)) {
18048
+ if (RECORDED_FLAG.test(token) && !recordedFlags.includes(token)) recordedFlags.push(token);
18049
+ }
18050
+ }
18051
+ const functions = elf.symbols.filter((symbol) => symbol.type === "func");
18052
+ const countBind = (bind) => functions.filter((symbol) => symbol.bind === bind).length;
18053
+ return {
18054
+ path: input.path,
18055
+ size: input.bytes.length,
18056
+ machine: elf.machine,
18057
+ textBytes,
18058
+ instructions,
18059
+ lto,
18060
+ ltoMarkers,
18061
+ debug: debugSections.length > 0,
18062
+ debugSections,
18063
+ compiler,
18064
+ recordedFlags,
18065
+ symbols: {
18066
+ functions: functions.length,
18067
+ global: countBind("global"),
18068
+ local: countBind("local"),
18069
+ weak: countBind("weak")
18070
+ },
18071
+ stripped: functions.length === 0
18072
+ };
18073
+ }
18074
+ function classifyOptimization(facts) {
18075
+ for (const flag2 of facts.recordedFlags) {
18076
+ const level = LEVEL_OF_FLAG[flag2];
18077
+ if (level !== void 0) return { level, basis: "recorded", signals: [] };
18078
+ }
18079
+ const total = facts.instructions.total;
18080
+ if (total === 0) {
18081
+ return { level: "unknown", basis: "none", signals: [] };
18082
+ }
18083
+ const vectorDensity = facts.instructions.vector / total;
18084
+ if (vectorDensity >= VECTOR_DENSITY_HIGH) {
18085
+ return { level: "high", basis: "inferred", signals: ["vector_density"] };
18086
+ }
18087
+ if (facts.debug) {
18088
+ return {
18089
+ level: "unoptimized",
18090
+ basis: "inferred",
18091
+ signals: vectorDensity <= VECTOR_DENSITY_NONE ? ["debug_sections", "no_vector_code"] : ["debug_sections"]
18092
+ };
18093
+ }
18094
+ if (vectorDensity <= VECTOR_DENSITY_NONE) {
18095
+ return { level: "low", basis: "inferred", signals: ["no_vector_code"] };
18096
+ }
18097
+ return { level: "medium", basis: "inferred", signals: ["vector_density"] };
18098
+ }
18099
+ var ARM64_LIBRARY = /^(?:libs|lib)\/arm64(?:-v8a)?\//;
18100
+ var SHARED_OBJECT = /\.so(?:\.|$)/;
18101
+ function extractBinaries(input) {
18102
+ if (input.path.endsWith(".a")) {
18103
+ throw new OhosPerfError(
18104
+ `${input.path}: an .a archive is not read by this package; pass the .so files (or the package that contains them) instead`,
18105
+ { code: "SCENARIO_BAD_INPUT" }
18106
+ );
18107
+ }
18108
+ if (!isZip(input.bytes)) {
18109
+ return [{ path: input.path, bytes: input.bytes }];
18110
+ }
18111
+ const archive = openZip(input.bytes);
18112
+ const binaries = [];
18113
+ for (const entry of archive.entries) {
18114
+ if (!ARM64_LIBRARY.test(entry.name)) continue;
18115
+ if (!SHARED_OBJECT.test(entry.name)) continue;
18116
+ const bytes = archive.read(entry);
18117
+ if (bytes.length < 4 || bytes[0] !== 127 || bytes[1] !== 69) continue;
18118
+ binaries.push({ path: entry.name, bytes });
18119
+ }
18120
+ if (binaries.length === 0) {
18121
+ throw new OhosPerfError(
18122
+ `${input.path}: no arm64 libraries (libs/arm64/*.so) in the package`,
18123
+ { code: "SCENARIO_BAD_INPUT" }
18124
+ );
18125
+ }
18126
+ return binaries;
18127
+ }
18128
+ function offlineProvenance(rows) {
18129
+ return { collector: "offline", table: "elf", rows, device: "offline" };
18130
+ }
18131
+ var LEVEL_IDS = {
18132
+ unoptimized: "binary.unoptimized.files.count",
18133
+ low: "binary.low.optimization.files.count",
18134
+ medium: "binary.medium.optimization.files.count",
18135
+ high: "binary.high.optimization.files.count",
18136
+ unknown: "binary.unknown.optimization.files.count"
18137
+ };
18138
+ function buildMetrics(binaries) {
18139
+ const rows = binaries.length;
18140
+ const make = (id, value, unit, fidelity) => metric({
18141
+ id,
18142
+ value,
18143
+ unit,
18144
+ fidelity,
18145
+ provenance: offlineProvenance(rows),
18146
+ window: OFFLINE_WINDOW
18147
+ });
18148
+ const metrics = [
18149
+ make("binary.files.count", rows, "count", "exact"),
18150
+ make("binary.text.bytes", binaries.reduce((sum, b) => sum + b.facts.textBytes, 0), "bytes", "exact"),
18151
+ make(
18152
+ "binary.instructions.count",
18153
+ binaries.reduce((sum, b) => sum + b.facts.instructions.total, 0),
18154
+ "count",
18155
+ "exact"
18156
+ ),
18157
+ make("binary.lto.files.count", binaries.filter((b) => b.facts.lto === "present").length, "count", "exact"),
18158
+ make("binary.lto.unknown.files.count", binaries.filter((b) => b.facts.lto === "unknown").length, "count", "exact"),
18159
+ make("binary.debug.files.count", binaries.filter((b) => b.facts.debug).length, "count", "exact"),
18160
+ make("binary.stripped.files.count", binaries.filter((b) => b.facts.stripped).length, "count", "exact")
18161
+ ];
18162
+ const byLevel = /* @__PURE__ */ new Map();
18163
+ for (const binary of binaries) {
18164
+ byLevel.set(binary.verdict.level, (byLevel.get(binary.verdict.level) ?? 0) + 1);
18165
+ }
18166
+ for (const level of ["unoptimized", "low", "medium", "high", "unknown"]) {
18167
+ const count = byLevel.get(level) ?? 0;
18168
+ if (count === 0) continue;
18169
+ metrics.push(make(LEVEL_IDS[level], count, "count", "proxy"));
18170
+ }
18171
+ return metrics.sort((a, b) => byString6(a.id, b.id));
18172
+ }
18173
+ function buildEvidence(packageName, binaries) {
18174
+ const subject = { process: packageName };
18175
+ const items = [];
18176
+ for (const binary of binaries) {
18177
+ if (binary.facts.lto === "present") {
18178
+ items.push(evidence({
18179
+ kind: "optimization",
18180
+ severity: "info",
18181
+ subject,
18182
+ window: OFFLINE_WINDOW,
18183
+ signals: {
18184
+ path: binary.path,
18185
+ lto: "present",
18186
+ markers: binary.facts.ltoMarkers.length,
18187
+ level: binary.verdict.level,
18188
+ basis: binary.verdict.basis
18189
+ },
18190
+ explain: `${binary.path} was linked with LTO: ${binary.facts.ltoMarkers.slice(0, 3).join(", ")}` + (binary.facts.ltoMarkers.length > 3 ? `, and ${binary.facts.ltoMarkers.length - 3} more` : ""),
18191
+ drillDown: [],
18192
+ key: `${binary.path}:lto`
18193
+ }));
18194
+ }
18195
+ if (binary.facts.instructions.total === 0) {
18196
+ items.push(evidence({
18197
+ kind: "no_data",
18198
+ severity: "info",
18199
+ subject,
18200
+ window: OFFLINE_WINDOW,
18201
+ signals: { path: binary.path },
18202
+ explain: `${binary.path} has no instructions in .text, so its optimization level was not measured; a binary with no code carries no evidence either way`,
18203
+ drillDown: [],
18204
+ key: `${binary.path}:no-text`
18205
+ }));
18206
+ }
18207
+ if (binary.verdict.level === "unoptimized" || binary.verdict.level === "low") {
18208
+ items.push(evidence({
18209
+ kind: "optimization",
18210
+ severity: binary.verdict.level === "unoptimized" ? "warn" : "info",
18211
+ subject,
18212
+ window: OFFLINE_WINDOW,
18213
+ signals: {
18214
+ path: binary.path,
18215
+ level: binary.verdict.level,
18216
+ basis: binary.verdict.basis,
18217
+ signals: [...binary.verdict.signals],
18218
+ vectorDensity: binary.facts.instructions.total === 0 ? 0 : Math.round(binary.facts.instructions.vector / binary.facts.instructions.total * 1e4) / 1e4
18219
+ },
18220
+ explain: `${binary.path} reads as ${binary.verdict.level} optimization` + (binary.verdict.basis === "recorded" ? ` from its recorded flag ${binary.facts.recordedFlags.join(" ")}` : ` from its instruction mix (${binary.verdict.signals.join(", ")})`),
18221
+ drillDown: [],
18222
+ key: `${binary.path}:level`
18223
+ }));
18224
+ }
18225
+ }
18226
+ return items.sort((a, b) => byString6(a.kind, b.kind) || byString6(a.id, b.id));
18227
+ }
18228
+ function analyzeBinaries(inputs, packageName) {
18229
+ const binaries = [...inputs].sort((a, b) => byString6(a.path, b.path)).map((input) => {
18230
+ const facts = inspectBinary(input);
18231
+ return { path: facts.path, facts, verdict: classifyOptimization(facts) };
18232
+ });
18233
+ return {
18234
+ schemaVersion: 1,
18235
+ package: packageName,
18236
+ binaries,
18237
+ totals: {
18238
+ binaries: binaries.length,
18239
+ lto: binaries.filter((binary) => binary.facts.lto === "present").length,
18240
+ debug: binaries.filter((binary) => binary.facts.debug).length,
18241
+ stripped: binaries.filter((binary) => binary.facts.stripped).length
18242
+ },
18243
+ metrics: buildMetrics(binaries),
18244
+ evidence: buildEvidence(packageName, binaries)
18245
+ };
18246
+ }
18247
+ function optimizationSection(analysis) {
18248
+ return {
18249
+ analyzerId: "optimization",
18250
+ status: "measured",
18251
+ result: { metrics: analysis.metrics, evidence: analysis.evidence }
18252
+ };
18253
+ }
18254
+
17597
18255
  // src/hap/inventory.ts
17598
18256
  var CATEGORY_EXTENSIONS = {
17599
18257
  images: ["png", "jpg", "jpeg", "gif", "bmp", "webp", "svg"],
@@ -17648,7 +18306,7 @@ function buildInventory(archive) {
17648
18306
  // src/hap/rules.ts
17649
18307
  var EXCLUDE_PATTERNS = ["resources/base/.*"];
17650
18308
  var KINDS2 = ["filename", "path", "extension", "magic", "content", "combined"];
17651
- function fail2(ruleId, message3) {
18309
+ function fail3(ruleId, message3) {
17652
18310
  throw new OhosPerfError(`rule ${JSON.stringify(ruleId)}: ${message3}`, { code: "HAP_BAD_RULE" });
17653
18311
  }
17654
18312
  function basename3(path) {
@@ -17658,7 +18316,7 @@ function compile(ruleId, source) {
17658
18316
  try {
17659
18317
  return new RegExp(source);
17660
18318
  } catch (err) {
17661
- return fail2(ruleId, `invalid pattern ${JSON.stringify(source)}: ${err.message}`);
18319
+ return fail3(ruleId, `invalid pattern ${JSON.stringify(source)}: ${err.message}`);
17662
18320
  }
17663
18321
  }
17664
18322
  var EntryReader = class {
@@ -17814,15 +18472,15 @@ function matchHapRules(rules, archive, inventory) {
17814
18472
  function validateRules(rules) {
17815
18473
  const seen = /* @__PURE__ */ new Set();
17816
18474
  for (const rule of rules) {
17817
- if (seen.has(rule.id)) fail2(rule.id, "duplicate rule id");
18475
+ if (seen.has(rule.id)) fail3(rule.id, "duplicate rule id");
17818
18476
  seen.add(rule.id);
17819
- if (rule.fileRules.length === 0) fail2(rule.id, "has no file rules");
18477
+ if (rule.fileRules.length === 0) fail3(rule.id, "has no file rules");
17820
18478
  if (rule.requireMetadata === true && (rule.metadataPatterns ?? []).length === 0) {
17821
- fail2(rule.id, "requires metadata but names no metadata pattern");
18479
+ fail3(rule.id, "requires metadata but names no metadata pattern");
17822
18480
  }
17823
18481
  for (const pattern of rule.metadataPatterns ?? []) {
17824
18482
  if (pattern.source !== "content" && pattern.source !== "path" && pattern.source !== "filename") {
17825
- fail2(rule.id, `metadata field ${JSON.stringify(pattern.field)} has unknown source ${JSON.stringify(pattern.source)}`);
18483
+ fail3(rule.id, `metadata field ${JSON.stringify(pattern.field)} has unknown source ${JSON.stringify(pattern.source)}`);
17826
18484
  }
17827
18485
  compile(rule.id, pattern.pattern);
17828
18486
  }
@@ -17831,28 +18489,28 @@ function validateRules(rules) {
17831
18489
  }
17832
18490
  function validateFileRules(ruleId, rules) {
17833
18491
  for (const rule of rules) {
17834
- if (!KINDS2.includes(rule.kind)) fail2(ruleId, `unknown rule kind ${JSON.stringify(rule.kind)}`);
18492
+ if (!KINDS2.includes(rule.kind)) fail3(ruleId, `unknown rule kind ${JSON.stringify(rule.kind)}`);
17835
18493
  switch (rule.kind) {
17836
18494
  case "filename":
17837
18495
  case "path":
17838
18496
  case "content":
17839
- if ((rule.patterns ?? []).length === 0) fail2(ruleId, `a ${rule.kind} rule names no pattern`);
18497
+ if ((rule.patterns ?? []).length === 0) fail3(ruleId, `a ${rule.kind} rule names no pattern`);
17840
18498
  for (const item of rule.patterns ?? []) compile(ruleId, typeof item === "string" ? item : item.pattern);
17841
18499
  break;
17842
18500
  case "extension":
17843
- if ((rule.extensions ?? []).length === 0) fail2(ruleId, "an extension rule names no extension");
18501
+ if ((rule.extensions ?? []).length === 0) fail3(ruleId, "an extension rule names no extension");
17844
18502
  break;
17845
18503
  case "magic":
17846
- if ((rule.bytes ?? []).length === 0) fail2(ruleId, "a magic rule names no bytes");
18504
+ if ((rule.bytes ?? []).length === 0) fail3(ruleId, "a magic rule names no bytes");
17847
18505
  for (const byte of rule.bytes ?? []) {
17848
- if (!Number.isInteger(byte) || byte < 0 || byte > 255) fail2(ruleId, `magic byte ${byte} is not a byte`);
18506
+ if (!Number.isInteger(byte) || byte < 0 || byte > 255) fail3(ruleId, `magic byte ${byte} is not a byte`);
17849
18507
  }
17850
18508
  break;
17851
18509
  case "combined":
17852
18510
  if (rule.operator !== "and" && rule.operator !== "or" && rule.operator !== "not") {
17853
- fail2(ruleId, `combined rule has operator ${JSON.stringify(rule.operator)}`);
18511
+ fail3(ruleId, `combined rule has operator ${JSON.stringify(rule.operator)}`);
17854
18512
  }
17855
- if ((rule.rules ?? []).length === 0) fail2(ruleId, "a combined rule names no sub-rules");
18513
+ if ((rule.rules ?? []).length === 0) fail3(ruleId, "a combined rule names no sub-rules");
17856
18514
  validateFileRules(ruleId, rule.rules ?? []);
17857
18515
  break;
17858
18516
  }
@@ -18235,10 +18893,10 @@ var TECH_RULES = [
18235
18893
 
18236
18894
  // src/hap/analyze.ts
18237
18895
  import { createHash as createHash3 } from "node:crypto";
18238
- var OFFLINE_WINDOW = { startNs: 0, endNs: 0 };
18896
+ var OFFLINE_WINDOW2 = { startNs: 0, endNs: 0 };
18239
18897
  var LARGEST_COUNT = 10;
18240
18898
  var EXPLAIN_PATHS = 5;
18241
- function byString6(a, b) {
18899
+ function byString7(a, b) {
18242
18900
  return a < b ? -1 : a > b ? 1 : 0;
18243
18901
  }
18244
18902
  function sha256(bytes) {
@@ -18290,7 +18948,7 @@ function findDuplicates(archive, inventory) {
18290
18948
  const groups = [];
18291
18949
  for (const [hash, files] of byHash) {
18292
18950
  if (files.length < 2) continue;
18293
- const sorted = [...files].sort((a, b) => byString6(a.path, b.path));
18951
+ const sorted = [...files].sort((a, b) => byString7(a.path, b.path));
18294
18952
  const size = sorted[0].size;
18295
18953
  groups.push({
18296
18954
  sha256: hash,
@@ -18300,7 +18958,7 @@ function findDuplicates(archive, inventory) {
18300
18958
  paths: sorted.map((file) => file.path)
18301
18959
  });
18302
18960
  }
18303
- return groups.sort((a, b) => byString6(a.sha256, b.sha256));
18961
+ return groups.sort((a, b) => byString7(a.sha256, b.sha256));
18304
18962
  }
18305
18963
  function findOversized(inventory) {
18306
18964
  return inventory.filter((file) => file.size > CATEGORY_MAX_BYTES[file.category]).map((file) => ({
@@ -18308,7 +18966,7 @@ function findOversized(inventory) {
18308
18966
  category: file.category,
18309
18967
  size: file.size,
18310
18968
  threshold: CATEGORY_MAX_BYTES[file.category]
18311
- })).sort((a, b) => b.size - a.size || byString6(a.path, b.path));
18969
+ })).sort((a, b) => b.size - a.size || byString7(a.path, b.path));
18312
18970
  }
18313
18971
  function categoryTotals(inventory) {
18314
18972
  const totals = /* @__PURE__ */ new Map();
@@ -18321,72 +18979,72 @@ function categoryTotals(inventory) {
18321
18979
  compressedSize: (current?.compressedSize ?? 0) + file.compressedSize
18322
18980
  });
18323
18981
  }
18324
- return [...totals.values()].sort((a, b) => byString6(a.name, b.name));
18982
+ return [...totals.values()].sort((a, b) => byString7(a.name, b.name));
18325
18983
  }
18326
18984
  function listPaths(paths) {
18327
18985
  const shown = paths.slice(0, EXPLAIN_PATHS).join(", ");
18328
18986
  return paths.length > EXPLAIN_PATHS ? `${shown}, and ${paths.length - EXPLAIN_PATHS} more` : shown;
18329
18987
  }
18330
- function offlineProvenance(rows) {
18988
+ function offlineProvenance2(rows) {
18331
18989
  return { collector: "offline", table: "hap", rows, device: "offline" };
18332
18990
  }
18333
- function buildMetrics(analysis) {
18991
+ function buildMetrics2(analysis) {
18334
18992
  const metrics = [
18335
18993
  metric({
18336
18994
  id: "hap.files.count",
18337
18995
  value: analysis.totals.files,
18338
18996
  unit: "count",
18339
- provenance: offlineProvenance(analysis.totals.files),
18997
+ provenance: offlineProvenance2(analysis.totals.files),
18340
18998
  fidelity: "exact",
18341
- window: OFFLINE_WINDOW
18999
+ window: OFFLINE_WINDOW2
18342
19000
  }),
18343
19001
  metric({
18344
19002
  id: "hap.size.bytes",
18345
19003
  value: analysis.totals.size,
18346
19004
  unit: "bytes",
18347
- provenance: offlineProvenance(analysis.totals.files),
19005
+ provenance: offlineProvenance2(analysis.totals.files),
18348
19006
  fidelity: "exact",
18349
- window: OFFLINE_WINDOW
19007
+ window: OFFLINE_WINDOW2
18350
19008
  }),
18351
19009
  metric({
18352
19010
  id: "hap.size.compressed.bytes",
18353
19011
  value: analysis.totals.compressedSize,
18354
19012
  unit: "bytes",
18355
- provenance: offlineProvenance(analysis.totals.files),
19013
+ provenance: offlineProvenance2(analysis.totals.files),
18356
19014
  fidelity: "exact",
18357
- window: OFFLINE_WINDOW
19015
+ window: OFFLINE_WINDOW2
18358
19016
  }),
18359
19017
  metric({
18360
19018
  id: "hap.techstack.count",
18361
19019
  value: analysis.technologies.length,
18362
19020
  unit: "count",
18363
- provenance: offlineProvenance(analysis.technologies.length),
19021
+ provenance: offlineProvenance2(analysis.technologies.length),
18364
19022
  fidelity: "exact",
18365
- window: OFFLINE_WINDOW
19023
+ window: OFFLINE_WINDOW2
18366
19024
  }),
18367
19025
  metric({
18368
19026
  id: "hap.duplicates.groups",
18369
19027
  value: analysis.duplicates.length,
18370
19028
  unit: "count",
18371
- provenance: offlineProvenance(analysis.duplicates.length),
19029
+ provenance: offlineProvenance2(analysis.duplicates.length),
18372
19030
  fidelity: "exact",
18373
- window: OFFLINE_WINDOW
19031
+ window: OFFLINE_WINDOW2
18374
19032
  }),
18375
19033
  metric({
18376
19034
  id: "hap.duplicates.wasted.bytes",
18377
19035
  value: analysis.duplicates.reduce((sum, group) => sum + group.wastedBytes, 0),
18378
19036
  unit: "bytes",
18379
- provenance: offlineProvenance(analysis.duplicates.length),
19037
+ provenance: offlineProvenance2(analysis.duplicates.length),
18380
19038
  fidelity: "exact",
18381
- window: OFFLINE_WINDOW
19039
+ window: OFFLINE_WINDOW2
18382
19040
  }),
18383
19041
  metric({
18384
19042
  id: "hap.oversized.count",
18385
19043
  value: analysis.oversized.length,
18386
19044
  unit: "count",
18387
- provenance: offlineProvenance(analysis.oversized.length),
19045
+ provenance: offlineProvenance2(analysis.oversized.length),
18388
19046
  fidelity: "exact",
18389
- window: OFFLINE_WINDOW
19047
+ window: OFFLINE_WINDOW2
18390
19048
  })
18391
19049
  ];
18392
19050
  const byType = /* @__PURE__ */ new Map();
@@ -18398,9 +19056,9 @@ function buildMetrics(analysis) {
18398
19056
  id: `hap.techstack.${type}.files`,
18399
19057
  value: files,
18400
19058
  unit: "count",
18401
- provenance: offlineProvenance(files),
19059
+ provenance: offlineProvenance2(files),
18402
19060
  fidelity: "exact",
18403
- window: OFFLINE_WINDOW
19061
+ window: OFFLINE_WINDOW2
18404
19062
  }));
18405
19063
  }
18406
19064
  for (const category of analysis.categories) {
@@ -18408,14 +19066,14 @@ function buildMetrics(analysis) {
18408
19066
  id: `hap.category.${category.name}.bytes`,
18409
19067
  value: category.size,
18410
19068
  unit: "bytes",
18411
- provenance: offlineProvenance(category.files),
19069
+ provenance: offlineProvenance2(category.files),
18412
19070
  fidelity: "exact",
18413
- window: OFFLINE_WINDOW
19071
+ window: OFFLINE_WINDOW2
18414
19072
  }));
18415
19073
  }
18416
- return metrics.sort((a, b) => byString6(a.id, b.id));
19074
+ return metrics.sort((a, b) => byString7(a.id, b.id));
18417
19075
  }
18418
- function buildEvidence(analysis) {
19076
+ function buildEvidence2(analysis) {
18419
19077
  const subject = { process: analysis.package.bundleName === "" ? analysis.package.name : analysis.package.bundleName };
18420
19078
  const items = [];
18421
19079
  for (const match of analysis.technologies) {
@@ -18423,7 +19081,7 @@ function buildEvidence(analysis) {
18423
19081
  kind: "tech_stack",
18424
19082
  severity: "info",
18425
19083
  subject,
18426
- window: OFFLINE_WINDOW,
19084
+ window: OFFLINE_WINDOW2,
18427
19085
  signals: {
18428
19086
  rule: match.ruleId,
18429
19087
  type: match.type,
@@ -18441,7 +19099,7 @@ function buildEvidence(analysis) {
18441
19099
  kind: "duplicate_asset",
18442
19100
  severity: "warn",
18443
19101
  subject,
18444
- window: OFFLINE_WINDOW,
19102
+ window: OFFLINE_WINDOW2,
18445
19103
  signals: {
18446
19104
  hash: group.sha256,
18447
19105
  size: group.size,
@@ -18458,14 +19116,14 @@ function buildEvidence(analysis) {
18458
19116
  kind: "oversized_asset",
18459
19117
  severity: "info",
18460
19118
  subject,
18461
- window: OFFLINE_WINDOW,
19119
+ window: OFFLINE_WINDOW2,
18462
19120
  signals: { category: file.category, size: file.size, threshold: file.threshold },
18463
19121
  explain: `${file.path} is ${file.size} bytes, above the ${file.category} limit of ${file.threshold} bytes`,
18464
19122
  drillDown: [],
18465
19123
  key: file.path
18466
19124
  }));
18467
19125
  }
18468
- return items.sort((a, b) => byString6(a.kind, b.kind) || a.window.startNs - b.window.startNs || byString6(a.id, b.id));
19126
+ return items.sort((a, b) => byString7(a.kind, b.kind) || a.window.startNs - b.window.startNs || byString7(a.id, b.id));
18469
19127
  }
18470
19128
  function analyzeHap(bytes, packageName) {
18471
19129
  const archive = openZip(bytes);
@@ -18481,7 +19139,7 @@ function analyzeHap(bytes, packageName) {
18481
19139
  size: inventory.reduce((sum, file) => sum + file.size, 0),
18482
19140
  compressedSize: inventory.reduce((sum, file) => sum + file.compressedSize, 0)
18483
19141
  };
18484
- const largest = [...inventory].sort((a, b) => b.size - a.size || byString6(a.path, b.path)).slice(0, LARGEST_COUNT).map((file) => ({ path: file.path, size: file.size }));
19142
+ const largest = [...inventory].sort((a, b) => b.size - a.size || byString7(a.path, b.path)).slice(0, LARGEST_COUNT).map((file) => ({ path: file.path, size: file.size }));
18485
19143
  const analysis = {
18486
19144
  schemaVersion: 1,
18487
19145
  package: { name: packageName, ...packageBlock },
@@ -18495,8 +19153,8 @@ function analyzeHap(bytes, packageName) {
18495
19153
  return {
18496
19154
  ...analysis,
18497
19155
  files: inventory,
18498
- metrics: buildMetrics(analysis),
18499
- evidence: buildEvidence(analysis)
19156
+ metrics: buildMetrics2(analysis),
19157
+ evidence: buildEvidence2(analysis)
18500
19158
  };
18501
19159
  }
18502
19160
  function hapSection(analysis) {
@@ -18694,6 +19352,7 @@ export {
18694
19352
  CallstackQuery,
18695
19353
  CapabilityMatrix,
18696
19354
  ComponentReuseAnalyzer,
19355
+ CoverageAnalyzer,
18697
19356
  DEFAULT_HILOG_RULES,
18698
19357
  DEFAULT_QUERY_LIMIT,
18699
19358
  DEVICE_PERF_PATH,
@@ -18701,6 +19360,7 @@ export {
18701
19360
  DEVICE_UI_PATH,
18702
19361
  Device,
18703
19362
  DeviceNotFoundError,
19363
+ EM_AARCH64,
18704
19364
  EXCLUDE_PATTERNS,
18705
19365
  EmptyFrameAnalyzer,
18706
19366
  EmulatorClient,
@@ -18775,6 +19435,7 @@ export {
18775
19435
  VsyncAnalyzer,
18776
19436
  aggregateUnreleased,
18777
19437
  analyseAnimations,
19438
+ analyzeBinaries,
18778
19439
  analyzeHap,
18779
19440
  analyzeThreadWakeup,
18780
19441
  animationSeverity,
@@ -18786,7 +19447,9 @@ export {
18786
19447
  buildReport,
18787
19448
  buildTrend,
18788
19449
  categorize,
19450
+ classifyInstruction,
18789
19451
  classifyNativePath,
19452
+ classifyOptimization,
18790
19453
  compareImages,
18791
19454
  compareRegion,
18792
19455
  compareResults,
@@ -18802,6 +19465,7 @@ export {
18802
19465
  computeThreadAnalysis,
18803
19466
  computeVsyncAnomalies,
18804
19467
  connect,
19468
+ countInstructions,
18805
19469
  createSceneLayout,
18806
19470
  cropRegion,
18807
19471
  decodePng,
@@ -18816,6 +19480,7 @@ export {
18816
19480
  executeAction,
18817
19481
  explorationDevice,
18818
19482
  explore,
19483
+ extractBinaries,
18819
19484
  filterEmptyFrames,
18820
19485
  flattenUiTree,
18821
19486
  ftracePlugin,
@@ -18824,6 +19489,7 @@ export {
18824
19489
  hashTree,
18825
19490
  hiperfRecordCommand,
18826
19491
  ingestScene,
19492
+ inspectBinary,
18827
19493
  isUnresolvedSymbol,
18828
19494
  isZip,
18829
19495
  loadCases,
@@ -18839,9 +19505,11 @@ export {
18839
19505
  nodeIdentity,
18840
19506
  openDb,
18841
19507
  openZip,
19508
+ optimizationSection,
18842
19509
  pairNativeMemory,
18843
19510
  paritySummary,
18844
19511
  parseBounds,
19512
+ parseCoverageReport,
18845
19513
  parseFpsCounts,
18846
19514
  parseHilogLine,
18847
19515
  parseHilogText,
@@ -18854,6 +19522,7 @@ export {
18854
19522
  parseSmapsRollup,
18855
19523
  planNextAction,
18856
19524
  queryDefinitions,
19525
+ readElf,
18857
19526
  readHidumperCapture,
18858
19527
  readHilogText,
18859
19528
  readJsheapSnapshot,