@ohos-perf/core 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 (3) hide show
  1. package/dist/index.d.ts +254 -97
  2. package/dist/index.js +367 -235
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -5099,6 +5099,259 @@ interface ReplayResult {
5099
5099
  */
5100
5100
  declare function replayAgent(device: AgentDevice, transcript: AgentTranscript): Promise<ReplayResult>;
5101
5101
 
5102
+ /**
5103
+ * A reader for the ELF headers, sections and symbols of an OHOS native binary.
5104
+ *
5105
+ * This exists for HapRay parity row 27. HapRay's `opt-detector` answers "what
5106
+ * optimization level was this built at, and was LTO on?" by feeding raw
5107
+ * `.text` bytes to a ~2 GB LSTM and a 551-feature SVM and printing the guess
5108
+ * as a percentage. An ELF records much of that directly — LTO leaves
5109
+ * `lto_priv.*` symbols and `.gnu.lto_*` sections, `-O0` leaves debug
5110
+ * sections, and the instruction mix is a fact about the bytes — so the
5111
+ * analyzer built on this reader reports what the file says and labels the
5112
+ * parts that are inference.
5113
+ *
5114
+ * What is here is deliberately narrow: the section header table, the two
5115
+ * symbol tables, and a decoder for the AArch64 instruction classes whose
5116
+ * density differs across optimization levels. There is no program-header
5117
+ * walk, no relocation processing, no dynamic-section parsing and no
5118
+ * disassembly — nothing this reader does not have a caller for.
5119
+ *
5120
+ * ## Refusals
5121
+ *
5122
+ * Every read is bounds-checked against the buffer, because a `.so` shipped
5123
+ * inside an app is attacker-controlled input as far as this package is
5124
+ * concerned. A bad magic, a short header, an unsupported class and a section
5125
+ * table pointing past the end are typed refusals naming the field, not bare
5126
+ * `RangeError`s from a `DataView`.
5127
+ */
5128
+ /** `e_machine` for AArch64, the only machine an OHOS app ships. */
5129
+ declare const EM_AARCH64 = 183;
5130
+ /** One section header, as much of it as a caller here needs. */
5131
+ interface ElfSection {
5132
+ readonly name: string;
5133
+ readonly type: number;
5134
+ readonly flags: number;
5135
+ /** Offset of the payload in the file. */
5136
+ readonly offset: number;
5137
+ /** Declared size. A `NOBITS` section declares one but occupies no bytes. */
5138
+ readonly size: number;
5139
+ /** Entry size for a table section (`sh_entsize`), else 0. */
5140
+ readonly entrySize: number;
5141
+ }
5142
+ /** One symbol, with the binding and type decoded from `st_info`. */
5143
+ interface ElfSymbol {
5144
+ readonly name: string;
5145
+ readonly bind: 'local' | 'global' | 'weak' | 'other';
5146
+ readonly type: 'notype' | 'func' | 'object' | 'section' | 'file' | 'other';
5147
+ readonly size: number;
5148
+ /**
5149
+ * `st_value`: the symbol's address. In a shared object this is the file
5150
+ * offset of the code, which is what a `libfoo.so+0xoffset` reference names.
5151
+ */
5152
+ readonly value: number;
5153
+ /** Section index the symbol belongs to; 0 for undefined, 0xfff1 for absolute. */
5154
+ readonly sectionIndex: number;
5155
+ }
5156
+ interface ElfFile {
5157
+ readonly bits: 32 | 64;
5158
+ readonly endian: 'little' | 'big';
5159
+ readonly machine: number;
5160
+ /** `e_type`: 1 relocatable, 2 executable, 3 shared object, 4 core. */
5161
+ readonly type: number;
5162
+ readonly sections: readonly ElfSection[];
5163
+ readonly symbols: readonly ElfSymbol[];
5164
+ /** The section with this name, or `undefined`. */
5165
+ readonly section: (name: string) => ElfSection | undefined;
5166
+ /** The payload of a section; empty for `NOBITS` and for a missing section. */
5167
+ readonly bytesOf: (name: string) => Uint8Array;
5168
+ }
5169
+ /**
5170
+ * Read an ELF's headers, sections and symbols.
5171
+ *
5172
+ * Only 64-bit little-endian is decoded. The class and endianness are read
5173
+ * first and refused by name, so a 32-bit or big-endian file gets a message
5174
+ * saying which shape was unsupported rather than a nonsensical section table.
5175
+ */
5176
+ declare function readElf(bytes: Uint8Array): ElfFile;
5177
+ /** The instruction classes whose density differs across optimization levels. */
5178
+ type InstructionClass = 'ret' | 'blr' | 'br' | 'bl' | 'b' | 'bcond' | 'cbz' | 'tbz' | 'adrp' | 'adr' | 'ldr' | 'str' | 'add' | 'vector' | 'other';
5179
+ /** Per-class instruction counts over a `.text` payload. */
5180
+ type InstructionCounts = Record<InstructionClass, number> & {
5181
+ total: number;
5182
+ };
5183
+ /**
5184
+ * Classify one AArch64 instruction word.
5185
+ *
5186
+ * The masks are the ARM ARM's fixed-field encodings for the classes whose
5187
+ * frequency a compiler changes: `ret`/`blr`/`br` (branch-register), `bl`/`b`
5188
+ * (immediate branch), `b.cond`, `cbz`/`cbnz`, `tbz`/`tbnz`, `adrp`/`adr`, and
5189
+ * the SIMD group. `other` covers everything else, which is most arithmetic.
5190
+ *
5191
+ * The order matters: `br`/`blr`/`ret` share a mask and are separated by their
5192
+ * `opc` field, and `b`/`bl` share a mask separated by bit 31.
5193
+ */
5194
+ declare function classifyInstruction(word: number): InstructionClass;
5195
+ /**
5196
+ * Count instruction classes over a payload.
5197
+ *
5198
+ * A trailing partial word is not an instruction and is not counted; a section
5199
+ * whose size is not a multiple of four is legal padding.
5200
+ */
5201
+ declare function countInstructions(payload: Uint8Array): InstructionCounts;
5202
+
5203
+ /**
5204
+ * Symbol recovery (HapRay parity row 28).
5205
+ *
5206
+ * HapRay's `symbol_recovery` tool answers "which function is
5207
+ * `libquick.so+0xc8a7c`?" by shelling out to radare2: `aflj` for the function
5208
+ * list, `afij` for boundaries, `pdfj` for disassembly, a decompiler plugin for
5209
+ * pseudo-C, then an LLM prompt built from the strings and call sites. Its own
5210
+ * documentation records the shape of the heuristic it is built on — a function
5211
+ * over 100 KB is "unreasonable, skip", and a function that cannot be found
5212
+ * gets a default size of 2000 bytes. Nothing in the tool measures whether the
5213
+ * name it prints is right.
5214
+ *
5215
+ * An ELF already answers the first half exactly. Every `STT_FUNC` symbol
5216
+ * carries an address (`st_value`) and a size (`st_size`), so "which function
5217
+ * contains this offset" is a lookup over sorted symbols — not a disassembly,
5218
+ * not a boundary heuristic, and not a guess when the lookup misses.
5219
+ *
5220
+ * The second half — naming a function whose symbol was stripped — is what the
5221
+ * model is for. What HapRay has no answer for is whether the model is any
5222
+ * good: it never compares a recovered name to a known one. This module adds
5223
+ * that. {@link measureNaming} holds out names the file *does* record, asks the
5224
+ * model to infer them from the same evidence it would have on a stripped file,
5225
+ * and reports the accuracy — so a run says "this model named 12 of 20 held-out
5226
+ * functions correctly" rather than "these are the names".
5227
+ */
5228
+
5229
+ /** One function body, as the symbols describe it. */
5230
+ interface FunctionRange {
5231
+ readonly name: string;
5232
+ /** Address of the first byte, from `st_value`. */
5233
+ readonly start: number;
5234
+ /** Address one past the last byte (`start + st_size`). */
5235
+ readonly end: number;
5236
+ readonly size: number;
5237
+ readonly bind: ElfSymbol['bind'];
5238
+ }
5239
+ /** A `libfoo.so+0xoffset` reference, split into its two halves. */
5240
+ interface AddressRef {
5241
+ readonly library: string;
5242
+ readonly offset: number;
5243
+ }
5244
+ /** A recovered name, and what it was recovered from. */
5245
+ interface RecoveredSymbol {
5246
+ readonly address: string;
5247
+ readonly offset: number;
5248
+ readonly name: string;
5249
+ readonly start: number;
5250
+ readonly end: number;
5251
+ /**
5252
+ * `recorded` when the ELF's own symbol table named it. There is no
5253
+ * `inferred` yet: inference is the model's job and its result is a
5254
+ * {@link NamingCase}, not a recovered symbol.
5255
+ */
5256
+ readonly basis: 'recorded';
5257
+ }
5258
+ /** An address this module could not locate, with the reason. */
5259
+ interface UnresolvedAddress {
5260
+ readonly address: string;
5261
+ readonly reason: string;
5262
+ }
5263
+ interface RecoveryResult {
5264
+ readonly recovered: readonly RecoveredSymbol[];
5265
+ readonly unresolved: readonly UnresolvedAddress[];
5266
+ }
5267
+ /**
5268
+ * Split a `libfoo.so+0x1cce24` reference.
5269
+ *
5270
+ * `undefined` for anything else: a resolved symbol is a name, and treating it
5271
+ * as an address would put a name in the library column and invent an offset.
5272
+ */
5273
+ declare function addressOfOffset(symbol: string): AddressRef | undefined;
5274
+ /**
5275
+ * The function ranges an ELF records, sorted by start address.
5276
+ *
5277
+ * A zero-size symbol is dropped: it marks a boundary (an alias, or a label the
5278
+ * compiler emitted) and has no extent, so treating it as a function would
5279
+ * claim every address after it.
5280
+ */
5281
+ declare function symbolIndex(elf: ElfFile): FunctionRange[];
5282
+ /**
5283
+ * The function containing `offset`, or `undefined`.
5284
+ *
5285
+ * The size a symbol records is authoritative: a function can be followed by
5286
+ * padding or by another section, and extending it to the next symbol would
5287
+ * claim bytes that are not its body.
5288
+ */
5289
+ declare function functionAt(index: readonly FunctionRange[], offset: number): FunctionRange | undefined;
5290
+ /**
5291
+ * Name every unresolved address the ELF can locate.
5292
+ *
5293
+ * Addresses are processed in sorted order so the same input in a different
5294
+ * order produces the same document — the determinism rule the rest of this
5295
+ * package follows.
5296
+ */
5297
+ declare function recoverSymbols(bytes: Uint8Array, unresolved: readonly string[]): RecoveryResult;
5298
+ /** One held-out function, and what the model answered for it. */
5299
+ interface NamingCase {
5300
+ readonly truth: string;
5301
+ readonly answer: string;
5302
+ readonly correct: boolean;
5303
+ readonly start: number;
5304
+ readonly size: number;
5305
+ }
5306
+ interface NamingReport {
5307
+ /** Functions the model was asked to name. */
5308
+ readonly heldOut: number;
5309
+ readonly correct: number;
5310
+ /** `correct / heldOut`, or `undefined` when nothing was held out. */
5311
+ readonly accuracy: number | undefined;
5312
+ readonly cases: readonly NamingCase[];
5313
+ }
5314
+ /** What the model is given about one function it must name. */
5315
+ interface NamingQuestion {
5316
+ /** The name being held out — the model must not see this. */
5317
+ readonly truth: string;
5318
+ readonly start: number;
5319
+ readonly size: number;
5320
+ readonly bind: ElfSymbol['bind'];
5321
+ /**
5322
+ * The function's own bytes, so the model has evidence rather than a prompt
5323
+ * asking it to guess. HapRay gets this from radare2's disassembly; here it
5324
+ * is the `.text` slice the symbol points at.
5325
+ */
5326
+ readonly body: Uint8Array;
5327
+ /** The instruction classes in the body, which is what a reader sees first. */
5328
+ readonly counts: InstructionCounts;
5329
+ }
5330
+ /** The model, as this module needs it: one function in, one name out. */
5331
+ type NamingAnswer = (question: NamingQuestion) => Promise<string>;
5332
+ /**
5333
+ * Reduce a name to what it means, so formatting does not score as a mistake.
5334
+ *
5335
+ * `sym.parseExpression`, `parseExpression(int)` and `_Z12parseExpressionv`
5336
+ * are the same function. Counting them wrong would measure a model's
5337
+ * punctuation habits rather than its understanding.
5338
+ */
5339
+ declare function normaliseName(name: string): string;
5340
+ /**
5341
+ * Measure how well a model names functions whose names are known.
5342
+ *
5343
+ * Every nameable function is held out in turn: the model is asked for a name
5344
+ * from the same evidence it would have on a stripped file, and its answer is
5345
+ * compared to the truth. The result is an accuracy over a stated number of
5346
+ * cases — the number HapRay's tool never reports, which is what makes its
5347
+ * output impossible to trust or to compare between models.
5348
+ *
5349
+ * A file with nothing to hold out reports `accuracy: undefined` rather than
5350
+ * zero: 0% over zero cases reads as a broken model when the truth is that
5351
+ * there was nothing to measure.
5352
+ */
5353
+ declare function measureNaming(bytes: Uint8Array, answer: NamingAnswer): Promise<NamingReport>;
5354
+
5102
5355
  /**
5103
5356
  * The HTTP model client for the GUI agent (HapRay parity row 5).
5104
5357
  *
@@ -6449,102 +6702,6 @@ declare function isZip(bytes: Uint8Array): boolean;
6449
6702
  /** Read the central directory and return an archive over `bytes`. */
6450
6703
  declare function openZip(bytes: Uint8Array): ZipArchive;
6451
6704
 
6452
- /**
6453
- * A reader for the ELF headers, sections and symbols of an OHOS native binary.
6454
- *
6455
- * This exists for HapRay parity row 27. HapRay's `opt-detector` answers "what
6456
- * optimization level was this built at, and was LTO on?" by feeding raw
6457
- * `.text` bytes to a ~2 GB LSTM and a 551-feature SVM and printing the guess
6458
- * as a percentage. An ELF records much of that directly — LTO leaves
6459
- * `lto_priv.*` symbols and `.gnu.lto_*` sections, `-O0` leaves debug
6460
- * sections, and the instruction mix is a fact about the bytes — so the
6461
- * analyzer built on this reader reports what the file says and labels the
6462
- * parts that are inference.
6463
- *
6464
- * What is here is deliberately narrow: the section header table, the two
6465
- * symbol tables, and a decoder for the AArch64 instruction classes whose
6466
- * density differs across optimization levels. There is no program-header
6467
- * walk, no relocation processing, no dynamic-section parsing and no
6468
- * disassembly — nothing this reader does not have a caller for.
6469
- *
6470
- * ## Refusals
6471
- *
6472
- * Every read is bounds-checked against the buffer, because a `.so` shipped
6473
- * inside an app is attacker-controlled input as far as this package is
6474
- * concerned. A bad magic, a short header, an unsupported class and a section
6475
- * table pointing past the end are typed refusals naming the field, not bare
6476
- * `RangeError`s from a `DataView`.
6477
- */
6478
- /** `e_machine` for AArch64, the only machine an OHOS app ships. */
6479
- declare const EM_AARCH64 = 183;
6480
- /** One section header, as much of it as a caller here needs. */
6481
- interface ElfSection {
6482
- readonly name: string;
6483
- readonly type: number;
6484
- readonly flags: number;
6485
- /** Offset of the payload in the file. */
6486
- readonly offset: number;
6487
- /** Declared size. A `NOBITS` section declares one but occupies no bytes. */
6488
- readonly size: number;
6489
- /** Entry size for a table section (`sh_entsize`), else 0. */
6490
- readonly entrySize: number;
6491
- }
6492
- /** One symbol, with the binding and type decoded from `st_info`. */
6493
- interface ElfSymbol {
6494
- readonly name: string;
6495
- readonly bind: 'local' | 'global' | 'weak' | 'other';
6496
- readonly type: 'notype' | 'func' | 'object' | 'section' | 'file' | 'other';
6497
- readonly size: number;
6498
- /** Section index the symbol belongs to; 0 for undefined, 0xfff1 for absolute. */
6499
- readonly sectionIndex: number;
6500
- }
6501
- interface ElfFile {
6502
- readonly bits: 32 | 64;
6503
- readonly endian: 'little' | 'big';
6504
- readonly machine: number;
6505
- /** `e_type`: 1 relocatable, 2 executable, 3 shared object, 4 core. */
6506
- readonly type: number;
6507
- readonly sections: readonly ElfSection[];
6508
- readonly symbols: readonly ElfSymbol[];
6509
- /** The section with this name, or `undefined`. */
6510
- readonly section: (name: string) => ElfSection | undefined;
6511
- /** The payload of a section; empty for `NOBITS` and for a missing section. */
6512
- readonly bytesOf: (name: string) => Uint8Array;
6513
- }
6514
- /**
6515
- * Read an ELF's headers, sections and symbols.
6516
- *
6517
- * Only 64-bit little-endian is decoded. The class and endianness are read
6518
- * first and refused by name, so a 32-bit or big-endian file gets a message
6519
- * saying which shape was unsupported rather than a nonsensical section table.
6520
- */
6521
- declare function readElf(bytes: Uint8Array): ElfFile;
6522
- /** The instruction classes whose density differs across optimization levels. */
6523
- type InstructionClass = 'ret' | 'blr' | 'br' | 'bl' | 'b' | 'bcond' | 'cbz' | 'tbz' | 'adrp' | 'adr' | 'ldr' | 'str' | 'add' | 'vector' | 'other';
6524
- /** Per-class instruction counts over a `.text` payload. */
6525
- type InstructionCounts = Record<InstructionClass, number> & {
6526
- total: number;
6527
- };
6528
- /**
6529
- * Classify one AArch64 instruction word.
6530
- *
6531
- * The masks are the ARM ARM's fixed-field encodings for the classes whose
6532
- * frequency a compiler changes: `ret`/`blr`/`br` (branch-register), `bl`/`b`
6533
- * (immediate branch), `b.cond`, `cbz`/`cbnz`, `tbz`/`tbnz`, `adrp`/`adr`, and
6534
- * the SIMD group. `other` covers everything else, which is most arithmetic.
6535
- *
6536
- * The order matters: `br`/`blr`/`ret` share a mask and are separated by their
6537
- * `opc` field, and `b`/`bl` share a mask separated by bit 31.
6538
- */
6539
- declare function classifyInstruction(word: number): InstructionClass;
6540
- /**
6541
- * Count instruction classes over a payload.
6542
- *
6543
- * A trailing partial word is not an instruction and is not counted; a section
6544
- * whose size is not a multiple of four is legal padding.
6545
- */
6546
- declare function countInstructions(payload: Uint8Array): InstructionCounts;
6547
-
6548
6705
  /**
6549
6706
  * Optimization-level and LTO detection for an OHOS native binary (HapRay
6550
6707
  * parity row 27).
@@ -6919,4 +7076,4 @@ interface FlamegraphPageInput {
6919
7076
  */
6920
7077
  declare function renderFlamegraphHtml(input: FlamegraphPageInput): string;
6921
7078
 
6922
- export { ANIMATION_BANDS, type ActionContext, type ActionDevice, type ActionOutcome, type ActiveAlloc, type AgentConfig, type AgentDecision, type AgentDevice, type AgentFetch, type AgentHistoryEntry, type AgentModel, type AgentOptions, type AgentResult, type AgentStatus, type AgentStep, type AgentStepStatus, type AgentTranscript, type AgentTurn, type AnalyzeContext, type AnalyzeResult, type Analyzer, type AnalyzerRun, type AnalyzerSection, type AnimationAnalysis, type AnimationLabel, type AnimationSeverity, type AppIdentity, BUNDLE_RENDERED_FILES, type BaselineComparison, type BelowThresholdPattern, type BinaryFacts, type BinaryInput, type BinaryReport, type BinderAnalysis, BinderAnalyzer, type BinderEndpoint, type BinderEvent, type BinderInterfaceStat, type BinderProcessStat, BinderQuery, type BinderThreadStat, type BinderTransaction, type BundleRerenderInput, CATEGORY_EXTENSIONS, CATEGORY_MAX_BYTES, COLLECTOR_NAMES, type CallchainSample, type CallstackEvent, type CallstackEventWithArgs, CallstackQuery, type CapabilityId, type CapabilityInputs, CapabilityMatrix, type CapabilityState, type CaseLoad, type CategoryTotal, type CollectOptions, type CollectSession, type Collector, type CollectorName, type CompiledRule, type ComponentReuse, ComponentReuseAnalyzer, type ConnectOptions, type ContentPattern, CoverageAnalyzer, type CoverageCounts, type CoverageFile, type CoverageRatio, type CoverageReport, type CreateEmulatorRequest, DEFAULT_HILOG_RULES, DEFAULT_QUERY_LIMIT, DEVICE_PERF_PATH, DEVICE_SCREENSHOT_PATH, DEVICE_UI_PATH, type DeltaStatus, type DepGraph, type DepGraphEdge, type DepGraphFile, Device, type DeviceDeps, type DeviceIdentity, DeviceNotFoundError, type DiscoveredCase, type DrillDownHandle, type DuplicateGroup, EM_AARCH64, EXCLUDE_PATTERNS, type ElfFile, type ElfSection, type ElfSymbol, EmptyFrameAnalyzer, type EmptyFrameFilter, type EmulatorBackend, EmulatorClient, type EmulatorClientOptions, EmulatorCommandError, type EmulatorImage, EmulatorImageMissingError, type EmulatorInstance, EmulatorLifecycle, type EmulatorLifecycleOptions, EmulatorNotFoundError, type EmulatorStartResult, type EmulatorStopResult, type Env, type Evidence, type EvidenceKind, type ExpectPresent, type ExpectationOutcome, type ExplorationAction, type ExplorationClock, type ExplorationDevice, type ExplorationDeviceOptions, type ExplorationHost, type ExplorationOptions, type ExplorationOutcome, type ExplorationResult, type ExplorationState, type ExplorationStep, type ExplorationStrategy, type ExplorationTargetDevice, FLAMEGRAPH_FILES, FPS_COMMAND, FTRACE_CATEGORIES, FaultTreeAnalyzer, type FaultTreeSignals, type Fidelity, type FileCategory, type FileRule, FlamegraphAnalyzer, type FlamegraphPageInput, type FoldedStack, type FpsBucket, type FpsWindow, type Frame, FrameAnalyzer, type FrameFlag, FrameLoadAnalyzer, FrameLoadIndex, type FrameLoadIndexInput, type FrameLoadThread, FrameQuery, type FrameStats, type FrameType, type FtraceOptions, GEOMETRY_TOLERANCE_PX, GcAnalyzer, type GcSignals, type Gesture, GestureDriver, type GestureResult, HILOG_COMMAND, HIPROFILER_PLUGIN_NAMES, HITCH_COMMAND, HITRACE_DEFAULT_CATEGORIES, type HapAnalysis, type HapPackage, type HarEdge, Hdc, HdcNotFoundError, type HdcOptions, type HdcResult, type HdcSlice, type HdcTarget, type HidumperCapture, HidumperCollector, type HidumperSnapshot, HilogAnalyzer, HilogCollector, type HilogLevel, type HilogLine, type HilogMatch, type HilogParseOptions, type HilogRule, type HiperfCapture, type HiperfCollectOptions, HiperfCollector, type HiprofilerCollectOptions, type HiprofilerCollectRequest, HiprofilerCollector, type HiprofilerConfigOptions, type HiprofilerPlugin, type HiprofilerPluginName, HitraceCollector, type HttpAgentModelOptions, IGNORED_ATTRIBUTES, IRREVERSIBLE_PATTERNS, type ImageComparison, IngestError, InstantQuery, type InstructionClass, type InstructionCounts, type InventoryFile, type IrreversiblePattern, type JsheapCapture, JsheapCollector, MAX_QUERY_LIMIT, METRIC_DIRECTIONS, MIN_BUFFER_PAGES, MIN_HASH_PIXELS, MemMeasureQuery, MemoryAnalyzer, MemoryMeasureAnalyzer, type MemoryPluginOptions, type MetadataPattern, type Metric, type MetricDelta, type MetricDirection, type MetricUnit, type ModuleDecl, type NamedQueryDefinition, type NamedQueryInfo, type NamedQueryResult, type NativeCategory, type NativeEventKind, type NativeHookEvent, type NativeHookFrame, NativeHookQuery, type NativeHookStatistic, NativeMemoryAnalyzer, type NativeMemoryResult, type NativeNames, type NativeTimelineBucket, type NativehookOptions, OhosPerfError, type OptimizationAnalysis, type OptimizationBasis, type OptimizationLevel, type OptimizationPotential, type OptimizationVerdict, type OversizedFile, PARITY_ROWS, PLANE_A_PLUGINS, type ParityRow, type ParityStatus, type PerfCallchain, type PerfFileAttribution, type PerfFunction, type PerfLeafAttribution, PerfQuery, type PerfSampleRow, type PerfThread, type PixelOnlyChange, type ProbeResult, type ProbeRunner, type ProbeSnapshot, type ProcessInfo, type ProcessMeasure, type ProcessMeasureFilter, ProcessQuery, ProcfsCollector, type ProcfsSample, type ProcfsStatus, type Provenance, type QueryArgument, type QueryContext, type QueryHandle, REPORT_SCHEMA_VERSION, type Rect, type RedundancyLevel, type RedundancyType, RedundantFileAnalyzer, type RedundantFileEntry, type RedundantFileReport, type RedundantThreadPattern, type RedundantThreadsSummary, type RegionPixelChange, RenderAnalyzer, type ReplayResult, type ReportGenerator, type ReportInput, type ReportModel, type ReportScenario, type ReportSection, type ReportSummary, type ReportTotals, type RgbaImage, RsSkipAnalyzer, type RsSkipFrame, type RsSkipResult, type RsSkipTraceMethod, type RuleMatch, type RuleMatchKind, type RunOptions, type RunResult, type RunStepResult, type RunnerCollectOptions, type RunnerDevice, SECTION_TITLES, type Scenario, type ScenarioAction, ScenarioRunner, type ScenarioStep, Scene, type SceneLayout, type SceneMetadata, type SceneStep, type SceneStepRef, type ScenesComparison, SchedQuery, type SchedSlice, type ScreenshotCapture, ScreenshotCollector, type Selector, type SelectorRect, type SmapsRollup, StartupAnalyzer, StartupQuery, type StartupRecord, type StepCapture, type StepComparison, type StepExpectation, type StepStatus, Streamer, StreamerNotFoundError, type StreamerOptions, type SymbolStat, SymbolsAnalyzer, TECH_RULES, type TechRule, type ThreadAnalysis, type ThreadAnalysisSummary, ThreadAnalyzer, type ThreadInfo, ThreadQuery, type ThreadState, ThreadStateQuery, type ThreadWakeupResult, type ThreadWakeupThread, type TimeRange, type TimingCycle, type TraceCollectOptions, type Trend, type TrendOrder, type TrendPoint, type TrendRun, type TrendSeries, UI_DIFF_FILES, UiAnalyzer, type UiCompareOptions, type UiDiff, type UiDiffSide, type UiNode, type UiTreeDiff, type UiTreeDifference, UitestCollector, type UnmeasuredRegion, type UnreleasedRow, type VsyncAnalysis, VsyncAnalyzer, type VsyncPeriod, type VsyncPeriodKind, type VsyncSeverity, type WakeupEvent, type WindowHitches, type ZipArchive, type ZipEntry, agentPrompt, aggregateUnreleased, analyseAnimations, analyzeBinaries, analyzeHap, analyzeThreadWakeup, animationSeverity, buildDepGraph, buildHiprofilerConfig, buildInventory, buildMatrix, buildNativeTimeline, buildReport, buildTrend, categorize, classifyInstruction, classifyNativePath, classifyOptimization, compareImages, compareRegion, compareResults, compareSceneDirs, compareScenes, compileRules, computeBinderAnalysis, computeComponentReuse, computeFaultTree, computeFpsWindows, computeGc, computeRsSkip, computeThreadAnalysis, computeVsyncAnomalies, connect, countInstructions, createSceneLayout, cropRegion, decodePng, defaultAnalyzers, describeDecision, deviceExplorationHost, dhash, diffTrees, discoverCases, encodePng, escapeHtml, evaluateExpectation, evidence, executeAction, explorationDevice, explore, extractBinaries, filterEmptyFrames, flattenUiTree, ftracePlugin, gpuPlugin, hapSection, hashTree, hiperfRecordCommand, httpAgentModel, ingestScene, inspectBinary, irreversibleReason, isUnresolvedSymbol, isZip, loadCases, lookupQuery, markRegions, matchHapRules, matchRules, matchSelector, memoryPlugin, metric, nativeEventKind, nativehookPlugin, nodeIdentity, openDb, openZip, optimizationSection, pairNativeMemory, paritySummary, parseBounds, parseCoverageReport, parseDecision, parseFpsCounts, parseHilogLine, parseHilogText, parseHiperfSummary, parseHitches, parseProcfsStatus, parseRedundantFile, parseScenario, parseSelector, parseSmapsRollup, planNextAction, queryDefinitions, readAgentConfig, readElf, readHidumperCapture, readHilogText, readJsheapSnapshot, readProcfsSamples, readSceneMetadata, readUiTree, renderBundle, renderEvidenceCsv, renderFlamegraphHtml, renderFlamegraphSvg, renderMetricsCsv, renderReportHtml, renderReportJson, renderReportXlsx, renderScenesComparison, renderSummaryJson, renderTree, renderTrendHtml, renderTrendJson, renderUiDiffHtml, replayAgent, resolveAppIdentity, resolveAppIpids, resolveQueryLimit, resolveSelector, round2HalfEven, runAgent, runAnalyzerSections, runAnalyzers, runDrillDown, runNamedQuery, runProbe, sortSteps, summarizeReport, tableRowCounts, trendRunFromReport, unknownQueryError, validateRules, writeProcfsSamples, writeRunFiles, writeSceneMetadata, xpowerPlugin };
7079
+ export { ANIMATION_BANDS, type ActionContext, type ActionDevice, type ActionOutcome, type ActiveAlloc, type AddressRef, type AgentConfig, type AgentDecision, type AgentDevice, type AgentFetch, type AgentHistoryEntry, type AgentModel, type AgentOptions, type AgentResult, type AgentStatus, type AgentStep, type AgentStepStatus, type AgentTranscript, type AgentTurn, type AnalyzeContext, type AnalyzeResult, type Analyzer, type AnalyzerRun, type AnalyzerSection, type AnimationAnalysis, type AnimationLabel, type AnimationSeverity, type AppIdentity, BUNDLE_RENDERED_FILES, type BaselineComparison, type BelowThresholdPattern, type BinaryFacts, type BinaryInput, type BinaryReport, type BinderAnalysis, BinderAnalyzer, type BinderEndpoint, type BinderEvent, type BinderInterfaceStat, type BinderProcessStat, BinderQuery, type BinderThreadStat, type BinderTransaction, type BundleRerenderInput, CATEGORY_EXTENSIONS, CATEGORY_MAX_BYTES, COLLECTOR_NAMES, type CallchainSample, type CallstackEvent, type CallstackEventWithArgs, CallstackQuery, type CapabilityId, type CapabilityInputs, CapabilityMatrix, type CapabilityState, type CaseLoad, type CategoryTotal, type CollectOptions, type CollectSession, type Collector, type CollectorName, type CompiledRule, type ComponentReuse, ComponentReuseAnalyzer, type ConnectOptions, type ContentPattern, CoverageAnalyzer, type CoverageCounts, type CoverageFile, type CoverageRatio, type CoverageReport, type CreateEmulatorRequest, DEFAULT_HILOG_RULES, DEFAULT_QUERY_LIMIT, DEVICE_PERF_PATH, DEVICE_SCREENSHOT_PATH, DEVICE_UI_PATH, type DeltaStatus, type DepGraph, type DepGraphEdge, type DepGraphFile, Device, type DeviceDeps, type DeviceIdentity, DeviceNotFoundError, type DiscoveredCase, type DrillDownHandle, type DuplicateGroup, EM_AARCH64, EXCLUDE_PATTERNS, type ElfFile, type ElfSection, type ElfSymbol, EmptyFrameAnalyzer, type EmptyFrameFilter, type EmulatorBackend, EmulatorClient, type EmulatorClientOptions, EmulatorCommandError, type EmulatorImage, EmulatorImageMissingError, type EmulatorInstance, EmulatorLifecycle, type EmulatorLifecycleOptions, EmulatorNotFoundError, type EmulatorStartResult, type EmulatorStopResult, type Env, type Evidence, type EvidenceKind, type ExpectPresent, type ExpectationOutcome, type ExplorationAction, type ExplorationClock, type ExplorationDevice, type ExplorationDeviceOptions, type ExplorationHost, type ExplorationOptions, type ExplorationOutcome, type ExplorationResult, type ExplorationState, type ExplorationStep, type ExplorationStrategy, type ExplorationTargetDevice, FLAMEGRAPH_FILES, FPS_COMMAND, FTRACE_CATEGORIES, FaultTreeAnalyzer, type FaultTreeSignals, type Fidelity, type FileCategory, type FileRule, FlamegraphAnalyzer, type FlamegraphPageInput, type FoldedStack, type FpsBucket, type FpsWindow, type Frame, FrameAnalyzer, type FrameFlag, FrameLoadAnalyzer, FrameLoadIndex, type FrameLoadIndexInput, type FrameLoadThread, FrameQuery, type FrameStats, type FrameType, type FtraceOptions, type FunctionRange, GEOMETRY_TOLERANCE_PX, GcAnalyzer, type GcSignals, type Gesture, GestureDriver, type GestureResult, HILOG_COMMAND, HIPROFILER_PLUGIN_NAMES, HITCH_COMMAND, HITRACE_DEFAULT_CATEGORIES, type HapAnalysis, type HapPackage, type HarEdge, Hdc, HdcNotFoundError, type HdcOptions, type HdcResult, type HdcSlice, type HdcTarget, type HidumperCapture, HidumperCollector, type HidumperSnapshot, HilogAnalyzer, HilogCollector, type HilogLevel, type HilogLine, type HilogMatch, type HilogParseOptions, type HilogRule, type HiperfCapture, type HiperfCollectOptions, HiperfCollector, type HiprofilerCollectOptions, type HiprofilerCollectRequest, HiprofilerCollector, type HiprofilerConfigOptions, type HiprofilerPlugin, type HiprofilerPluginName, HitraceCollector, type HttpAgentModelOptions, IGNORED_ATTRIBUTES, IRREVERSIBLE_PATTERNS, type ImageComparison, IngestError, InstantQuery, type InstructionClass, type InstructionCounts, type InventoryFile, type IrreversiblePattern, type JsheapCapture, JsheapCollector, MAX_QUERY_LIMIT, METRIC_DIRECTIONS, MIN_BUFFER_PAGES, MIN_HASH_PIXELS, MemMeasureQuery, MemoryAnalyzer, MemoryMeasureAnalyzer, type MemoryPluginOptions, type MetadataPattern, type Metric, type MetricDelta, type MetricDirection, type MetricUnit, type ModuleDecl, type NamedQueryDefinition, type NamedQueryInfo, type NamedQueryResult, type NamingAnswer, type NamingCase, type NamingQuestion, type NamingReport, type NativeCategory, type NativeEventKind, type NativeHookEvent, type NativeHookFrame, NativeHookQuery, type NativeHookStatistic, NativeMemoryAnalyzer, type NativeMemoryResult, type NativeNames, type NativeTimelineBucket, type NativehookOptions, OhosPerfError, type OptimizationAnalysis, type OptimizationBasis, type OptimizationLevel, type OptimizationPotential, type OptimizationVerdict, type OversizedFile, PARITY_ROWS, PLANE_A_PLUGINS, type ParityRow, type ParityStatus, type PerfCallchain, type PerfFileAttribution, type PerfFunction, type PerfLeafAttribution, PerfQuery, type PerfSampleRow, type PerfThread, type PixelOnlyChange, type ProbeResult, type ProbeRunner, type ProbeSnapshot, type ProcessInfo, type ProcessMeasure, type ProcessMeasureFilter, ProcessQuery, ProcfsCollector, type ProcfsSample, type ProcfsStatus, type Provenance, type QueryArgument, type QueryContext, type QueryHandle, REPORT_SCHEMA_VERSION, type RecoveredSymbol, type RecoveryResult, type Rect, type RedundancyLevel, type RedundancyType, RedundantFileAnalyzer, type RedundantFileEntry, type RedundantFileReport, type RedundantThreadPattern, type RedundantThreadsSummary, type RegionPixelChange, RenderAnalyzer, type ReplayResult, type ReportGenerator, type ReportInput, type ReportModel, type ReportScenario, type ReportSection, type ReportSummary, type ReportTotals, type RgbaImage, RsSkipAnalyzer, type RsSkipFrame, type RsSkipResult, type RsSkipTraceMethod, type RuleMatch, type RuleMatchKind, type RunOptions, type RunResult, type RunStepResult, type RunnerCollectOptions, type RunnerDevice, SECTION_TITLES, type Scenario, type ScenarioAction, ScenarioRunner, type ScenarioStep, Scene, type SceneLayout, type SceneMetadata, type SceneStep, type SceneStepRef, type ScenesComparison, SchedQuery, type SchedSlice, type ScreenshotCapture, ScreenshotCollector, type Selector, type SelectorRect, type SmapsRollup, StartupAnalyzer, StartupQuery, type StartupRecord, type StepCapture, type StepComparison, type StepExpectation, type StepStatus, Streamer, StreamerNotFoundError, type StreamerOptions, type SymbolStat, SymbolsAnalyzer, TECH_RULES, type TechRule, type ThreadAnalysis, type ThreadAnalysisSummary, ThreadAnalyzer, type ThreadInfo, ThreadQuery, type ThreadState, ThreadStateQuery, type ThreadWakeupResult, type ThreadWakeupThread, type TimeRange, type TimingCycle, type TraceCollectOptions, type Trend, type TrendOrder, type TrendPoint, type TrendRun, type TrendSeries, UI_DIFF_FILES, UiAnalyzer, type UiCompareOptions, type UiDiff, type UiDiffSide, type UiNode, type UiTreeDiff, type UiTreeDifference, UitestCollector, type UnmeasuredRegion, type UnreleasedRow, type UnresolvedAddress, type VsyncAnalysis, VsyncAnalyzer, type VsyncPeriod, type VsyncPeriodKind, type VsyncSeverity, type WakeupEvent, type WindowHitches, type ZipArchive, type ZipEntry, addressOfOffset, agentPrompt, aggregateUnreleased, analyseAnimations, analyzeBinaries, analyzeHap, analyzeThreadWakeup, animationSeverity, buildDepGraph, buildHiprofilerConfig, buildInventory, buildMatrix, buildNativeTimeline, buildReport, buildTrend, categorize, classifyInstruction, classifyNativePath, classifyOptimization, compareImages, compareRegion, compareResults, compareSceneDirs, compareScenes, compileRules, computeBinderAnalysis, computeComponentReuse, computeFaultTree, computeFpsWindows, computeGc, computeRsSkip, computeThreadAnalysis, computeVsyncAnomalies, connect, countInstructions, createSceneLayout, cropRegion, decodePng, defaultAnalyzers, describeDecision, deviceExplorationHost, dhash, diffTrees, discoverCases, encodePng, escapeHtml, evaluateExpectation, evidence, executeAction, explorationDevice, explore, extractBinaries, filterEmptyFrames, flattenUiTree, ftracePlugin, functionAt, gpuPlugin, hapSection, hashTree, hiperfRecordCommand, httpAgentModel, ingestScene, inspectBinary, irreversibleReason, isUnresolvedSymbol, isZip, loadCases, lookupQuery, markRegions, matchHapRules, matchRules, matchSelector, measureNaming, memoryPlugin, metric, nativeEventKind, nativehookPlugin, nodeIdentity, normaliseName, openDb, openZip, optimizationSection, pairNativeMemory, paritySummary, parseBounds, parseCoverageReport, parseDecision, parseFpsCounts, parseHilogLine, parseHilogText, parseHiperfSummary, parseHitches, parseProcfsStatus, parseRedundantFile, parseScenario, parseSelector, parseSmapsRollup, planNextAction, queryDefinitions, readAgentConfig, readElf, readHidumperCapture, readHilogText, readJsheapSnapshot, readProcfsSamples, readSceneMetadata, readUiTree, recoverSymbols, renderBundle, renderEvidenceCsv, renderFlamegraphHtml, renderFlamegraphSvg, renderMetricsCsv, renderReportHtml, renderReportJson, renderReportXlsx, renderScenesComparison, renderSummaryJson, renderTree, renderTrendHtml, renderTrendJson, renderUiDiffHtml, replayAgent, resolveAppIdentity, resolveAppIpids, resolveQueryLimit, resolveSelector, round2HalfEven, runAgent, runAnalyzerSections, runAnalyzers, runDrillDown, runNamedQuery, runProbe, sortSteps, summarizeReport, symbolIndex, tableRowCounts, trendRunFromReport, unknownQueryError, validateRules, writeProcfsSamples, writeRunFiles, writeSceneMetadata, xpowerPlugin };
package/dist/index.js CHANGED
@@ -6322,8 +6322,8 @@ var PARITY_ROWS = [
6322
6322
  {
6323
6323
  row: 28,
6324
6324
  name: "Symbol recovery",
6325
- status: "out",
6326
- reason: "Heuristic disassembly (radare2/capstone) plus LLM naming, with no accuracy measurement; device `--so-dir` symbolization covers the resolved symbols."
6325
+ status: "ported",
6326
+ reason: ""
6327
6327
  },
6328
6328
  {
6329
6329
  row: 29,
@@ -8888,6 +8888,351 @@ async function replayAgent(device, transcript) {
8888
8888
  return { performed, skipped };
8889
8889
  }
8890
8890
 
8891
+ // src/hap/elf.ts
8892
+ var EM_AARCH64 = 183;
8893
+ var SHT_SYMTAB = 2;
8894
+ var SHT_NOBITS = 8;
8895
+ var SHT_DYNSYM = 11;
8896
+ function fail(message3, cause) {
8897
+ throw new OhosPerfError(message3, { code: "ELF_INVALID", ...cause === void 0 ? {} : { cause } });
8898
+ }
8899
+ function view(bytes) {
8900
+ return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
8901
+ }
8902
+ function field(dv, at, size, what) {
8903
+ if (at < 0 || at + size > dv.byteLength) {
8904
+ fail(`ELF is truncated: ${what} at offset ${at} runs past the ${dv.byteLength}-byte file`);
8905
+ }
8906
+ if (size === 1) return dv.getUint8(at);
8907
+ if (size === 2) return dv.getUint16(at, true);
8908
+ if (size === 4) return dv.getUint32(at, true);
8909
+ return dv.getUint32(at, true) + dv.getUint32(at + 4, true) * 2 ** 32;
8910
+ }
8911
+ function readString(table, offset) {
8912
+ if (offset < 0 || offset >= table.length) return "";
8913
+ const end = table.indexOf(0, offset);
8914
+ return new TextDecoder("utf-8").decode(
8915
+ table.subarray(offset, end === -1 ? table.length : end)
8916
+ );
8917
+ }
8918
+ function bindOf(info) {
8919
+ const bind = info >> 4;
8920
+ if (bind === 0) return "local";
8921
+ if (bind === 1) return "global";
8922
+ if (bind === 2) return "weak";
8923
+ return "other";
8924
+ }
8925
+ function typeOf(info) {
8926
+ const type = info & 15;
8927
+ if (type === 0) return "notype";
8928
+ if (type === 1) return "object";
8929
+ if (type === 2) return "func";
8930
+ if (type === 3) return "section";
8931
+ if (type === 4) return "file";
8932
+ return "other";
8933
+ }
8934
+ function symbolTableOf(dv, sections, links, bytes, index) {
8935
+ const section = sections[index];
8936
+ const link = links[index];
8937
+ const strings = link >= 0 && link < sections.length ? bytes.subarray(sections[link].offset, sections[link].offset + sections[link].size) : new Uint8Array(0);
8938
+ const entrySize = section.entrySize === 0 ? 24 : section.entrySize;
8939
+ const count = Math.floor(section.size / entrySize);
8940
+ const symbols = [];
8941
+ for (let at = 0; at < count; at += 1) {
8942
+ const base = section.offset + at * entrySize;
8943
+ if (at === 0) continue;
8944
+ const nameOffset = field(dv, base, 4, "st_name");
8945
+ const info = field(dv, base + 4, 1, "st_info");
8946
+ const sectionIndex = field(dv, base + 6, 2, "st_shndx");
8947
+ const value = field(dv, base + 8, 8, "st_value");
8948
+ const size = field(dv, base + 16, 8, "st_size");
8949
+ const name = readString(strings, nameOffset);
8950
+ symbols.push({ name, bind: bindOf(info), type: typeOf(info), size, value, sectionIndex });
8951
+ }
8952
+ return symbols;
8953
+ }
8954
+ function readElf(bytes) {
8955
+ if (bytes.length < 4) {
8956
+ fail(`ELF is truncated: ${bytes.length} bytes is shorter than the 4-byte magic`);
8957
+ }
8958
+ if (bytes[0] !== 127 || bytes[1] !== 69 || bytes[2] !== 76 || bytes[3] !== 70) {
8959
+ fail("not an ELF file: the first four bytes are not \\x7fELF");
8960
+ }
8961
+ if (bytes.length < 16) {
8962
+ fail(`ELF is truncated: ${bytes.length} bytes is shorter than the 16-byte ident`);
8963
+ }
8964
+ const bits = bytes[4] === 2 ? 64 : bytes[4] === 1 ? 32 : 0;
8965
+ if (bits === 0) {
8966
+ fail(`unsupported ELF class ${String(bytes[4])}: only 32-bit and 64-bit are defined`);
8967
+ }
8968
+ const endian = bytes[5] === 1 ? "little" : bytes[5] === 2 ? "big" : void 0;
8969
+ if (endian === void 0) {
8970
+ fail(`unsupported ELF data encoding ${String(bytes[5])}: only little and big endian are defined`);
8971
+ }
8972
+ if (bits !== 64 || endian !== "little") {
8973
+ fail(`unsupported ELF: ${String(bits)}-bit ${endian}-endian; OHOS ships 64-bit little-endian`);
8974
+ }
8975
+ const headerSize = 64;
8976
+ if (bytes.length < headerSize) {
8977
+ fail(`ELF is truncated: ${bytes.length} bytes is shorter than the ${headerSize}-byte header`);
8978
+ }
8979
+ const dv = view(bytes);
8980
+ const machine = field(dv, 18, 2, "e_machine");
8981
+ const type = field(dv, 16, 2, "e_type");
8982
+ const shoff = field(dv, 40, 8, "e_shoff");
8983
+ const shentsize = field(dv, 58, 2, "e_shentsize");
8984
+ const shnum = field(dv, 60, 2, "e_shnum");
8985
+ const shstrndx = field(dv, 62, 2, "e_shstrndx");
8986
+ if (shnum === 0) {
8987
+ return {
8988
+ bits: 64,
8989
+ endian,
8990
+ machine,
8991
+ type,
8992
+ sections: [],
8993
+ symbols: [],
8994
+ section: () => void 0,
8995
+ bytesOf: () => new Uint8Array(0)
8996
+ };
8997
+ }
8998
+ if (shentsize !== 64) {
8999
+ fail(`unsupported section header size ${shentsize}: a 64-bit ELF uses 64`);
9000
+ }
9001
+ if (shoff + shnum * shentsize > bytes.length) {
9002
+ fail(
9003
+ `ELF is truncated: the section header table at offset ${shoff} with ${shnum} entries runs past the ${bytes.length}-byte file`
9004
+ );
9005
+ }
9006
+ if (shstrndx >= shnum) {
9007
+ fail(`e_shstrndx ${shstrndx} names a section beyond the ${shnum} the file declares`);
9008
+ }
9009
+ const raw = [];
9010
+ const links = [];
9011
+ for (let index = 0; index < shnum; index += 1) {
9012
+ const at = shoff + index * shentsize;
9013
+ raw.push({
9014
+ nameOffset: field(dv, at, 4, `section[${index}].sh_name`),
9015
+ type: field(dv, at + 4, 4, `section[${index}].sh_type`),
9016
+ flags: field(dv, at + 8, 8, `section[${index}].sh_flags`),
9017
+ offset: field(dv, at + 24, 8, `section[${index}].sh_offset`),
9018
+ size: field(dv, at + 32, 8, `section[${index}].sh_size`),
9019
+ link: field(dv, at + 40, 4, `section[${index}].sh_link`),
9020
+ entrySize: field(dv, at + 56, 8, `section[${index}].sh_entsize`)
9021
+ });
9022
+ links.push(raw[index].link);
9023
+ }
9024
+ for (const [index, section] of raw.entries()) {
9025
+ if (section.type === SHT_NOBITS || section.type === 0) continue;
9026
+ if (section.offset + section.size > bytes.length) {
9027
+ fail(
9028
+ `ELF is truncated: section ${index} at offset ${section.offset} with size ${section.size} runs past the ${bytes.length}-byte file`
9029
+ );
9030
+ }
9031
+ }
9032
+ const nameTable = raw[shstrndx];
9033
+ const strings = bytes.subarray(nameTable.offset, nameTable.offset + nameTable.size);
9034
+ const sections = raw.map((section) => ({
9035
+ name: readString(strings, section.nameOffset),
9036
+ type: section.type,
9037
+ flags: section.flags,
9038
+ offset: section.offset,
9039
+ size: section.size,
9040
+ entrySize: section.entrySize
9041
+ }));
9042
+ const symbols = [];
9043
+ for (const [index, section] of sections.entries()) {
9044
+ if (section.type !== SHT_SYMTAB && section.type !== SHT_DYNSYM) continue;
9045
+ symbols.push(...symbolTableOf(dv, sections, links, bytes, index));
9046
+ }
9047
+ const byName = new Map(sections.map((section) => [section.name, section]));
9048
+ return {
9049
+ bits: 64,
9050
+ endian,
9051
+ machine,
9052
+ type,
9053
+ sections,
9054
+ symbols,
9055
+ section: (name) => byName.get(name),
9056
+ bytesOf: (name) => {
9057
+ const section = byName.get(name);
9058
+ if (section === void 0 || section.type === SHT_NOBITS) return new Uint8Array(0);
9059
+ return bytes.subarray(section.offset, section.offset + section.size);
9060
+ }
9061
+ };
9062
+ }
9063
+ function classifyInstruction(word) {
9064
+ const masked = (mask) => (word & mask) >>> 0;
9065
+ if (masked(4294966303) === 3596550144) return "ret";
9066
+ if (masked(4294966303) === 3594452992) return "blr";
9067
+ if (masked(4294966303) === 3592355840) return "br";
9068
+ if (masked(4227858432) === 2483027968) return "bl";
9069
+ if (masked(4227858432) === 335544320) return "b";
9070
+ if (masked(4278190096) === 1409286144) return "bcond";
9071
+ if (masked(2113929216) === 872415232) return "cbz";
9072
+ if (masked(2113929216) === 905969664) return "tbz";
9073
+ if (masked(2667577344) === 2415919104) return "adrp";
9074
+ if (masked(2667577344) === 268435456) return "adr";
9075
+ if (masked(989855744) === 956301312) {
9076
+ return masked(4194304) === 0 ? "str" : "ldr";
9077
+ }
9078
+ if (masked(520093696) === 285212672) return "add";
9079
+ if (masked(167772160) === 167772160) return "vector";
9080
+ return "other";
9081
+ }
9082
+ function countInstructions(payload) {
9083
+ const counts = {
9084
+ total: 0,
9085
+ ret: 0,
9086
+ blr: 0,
9087
+ br: 0,
9088
+ bl: 0,
9089
+ b: 0,
9090
+ bcond: 0,
9091
+ cbz: 0,
9092
+ tbz: 0,
9093
+ adrp: 0,
9094
+ adr: 0,
9095
+ ldr: 0,
9096
+ str: 0,
9097
+ add: 0,
9098
+ vector: 0,
9099
+ other: 0
9100
+ };
9101
+ const dv = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
9102
+ const words = Math.floor(payload.length / 4);
9103
+ for (let index = 0; index < words; index += 1) {
9104
+ const cls = classifyInstruction(dv.getUint32(index * 4, true));
9105
+ counts[cls] += 1;
9106
+ counts.total += 1;
9107
+ }
9108
+ return counts;
9109
+ }
9110
+
9111
+ // src/hap/symbols-recovery.ts
9112
+ var ADDRESS_FORM = /^(.+)\+0x([0-9a-fA-F]+)$/;
9113
+ function addressOfOffset(symbol) {
9114
+ const match = ADDRESS_FORM.exec(symbol);
9115
+ if (match === null) return void 0;
9116
+ const offset = Number.parseInt(match[2], 16);
9117
+ if (!Number.isSafeInteger(offset) || offset < 0) return void 0;
9118
+ return { library: match[1], offset };
9119
+ }
9120
+ function symbolIndex(elf) {
9121
+ return elf.symbols.filter((symbol) => symbol.type === "func" && symbol.size > 0 && symbol.name !== "").map((symbol) => ({
9122
+ name: symbol.name,
9123
+ start: symbol.value,
9124
+ end: symbol.value + symbol.size,
9125
+ size: symbol.size,
9126
+ bind: symbol.bind
9127
+ })).sort((a, b) => a.start - b.start || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
9128
+ }
9129
+ function functionAt(index, offset) {
9130
+ for (const range of index) {
9131
+ if (range.start > offset) return void 0;
9132
+ if (offset >= range.start && offset < range.end) return range;
9133
+ }
9134
+ return void 0;
9135
+ }
9136
+ function recoverSymbols(bytes, unresolved) {
9137
+ const elf = readElf(bytes);
9138
+ const index = symbolIndex(elf);
9139
+ const stripped = index.length === 0;
9140
+ const recovered = [];
9141
+ const missed = [];
9142
+ for (const address of [...unresolved].sort()) {
9143
+ const ref = addressOfOffset(address);
9144
+ if (ref === void 0) {
9145
+ missed.push({ address, reason: "not an address of the form lib.so+0xoffset" });
9146
+ continue;
9147
+ }
9148
+ if (stripped) {
9149
+ missed.push({
9150
+ address,
9151
+ reason: "the file has no symbol table (it is stripped), so no function boundary is recorded"
9152
+ });
9153
+ continue;
9154
+ }
9155
+ const found = functionAt(index, ref.offset);
9156
+ if (found === void 0) {
9157
+ missed.push({ address, reason: `no function recorded at ${address}` });
9158
+ continue;
9159
+ }
9160
+ recovered.push({
9161
+ address,
9162
+ offset: ref.offset,
9163
+ name: found.name,
9164
+ start: found.start,
9165
+ end: found.end,
9166
+ basis: "recorded"
9167
+ });
9168
+ }
9169
+ return { recovered, unresolved: missed };
9170
+ }
9171
+ var PLACEHOLDER = /^(?:fcn|sym|sub|loc|unk|fun)[._][0-9a-f]+$/i;
9172
+ function normaliseName(name) {
9173
+ let text = name.trim();
9174
+ text = text.replace(/^(?:sym\.(?:imp\.)?|fcn\.)/i, "");
9175
+ text = text.replace(/\(.*\)$/, "");
9176
+ text = text.replace(/\s*->.*$/, "");
9177
+ text = text.replace(/^_Z\d+/, "");
9178
+ text = text.replace(/^_+/, "");
9179
+ return text.toLowerCase();
9180
+ }
9181
+ function isNameable(symbol) {
9182
+ if (symbol.type !== "func" || symbol.size === 0) return false;
9183
+ if (symbol.name === "") return false;
9184
+ if (PLACEHOLDER.test(symbol.name)) return false;
9185
+ return true;
9186
+ }
9187
+ async function measureNaming(bytes, answer) {
9188
+ const elf = readElf(bytes);
9189
+ const held = elf.symbols.filter(isNameable).map((symbol) => ({
9190
+ truth: symbol.name,
9191
+ start: symbol.value,
9192
+ size: symbol.size,
9193
+ bind: symbol.bind
9194
+ })).sort((a, b) => a.start - b.start || (a.truth < b.truth ? -1 : a.truth > b.truth ? 1 : 0));
9195
+ const text = elf.bytesOf(".text");
9196
+ const textStart = elf.section(".text")?.offset ?? 0;
9197
+ const bodyOf = (start, size) => {
9198
+ const from = start - textStart;
9199
+ if (from < 0 || from + size > text.length) return new Uint8Array(0);
9200
+ return text.subarray(from, from + size);
9201
+ };
9202
+ const cases = [];
9203
+ for (const held_out of held) {
9204
+ const body = bodyOf(held_out.start, held_out.size);
9205
+ const question = {
9206
+ ...held_out,
9207
+ body,
9208
+ counts: countInstructions(body)
9209
+ };
9210
+ let reply;
9211
+ try {
9212
+ reply = await answer(question);
9213
+ } catch (err) {
9214
+ throw new OhosPerfError(
9215
+ `naming ${question.truth} failed: ${err.message}`,
9216
+ { code: "AGENT_NAMING_FAILED", cause: err }
9217
+ );
9218
+ }
9219
+ cases.push({
9220
+ truth: question.truth,
9221
+ answer: reply,
9222
+ correct: normaliseName(reply) === normaliseName(question.truth),
9223
+ start: question.start,
9224
+ size: question.size
9225
+ });
9226
+ }
9227
+ const correct = cases.filter((entry) => entry.correct).length;
9228
+ return {
9229
+ heldOut: cases.length,
9230
+ correct,
9231
+ accuracy: cases.length === 0 ? void 0 : correct / cases.length,
9232
+ cases
9233
+ };
9234
+ }
9235
+
8891
9236
  // src/scenario/agent-client.ts
8892
9237
  var OWN_BASE_URL = "OHOS_PERF_AGENT_BASE_URL";
8893
9238
  var OWN_API_KEY = "OHOS_PERF_AGENT_API_KEY";
@@ -18072,7 +18417,7 @@ var CENTRAL_SIGNATURE = 33639248;
18072
18417
  var LOCAL_SIGNATURE = 67324752;
18073
18418
  var ZIP64_SENTINEL = 4294967295;
18074
18419
  var ZIP_COMMENT_MAX = 65535;
18075
- function fail(code, message3) {
18420
+ function fail2(code, message3) {
18076
18421
  throw new OhosPerfError(message3, { code });
18077
18422
  }
18078
18423
  function u16(bytes, at) {
@@ -18083,7 +18428,7 @@ function u32(bytes, at) {
18083
18428
  }
18084
18429
  function need(bytes, at, length, end, what) {
18085
18430
  if (at < 0 || length < 0 || at + length > end) {
18086
- fail("HAP_NOT_ZIP", `${what} lies outside the archive`);
18431
+ fail2("HAP_NOT_ZIP", `${what} lies outside the archive`);
18087
18432
  }
18088
18433
  }
18089
18434
  function isZip(bytes) {
@@ -18099,32 +18444,32 @@ function findEocd(bytes) {
18099
18444
  function assertSafeName(name) {
18100
18445
  const normalized = name.replace(/\\/g, "/");
18101
18446
  if (normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized)) {
18102
- fail("HAP_UNSAFE_PATH", `archive entry ${JSON.stringify(name)} is an absolute path`);
18447
+ fail2("HAP_UNSAFE_PATH", `archive entry ${JSON.stringify(name)} is an absolute path`);
18103
18448
  }
18104
18449
  if (normalized.split("/").includes("..")) {
18105
- fail("HAP_UNSAFE_PATH", `archive entry ${JSON.stringify(name)} climbs out of the archive`);
18450
+ fail2("HAP_UNSAFE_PATH", `archive entry ${JSON.stringify(name)} climbs out of the archive`);
18106
18451
  }
18107
18452
  }
18108
18453
  function openZip(bytes) {
18109
18454
  const eocd = findEocd(bytes);
18110
18455
  if (eocd === -1) {
18111
- fail("HAP_NOT_ZIP", "not a ZIP archive: no end-of-central-directory record");
18456
+ fail2("HAP_NOT_ZIP", "not a ZIP archive: no end-of-central-directory record");
18112
18457
  }
18113
18458
  const count = u16(bytes, eocd + 10);
18114
18459
  const centralSize = u32(bytes, eocd + 12);
18115
18460
  const centralOffset = u32(bytes, eocd + 16);
18116
18461
  if (count === 65535 || centralSize === ZIP64_SENTINEL || centralOffset === ZIP64_SENTINEL) {
18117
- fail("HAP_ZIP64_UNSUPPORTED", "ZIP64 archives are not supported");
18462
+ fail2("HAP_ZIP64_UNSUPPORTED", "ZIP64 archives are not supported");
18118
18463
  }
18119
18464
  if (centralOffset + centralSize > bytes.length) {
18120
- fail("HAP_NOT_ZIP", "central directory lies outside the archive");
18465
+ fail2("HAP_NOT_ZIP", "central directory lies outside the archive");
18121
18466
  }
18122
18467
  const entries = [];
18123
18468
  let at = centralOffset;
18124
18469
  for (let index = 0; index < count; index++) {
18125
18470
  need(bytes, at, 46, bytes.length, `central directory entry ${index}`);
18126
18471
  if (u32(bytes, at) !== CENTRAL_SIGNATURE) {
18127
- fail("HAP_NOT_ZIP", `central directory entry ${index} has no header`);
18472
+ fail2("HAP_NOT_ZIP", `central directory entry ${index} has no header`);
18128
18473
  }
18129
18474
  const flags = u16(bytes, at + 8);
18130
18475
  const method = u16(bytes, at + 10);
@@ -18139,14 +18484,14 @@ function openZip(bytes) {
18139
18484
  const name = new TextDecoder("utf-8").decode(bytes.subarray(at + 46, at + 46 + nameLength));
18140
18485
  at += 46 + nameLength + extraLength + commentLength;
18141
18486
  if (size === ZIP64_SENTINEL || compressedSize === ZIP64_SENTINEL || localOffset === ZIP64_SENTINEL) {
18142
- fail("HAP_ZIP64_UNSUPPORTED", `archive entry ${JSON.stringify(name)} needs ZIP64`);
18487
+ fail2("HAP_ZIP64_UNSUPPORTED", `archive entry ${JSON.stringify(name)} needs ZIP64`);
18143
18488
  }
18144
18489
  assertSafeName(name);
18145
18490
  if ((flags & 1) !== 0) {
18146
- fail("HAP_ENCRYPTED_ENTRY", `archive entry ${JSON.stringify(name)} is encrypted`);
18491
+ fail2("HAP_ENCRYPTED_ENTRY", `archive entry ${JSON.stringify(name)} is encrypted`);
18147
18492
  }
18148
18493
  if (method !== 0 && method !== 8) {
18149
- fail(
18494
+ fail2(
18150
18495
  "HAP_UNSUPPORTED_METHOD",
18151
18496
  `archive entry ${JSON.stringify(name)} uses compression method ${method}; only stored (0) and deflate (8) are supported`
18152
18497
  );
@@ -18154,13 +18499,13 @@ function openZip(bytes) {
18154
18499
  if (name.endsWith("/")) continue;
18155
18500
  need(bytes, localOffset, 30, bytes.length, `archive entry ${JSON.stringify(name)} local header`);
18156
18501
  if (u32(bytes, localOffset) !== LOCAL_SIGNATURE) {
18157
- fail("HAP_NOT_ZIP", `archive entry ${JSON.stringify(name)} has no local header`);
18502
+ fail2("HAP_NOT_ZIP", `archive entry ${JSON.stringify(name)} has no local header`);
18158
18503
  }
18159
18504
  const localNameLength = u16(bytes, localOffset + 26);
18160
18505
  const localExtraLength = u16(bytes, localOffset + 28);
18161
18506
  const dataOffset = localOffset + 30 + localNameLength + localExtraLength;
18162
18507
  if (dataOffset + compressedSize > bytes.length) {
18163
- fail("HAP_NOT_ZIP", `archive entry ${JSON.stringify(name)} is truncated`);
18508
+ fail2("HAP_NOT_ZIP", `archive entry ${JSON.stringify(name)} is truncated`);
18164
18509
  }
18165
18510
  entries.push({ name, size, compressedSize, crc32: crc, method, dataOffset });
18166
18511
  }
@@ -18183,7 +18528,7 @@ function openZip(bytes) {
18183
18528
  }
18184
18529
  const actual = crc322(out);
18185
18530
  if (actual !== entry.crc32) {
18186
- fail(
18531
+ fail2(
18187
18532
  "HAP_CRC_MISMATCH",
18188
18533
  `archive entry ${JSON.stringify(entry.name)} fails its CRC check: header ${entry.crc32.toString(16)}, data ${actual.toString(16)}`
18189
18534
  );
@@ -18193,225 +18538,6 @@ function openZip(bytes) {
18193
18538
  };
18194
18539
  }
18195
18540
 
18196
- // src/hap/elf.ts
18197
- var EM_AARCH64 = 183;
18198
- var SHT_SYMTAB = 2;
18199
- var SHT_NOBITS = 8;
18200
- var SHT_DYNSYM = 11;
18201
- function fail2(message3, cause) {
18202
- throw new OhosPerfError(message3, { code: "ELF_INVALID", ...cause === void 0 ? {} : { cause } });
18203
- }
18204
- function view(bytes) {
18205
- return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
18206
- }
18207
- function field(dv, at, size, what) {
18208
- if (at < 0 || at + size > dv.byteLength) {
18209
- fail2(`ELF is truncated: ${what} at offset ${at} runs past the ${dv.byteLength}-byte file`);
18210
- }
18211
- if (size === 1) return dv.getUint8(at);
18212
- if (size === 2) return dv.getUint16(at, true);
18213
- if (size === 4) return dv.getUint32(at, true);
18214
- return dv.getUint32(at, true) + dv.getUint32(at + 4, true) * 2 ** 32;
18215
- }
18216
- function readString(table, offset) {
18217
- if (offset < 0 || offset >= table.length) return "";
18218
- const end = table.indexOf(0, offset);
18219
- return new TextDecoder("utf-8").decode(
18220
- table.subarray(offset, end === -1 ? table.length : end)
18221
- );
18222
- }
18223
- function bindOf(info) {
18224
- const bind = info >> 4;
18225
- if (bind === 0) return "local";
18226
- if (bind === 1) return "global";
18227
- if (bind === 2) return "weak";
18228
- return "other";
18229
- }
18230
- function typeOf(info) {
18231
- const type = info & 15;
18232
- if (type === 0) return "notype";
18233
- if (type === 1) return "object";
18234
- if (type === 2) return "func";
18235
- if (type === 3) return "section";
18236
- if (type === 4) return "file";
18237
- return "other";
18238
- }
18239
- function symbolTableOf(dv, sections, links, bytes, index) {
18240
- const section = sections[index];
18241
- const link = links[index];
18242
- const strings = link >= 0 && link < sections.length ? bytes.subarray(sections[link].offset, sections[link].offset + sections[link].size) : new Uint8Array(0);
18243
- const entrySize = section.entrySize === 0 ? 24 : section.entrySize;
18244
- const count = Math.floor(section.size / entrySize);
18245
- const symbols = [];
18246
- for (let at = 0; at < count; at += 1) {
18247
- const base = section.offset + at * entrySize;
18248
- if (at === 0) continue;
18249
- const nameOffset = field(dv, base, 4, "st_name");
18250
- const info = field(dv, base + 4, 1, "st_info");
18251
- const sectionIndex = field(dv, base + 6, 2, "st_shndx");
18252
- const size = field(dv, base + 16, 8, "st_size");
18253
- const name = readString(strings, nameOffset);
18254
- symbols.push({ name, bind: bindOf(info), type: typeOf(info), size, sectionIndex });
18255
- }
18256
- return symbols;
18257
- }
18258
- function readElf(bytes) {
18259
- if (bytes.length < 4) {
18260
- fail2(`ELF is truncated: ${bytes.length} bytes is shorter than the 4-byte magic`);
18261
- }
18262
- if (bytes[0] !== 127 || bytes[1] !== 69 || bytes[2] !== 76 || bytes[3] !== 70) {
18263
- fail2("not an ELF file: the first four bytes are not \\x7fELF");
18264
- }
18265
- if (bytes.length < 16) {
18266
- fail2(`ELF is truncated: ${bytes.length} bytes is shorter than the 16-byte ident`);
18267
- }
18268
- const bits = bytes[4] === 2 ? 64 : bytes[4] === 1 ? 32 : 0;
18269
- if (bits === 0) {
18270
- fail2(`unsupported ELF class ${String(bytes[4])}: only 32-bit and 64-bit are defined`);
18271
- }
18272
- const endian = bytes[5] === 1 ? "little" : bytes[5] === 2 ? "big" : void 0;
18273
- if (endian === void 0) {
18274
- fail2(`unsupported ELF data encoding ${String(bytes[5])}: only little and big endian are defined`);
18275
- }
18276
- if (bits !== 64 || endian !== "little") {
18277
- fail2(`unsupported ELF: ${String(bits)}-bit ${endian}-endian; OHOS ships 64-bit little-endian`);
18278
- }
18279
- const headerSize = 64;
18280
- if (bytes.length < headerSize) {
18281
- fail2(`ELF is truncated: ${bytes.length} bytes is shorter than the ${headerSize}-byte header`);
18282
- }
18283
- const dv = view(bytes);
18284
- const machine = field(dv, 18, 2, "e_machine");
18285
- const type = field(dv, 16, 2, "e_type");
18286
- const shoff = field(dv, 40, 8, "e_shoff");
18287
- const shentsize = field(dv, 58, 2, "e_shentsize");
18288
- const shnum = field(dv, 60, 2, "e_shnum");
18289
- const shstrndx = field(dv, 62, 2, "e_shstrndx");
18290
- if (shnum === 0) {
18291
- return {
18292
- bits: 64,
18293
- endian,
18294
- machine,
18295
- type,
18296
- sections: [],
18297
- symbols: [],
18298
- section: () => void 0,
18299
- bytesOf: () => new Uint8Array(0)
18300
- };
18301
- }
18302
- if (shentsize !== 64) {
18303
- fail2(`unsupported section header size ${shentsize}: a 64-bit ELF uses 64`);
18304
- }
18305
- if (shoff + shnum * shentsize > bytes.length) {
18306
- fail2(
18307
- `ELF is truncated: the section header table at offset ${shoff} with ${shnum} entries runs past the ${bytes.length}-byte file`
18308
- );
18309
- }
18310
- if (shstrndx >= shnum) {
18311
- fail2(`e_shstrndx ${shstrndx} names a section beyond the ${shnum} the file declares`);
18312
- }
18313
- const raw = [];
18314
- const links = [];
18315
- for (let index = 0; index < shnum; index += 1) {
18316
- const at = shoff + index * shentsize;
18317
- raw.push({
18318
- nameOffset: field(dv, at, 4, `section[${index}].sh_name`),
18319
- type: field(dv, at + 4, 4, `section[${index}].sh_type`),
18320
- flags: field(dv, at + 8, 8, `section[${index}].sh_flags`),
18321
- offset: field(dv, at + 24, 8, `section[${index}].sh_offset`),
18322
- size: field(dv, at + 32, 8, `section[${index}].sh_size`),
18323
- link: field(dv, at + 40, 4, `section[${index}].sh_link`),
18324
- entrySize: field(dv, at + 56, 8, `section[${index}].sh_entsize`)
18325
- });
18326
- links.push(raw[index].link);
18327
- }
18328
- for (const [index, section] of raw.entries()) {
18329
- if (section.type === SHT_NOBITS || section.type === 0) continue;
18330
- if (section.offset + section.size > bytes.length) {
18331
- fail2(
18332
- `ELF is truncated: section ${index} at offset ${section.offset} with size ${section.size} runs past the ${bytes.length}-byte file`
18333
- );
18334
- }
18335
- }
18336
- const nameTable = raw[shstrndx];
18337
- const strings = bytes.subarray(nameTable.offset, nameTable.offset + nameTable.size);
18338
- const sections = raw.map((section) => ({
18339
- name: readString(strings, section.nameOffset),
18340
- type: section.type,
18341
- flags: section.flags,
18342
- offset: section.offset,
18343
- size: section.size,
18344
- entrySize: section.entrySize
18345
- }));
18346
- const symbols = [];
18347
- for (const [index, section] of sections.entries()) {
18348
- if (section.type !== SHT_SYMTAB && section.type !== SHT_DYNSYM) continue;
18349
- symbols.push(...symbolTableOf(dv, sections, links, bytes, index));
18350
- }
18351
- const byName = new Map(sections.map((section) => [section.name, section]));
18352
- return {
18353
- bits: 64,
18354
- endian,
18355
- machine,
18356
- type,
18357
- sections,
18358
- symbols,
18359
- section: (name) => byName.get(name),
18360
- bytesOf: (name) => {
18361
- const section = byName.get(name);
18362
- if (section === void 0 || section.type === SHT_NOBITS) return new Uint8Array(0);
18363
- return bytes.subarray(section.offset, section.offset + section.size);
18364
- }
18365
- };
18366
- }
18367
- function classifyInstruction(word) {
18368
- const masked = (mask) => (word & mask) >>> 0;
18369
- if (masked(4294966303) === 3596550144) return "ret";
18370
- if (masked(4294966303) === 3594452992) return "blr";
18371
- if (masked(4294966303) === 3592355840) return "br";
18372
- if (masked(4227858432) === 2483027968) return "bl";
18373
- if (masked(4227858432) === 335544320) return "b";
18374
- if (masked(4278190096) === 1409286144) return "bcond";
18375
- if (masked(2113929216) === 872415232) return "cbz";
18376
- if (masked(2113929216) === 905969664) return "tbz";
18377
- if (masked(2667577344) === 2415919104) return "adrp";
18378
- if (masked(2667577344) === 268435456) return "adr";
18379
- if (masked(989855744) === 956301312) {
18380
- return masked(4194304) === 0 ? "str" : "ldr";
18381
- }
18382
- if (masked(520093696) === 285212672) return "add";
18383
- if (masked(167772160) === 167772160) return "vector";
18384
- return "other";
18385
- }
18386
- function countInstructions(payload) {
18387
- const counts = {
18388
- total: 0,
18389
- ret: 0,
18390
- blr: 0,
18391
- br: 0,
18392
- bl: 0,
18393
- b: 0,
18394
- bcond: 0,
18395
- cbz: 0,
18396
- tbz: 0,
18397
- adrp: 0,
18398
- adr: 0,
18399
- ldr: 0,
18400
- str: 0,
18401
- add: 0,
18402
- vector: 0,
18403
- other: 0
18404
- };
18405
- const dv = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
18406
- const words = Math.floor(payload.length / 4);
18407
- for (let index = 0; index < words; index += 1) {
18408
- const cls = classifyInstruction(dv.getUint32(index * 4, true));
18409
- counts[cls] += 1;
18410
- counts.total += 1;
18411
- }
18412
- return counts;
18413
- }
18414
-
18415
18541
  // src/hap/optimization.ts
18416
18542
  var OFFLINE_WINDOW = { startNs: 0, endNs: 0 };
18417
18543
  var LTO_PATTERNS = [
@@ -19864,6 +19990,7 @@ export {
19864
19990
  UiAnalyzer,
19865
19991
  UitestCollector,
19866
19992
  VsyncAnalyzer,
19993
+ addressOfOffset,
19867
19994
  agentPrompt,
19868
19995
  aggregateUnreleased,
19869
19996
  analyseAnimations,
@@ -19918,6 +20045,7 @@ export {
19918
20045
  filterEmptyFrames,
19919
20046
  flattenUiTree,
19920
20047
  ftracePlugin,
20048
+ functionAt,
19921
20049
  gpuPlugin,
19922
20050
  hapSection,
19923
20051
  hashTree,
@@ -19934,11 +20062,13 @@ export {
19934
20062
  matchHapRules,
19935
20063
  matchRules,
19936
20064
  matchSelector,
20065
+ measureNaming,
19937
20066
  memoryPlugin,
19938
20067
  metric,
19939
20068
  nativeEventKind,
19940
20069
  nativehookPlugin,
19941
20070
  nodeIdentity,
20071
+ normaliseName,
19942
20072
  openDb,
19943
20073
  openZip,
19944
20074
  optimizationSection,
@@ -19967,6 +20097,7 @@ export {
19967
20097
  readProcfsSamples,
19968
20098
  readSceneMetadata,
19969
20099
  readUiTree,
20100
+ recoverSymbols,
19970
20101
  renderBundle,
19971
20102
  renderEvidenceCsv,
19972
20103
  renderFlamegraphHtml,
@@ -19995,6 +20126,7 @@ export {
19995
20126
  runProbe,
19996
20127
  sortSteps,
19997
20128
  summarizeReport,
20129
+ symbolIndex,
19998
20130
  tableRowCounts,
19999
20131
  trendRunFromReport,
20000
20132
  unknownQueryError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohos-perf/core",
3
- "version": "0.21.0",
3
+ "version": "0.22.1",
4
4
  "description": "HarmonyOS performance analysis: capability probing, nine collectors, trace ingest, typed queries, twenty-one analyzers with provenance and fidelity, reports and a scenario runner",
5
5
  "keywords": [
6
6
  "harmonyos",