@ohos-perf/core 0.14.0 → 0.15.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.
package/dist/index.d.ts CHANGED
@@ -2127,6 +2127,106 @@ declare function nodeIdentity(node: UiNode): string;
2127
2127
  */
2128
2128
  declare function diffTrees(before: readonly UiNode[], after: readonly UiNode[]): UiTreeDiff;
2129
2129
 
2130
+ /**
2131
+ * Animation labelling for a start/end capture pair (HapRay parity row 31).
2132
+ *
2133
+ * Ported from `ui_detector/image_comparator.py` and the label bands in
2134
+ * `analyze/ui_analyzer.py`: crop a region from both screenshots, compare their
2135
+ * dHashes, and call the region an animation when the similarity falls under
2136
+ * 85%. The bands are HapRay's — `major_change` under 50, `moderate_change`
2137
+ * under 70, `minor_change` under 85 — and are kept so a reader who knows
2138
+ * HapRay's numbers reads the same ones here.
2139
+ *
2140
+ * ## Why this is narrower than HapRay
2141
+ *
2142
+ * HapRay's label rests on pixels alone, and pixels alone are not evidence of
2143
+ * an animation. A blinking text cursor, a system clock in the status bar and a
2144
+ * video frame all move under a region the app never re-rendered; conversely a
2145
+ * node the tree added but the screen never painted is a rendering defect, not
2146
+ * an animation. So a region is labelled only when *both* the pixels and the
2147
+ * tree moved inside it, and each half is reported so the caller can see the
2148
+ * agreement rather than take the label on trust. A pixel-only movement is
2149
+ * returned separately — it is a real observation, just not this label.
2150
+ *
2151
+ * ## Resolution dependence
2152
+ *
2153
+ * The dHash is computed at a fixed 9×8 grid, so a region smaller than that
2154
+ * grid cannot express its own detail: two 3×3 regions hash identically
2155
+ * whatever they contain. Regions below {@link MIN_HASH_PIXELS} are therefore
2156
+ * not labelled, and say so in `unmeasured`.
2157
+ */
2158
+ /** HapRay's similarity bands, as percentages. */
2159
+ declare const ANIMATION_BANDS: {
2160
+ readonly major: 50;
2161
+ readonly moderate: 70;
2162
+ readonly minor: 85;
2163
+ };
2164
+ /** A region smaller than this cannot fill the 9×8 hash grid. */
2165
+ declare const MIN_HASH_PIXELS: number;
2166
+ type AnimationSeverity = 'major_change' | 'moderate_change' | 'minor_change';
2167
+ /** How much the pixels inside one region moved between the two captures. */
2168
+ interface RegionPixelChange {
2169
+ readonly bounds: Rect;
2170
+ /** 0..1; 1 means the two hashes are identical. */
2171
+ readonly similarity: number;
2172
+ /** Fraction of the region's pixels whose channels differ by more than the tolerance. */
2173
+ readonly changedRatio: number;
2174
+ readonly dhashA: string;
2175
+ readonly dhashB: string;
2176
+ }
2177
+ /** A region both halves agree moved: an animation label. */
2178
+ interface AnimationLabel extends RegionPixelChange {
2179
+ readonly label: 'animation';
2180
+ readonly severity: AnimationSeverity;
2181
+ /** Tree differences whose bounds fall inside this region. */
2182
+ readonly treeChanges: number;
2183
+ }
2184
+ /** A region the pixels moved in while the tree did not. */
2185
+ interface PixelOnlyChange extends RegionPixelChange {
2186
+ readonly note: 'pixels changed, tree did not: not labelled an animation';
2187
+ }
2188
+ /** A region that was skipped, and why. */
2189
+ interface UnmeasuredRegion {
2190
+ readonly bounds: Rect;
2191
+ readonly reason: string;
2192
+ }
2193
+ interface AnimationAnalysis {
2194
+ readonly animations: AnimationLabel[];
2195
+ readonly pixelOnly: PixelOnlyChange[];
2196
+ readonly unmeasured: UnmeasuredRegion[];
2197
+ }
2198
+ /**
2199
+ * HapRay's severity band for a similarity percentage.
2200
+ *
2201
+ * Returns `undefined` at or above the 85% band: HapRay calls that
2202
+ * `no_change`, and a label for no change is not an animation.
2203
+ */
2204
+ declare function animationSeverity(similarityPercent: number): AnimationSeverity | undefined;
2205
+ /**
2206
+ * Crop a region out of an image.
2207
+ *
2208
+ * `right` and `bottom` are exclusive, matching `bounds` as `uitest` writes it
2209
+ * (`[0,0][8,4]` on an 8×4 screen). A region is clipped to the image rather
2210
+ * than refused: a node whose bounds run past the screen still has a visible
2211
+ * part, and that part is what the capture can speak about.
2212
+ */
2213
+ declare function cropRegion(image: RgbaImage, rect: Rect): RgbaImage;
2214
+ /** Compare one region across the two captures, or `undefined` when too small. */
2215
+ declare function compareRegion(a: RgbaImage, b: RgbaImage, rect: Rect, tolerance: number): RegionPixelChange | undefined;
2216
+ /**
2217
+ * Label the regions both halves agree moved.
2218
+ *
2219
+ * `treeRegions` are the bounds the tree diff reported, each with its count of
2220
+ * differences; `pixelOnlyBounds` is where to look when the tree reported
2221
+ * nothing at all — the whole screen, because there is no node to narrow it to.
2222
+ * A region whose pixels moved and whose tree did not is returned in
2223
+ * `pixelOnly`, never promoted.
2224
+ */
2225
+ declare function analyseAnimations(a: RgbaImage, b: RgbaImage, treeRegions: ReadonlyArray<{
2226
+ bounds: Rect;
2227
+ changes: number;
2228
+ }>, pixelOnlyBounds: Rect | undefined, tolerance: number): AnimationAnalysis;
2229
+
2130
2230
  /** What one side of the comparison contained, as the page and JSON report it. */
2131
2231
  interface UiDiffSide {
2132
2232
  readonly dir: string;
@@ -2155,6 +2255,19 @@ interface UiDiff {
2155
2255
  readonly image: ImageComparison | null;
2156
2256
  readonly tree: UiTreeDiff | null;
2157
2257
  readonly regions: Rect[];
2258
+ /**
2259
+ * Regions both the pixels and the tree agree moved between the two captures
2260
+ * (HapRay parity row 31). Empty for a tree-only comparison, which has no
2261
+ * pixels to compare.
2262
+ */
2263
+ readonly animations: AnimationAnalysis['animations'];
2264
+ /**
2265
+ * Regions whose pixels moved while the tree did not: a cursor blink, a video
2266
+ * frame, a system clock. Reported, never labelled an animation.
2267
+ */
2268
+ readonly pixelOnly: AnimationAnalysis['pixelOnly'];
2269
+ /** Regions too small for the dHash grid to say anything about. */
2270
+ readonly unmeasuredRegions: AnimationAnalysis['unmeasured'];
2158
2271
  readonly degraded: string[];
2159
2272
  }
2160
2273
  /** Where `compareSceneDirs` writes its artifacts. */
@@ -5888,4 +6001,4 @@ interface FlamegraphPageInput {
5888
6001
  */
5889
6002
  declare function renderFlamegraphHtml(input: FlamegraphPageInput): string;
5890
6003
 
5891
- export { type ActionContext, type ActionDevice, type ActionOutcome, type ActiveAlloc, type AnalyzeContext, type AnalyzeResult, type Analyzer, type AnalyzerRun, type AnalyzerSection, type AppIdentity, type BaselineComparison, type BelowThresholdPattern, type BinderAnalysis, BinderAnalyzer, type BinderEndpoint, type BinderEvent, type BinderInterfaceStat, type BinderProcessStat, BinderQuery, type BinderThreadStat, type BinderTransaction, 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, 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, EXCLUDE_PATTERNS, 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, 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, IGNORED_ATTRIBUTES, type ImageComparison, IngestError, InstantQuery, type InventoryFile, type JsheapCapture, JsheapCollector, MAX_QUERY_LIMIT, METRIC_DIRECTIONS, MIN_BUFFER_PAGES, 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 OptimizationPotential, 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 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, RenderAnalyzer, 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, UI_DIFF_FILES, UiAnalyzer, type UiCompareOptions, type UiDiff, type UiDiffSide, type UiNode, type UiTreeDiff, type UiTreeDifference, UitestCollector, type UnreleasedRow, type VsyncAnalysis, VsyncAnalyzer, type VsyncPeriod, type VsyncPeriodKind, type VsyncSeverity, type WakeupEvent, type WindowHitches, type ZipArchive, type ZipEntry, aggregateUnreleased, analyzeHap, analyzeThreadWakeup, buildDepGraph, buildHiprofilerConfig, buildInventory, buildMatrix, buildNativeTimeline, buildReport, categorize, classifyNativePath, compareImages, compareResults, compareSceneDirs, compareScenes, compileRules, computeBinderAnalysis, computeComponentReuse, computeFaultTree, computeFpsWindows, computeGc, computeRsSkip, computeThreadAnalysis, computeVsyncAnomalies, connect, createSceneLayout, decodePng, defaultAnalyzers, dhash, diffTrees, discoverCases, encodePng, escapeHtml, evidence, executeAction, filterEmptyFrames, flattenUiTree, ftracePlugin, gpuPlugin, hapSection, hiperfRecordCommand, ingestScene, isUnresolvedSymbol, isZip, loadCases, lookupQuery, markRegions, matchHapRules, matchRules, matchSelector, memoryPlugin, metric, nativeEventKind, nativehookPlugin, nodeIdentity, openDb, openZip, pairNativeMemory, paritySummary, parseBounds, parseFpsCounts, parseHilogLine, parseHilogText, parseHiperfSummary, parseHitches, parseProcfsStatus, parseRedundantFile, parseScenario, parseSelector, parseSmapsRollup, queryDefinitions, readHidumperCapture, readHilogText, readJsheapSnapshot, readProcfsSamples, readSceneMetadata, readUiTree, renderEvidenceCsv, renderFlamegraphHtml, renderFlamegraphSvg, renderMetricsCsv, renderReportHtml, renderReportJson, renderReportXlsx, renderScenesComparison, renderSummaryJson, renderUiDiffHtml, resolveAppIdentity, resolveAppIpids, resolveQueryLimit, resolveSelector, round2HalfEven, runAnalyzerSections, runAnalyzers, runDrillDown, runNamedQuery, runProbe, sortSteps, summarizeReport, tableRowCounts, unknownQueryError, validateRules, writeProcfsSamples, writeRunFiles, writeSceneMetadata, xpowerPlugin };
6004
+ export { ANIMATION_BANDS, type ActionContext, type ActionDevice, type ActionOutcome, type ActiveAlloc, type AnalyzeContext, type AnalyzeResult, type Analyzer, type AnalyzerRun, type AnalyzerSection, type AnimationAnalysis, type AnimationLabel, type AnimationSeverity, type AppIdentity, type BaselineComparison, type BelowThresholdPattern, type BinderAnalysis, BinderAnalyzer, type BinderEndpoint, type BinderEvent, type BinderInterfaceStat, type BinderProcessStat, BinderQuery, type BinderThreadStat, type BinderTransaction, 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, 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, EXCLUDE_PATTERNS, 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, 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, IGNORED_ATTRIBUTES, type ImageComparison, IngestError, InstantQuery, type InventoryFile, 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 OptimizationPotential, 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 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, 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, aggregateUnreleased, analyseAnimations, analyzeHap, analyzeThreadWakeup, animationSeverity, buildDepGraph, buildHiprofilerConfig, buildInventory, buildMatrix, buildNativeTimeline, buildReport, categorize, classifyNativePath, compareImages, compareRegion, compareResults, compareSceneDirs, compareScenes, compileRules, computeBinderAnalysis, computeComponentReuse, computeFaultTree, computeFpsWindows, computeGc, computeRsSkip, computeThreadAnalysis, computeVsyncAnomalies, connect, createSceneLayout, cropRegion, decodePng, defaultAnalyzers, dhash, diffTrees, discoverCases, encodePng, escapeHtml, evidence, executeAction, filterEmptyFrames, flattenUiTree, ftracePlugin, gpuPlugin, hapSection, hiperfRecordCommand, ingestScene, isUnresolvedSymbol, isZip, loadCases, lookupQuery, markRegions, matchHapRules, matchRules, matchSelector, memoryPlugin, metric, nativeEventKind, nativehookPlugin, nodeIdentity, openDb, openZip, pairNativeMemory, paritySummary, parseBounds, parseFpsCounts, parseHilogLine, parseHilogText, parseHiperfSummary, parseHitches, parseProcfsStatus, parseRedundantFile, parseScenario, parseSelector, parseSmapsRollup, queryDefinitions, readHidumperCapture, readHilogText, readJsheapSnapshot, readProcfsSamples, readSceneMetadata, readUiTree, renderEvidenceCsv, renderFlamegraphHtml, renderFlamegraphSvg, renderMetricsCsv, renderReportHtml, renderReportJson, renderReportXlsx, renderScenesComparison, renderSummaryJson, renderUiDiffHtml, resolveAppIdentity, resolveAppIpids, resolveQueryLimit, resolveSelector, round2HalfEven, runAnalyzerSections, runAnalyzers, runDrillDown, runNamedQuery, runProbe, sortSteps, summarizeReport, tableRowCounts, unknownQueryError, validateRules, writeProcfsSamples, writeRunFiles, writeSceneMetadata, xpowerPlugin };
package/dist/index.js CHANGED
@@ -5019,6 +5019,108 @@ function diffTrees(before, after) {
5019
5019
  import { existsSync as existsSync13, mkdirSync as mkdirSync8, readFileSync as readFileSync10, writeFileSync as writeFileSync7 } from "node:fs";
5020
5020
  import { join as join7, resolve } from "node:path";
5021
5021
 
5022
+ // src/ui/animation.ts
5023
+ var ANIMATION_BANDS = {
5024
+ major: 50,
5025
+ moderate: 70,
5026
+ minor: 85
5027
+ };
5028
+ var MIN_HASH_PIXELS = 9 * 8;
5029
+ function animationSeverity(similarityPercent) {
5030
+ if (similarityPercent < ANIMATION_BANDS.major) return "major_change";
5031
+ if (similarityPercent < ANIMATION_BANDS.moderate) return "moderate_change";
5032
+ if (similarityPercent < ANIMATION_BANDS.minor) return "minor_change";
5033
+ return void 0;
5034
+ }
5035
+ function cropRegion(image, rect) {
5036
+ const left = Math.max(0, Math.min(rect.left, rect.right));
5037
+ const right = Math.min(image.width, Math.max(rect.left, rect.right));
5038
+ const top = Math.max(0, Math.min(rect.top, rect.bottom));
5039
+ const bottom = Math.min(image.height, Math.max(rect.top, rect.bottom));
5040
+ const width = Math.max(0, right - left);
5041
+ const height = Math.max(0, bottom - top);
5042
+ const data = new Uint8Array(width * height * 4);
5043
+ for (let y = 0; y < height; y += 1) {
5044
+ const from = ((top + y) * image.width + left) * 4;
5045
+ data.set(image.data.subarray(from, from + width * 4), y * width * 4);
5046
+ }
5047
+ return { width, height, data };
5048
+ }
5049
+ function hammingHex(a, b) {
5050
+ let distance = 0;
5051
+ for (let i = 0; i < a.length; i += 1) {
5052
+ let xor = parseInt(a[i], 16) ^ parseInt(b[i], 16);
5053
+ while (xor !== 0) {
5054
+ distance += xor & 1;
5055
+ xor >>= 1;
5056
+ }
5057
+ }
5058
+ return distance;
5059
+ }
5060
+ function compareRegion(a, b, rect, tolerance) {
5061
+ const left = cropRegion(a, rect);
5062
+ const right = cropRegion(b, rect);
5063
+ const width = Math.min(left.width, right.width);
5064
+ const height = Math.min(left.height, right.height);
5065
+ if (width * height < MIN_HASH_PIXELS) return void 0;
5066
+ const dhashA = dhash(left);
5067
+ const dhashB = dhash(right);
5068
+ let changed = 0;
5069
+ let compared = 0;
5070
+ for (let y = 0; y < height; y += 1) {
5071
+ for (let x = 0; x < width; x += 1) {
5072
+ const at = (y * left.width + x) * 4;
5073
+ const bt = (y * right.width + x) * 4;
5074
+ compared += 1;
5075
+ if (Math.abs(left.data[at] - right.data[bt]) > tolerance || Math.abs(left.data[at + 1] - right.data[bt + 1]) > tolerance || Math.abs(left.data[at + 2] - right.data[bt + 2]) > tolerance || Math.abs(left.data[at + 3] - right.data[bt + 3]) > tolerance) {
5076
+ changed += 1;
5077
+ }
5078
+ }
5079
+ }
5080
+ return {
5081
+ bounds: rect,
5082
+ similarity: 1 - hammingHex(dhashA, dhashB) / 64,
5083
+ changedRatio: compared === 0 ? 0 : changed / compared,
5084
+ dhashA,
5085
+ dhashB
5086
+ };
5087
+ }
5088
+ function analyseAnimations(a, b, treeRegions, pixelOnlyBounds, tolerance) {
5089
+ const animations = [];
5090
+ const pixelOnly = [];
5091
+ const unmeasured = [];
5092
+ const consider = (bounds, treeChanges) => {
5093
+ const pixels = compareRegion(a, b, bounds, tolerance);
5094
+ if (pixels === void 0) {
5095
+ unmeasured.push({
5096
+ bounds,
5097
+ reason: `the region is smaller than the ${MIN_HASH_PIXELS}-pixel dHash grid, so its pixels cannot be compared`
5098
+ });
5099
+ return;
5100
+ }
5101
+ if (pixels.changedRatio === 0) return;
5102
+ if (treeChanges === 0) {
5103
+ pixelOnly.push({
5104
+ ...pixels,
5105
+ note: "pixels changed, tree did not: not labelled an animation"
5106
+ });
5107
+ return;
5108
+ }
5109
+ const severity = animationSeverity(pixels.similarity * 100);
5110
+ if (severity === void 0) return;
5111
+ animations.push({ ...pixels, label: "animation", severity, treeChanges });
5112
+ };
5113
+ for (const region of treeRegions) consider(region.bounds, region.changes);
5114
+ if (treeRegions.length === 0 && pixelOnlyBounds !== void 0) {
5115
+ consider(pixelOnlyBounds, 0);
5116
+ }
5117
+ const order = (x, y) => x.bounds.top - y.bounds.top || x.bounds.left - y.bounds.left || x.bounds.bottom - y.bounds.bottom || x.bounds.right - y.bounds.right;
5118
+ animations.sort(order);
5119
+ pixelOnly.sort(order);
5120
+ unmeasured.sort(order);
5121
+ return { animations, pixelOnly, unmeasured };
5122
+ }
5123
+
5022
5124
  // src/report/escape.ts
5023
5125
  function escapeHtml(value) {
5024
5126
  return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
@@ -5119,6 +5221,28 @@ function renderUiDiffHtml(diff) {
5119
5221
  "</table>"
5120
5222
  ].join("");
5121
5223
  })();
5224
+ const animationSection = (() => {
5225
+ const labels = diff.animations;
5226
+ const pixelOnly = diff.pixelOnly;
5227
+ const unmeasured = diff.unmeasuredRegions;
5228
+ if (labels.length === 0 && pixelOnly.length === 0 && unmeasured.length === 0) {
5229
+ return '<h2>Animations</h2><p class="meta">No region changed in both the pixels and the tree, so no animation is labelled.</p>';
5230
+ }
5231
+ const rect = (bounds) => `[${bounds.left},${bounds.top}][${bounds.right},${bounds.bottom}]`;
5232
+ const rows = [
5233
+ ...labels.map((item) => `<tr><td>animation (${escapeHtml(item.severity)})</td><td class="num">${rect(item.bounds)}</td><td class="num">${(item.similarity * 100).toFixed(1)}%</td><td class="num">${item.treeChanges}</td></tr>`),
5234
+ ...pixelOnly.map((item) => `<tr><td>pixels only, not labelled</td><td class="num">${rect(item.bounds)}</td><td class="num">${(item.similarity * 100).toFixed(1)}%</td><td class="num">0</td></tr>`),
5235
+ ...unmeasured.map((item) => `<tr><td>unmeasured: ${escapeHtml(item.reason)}</td><td class="num">${rect(item.bounds)}</td><td class="num">\u2014</td><td class="num">\u2014</td></tr>`)
5236
+ ].join("");
5237
+ return [
5238
+ "<h2>Animations</h2>",
5239
+ `<p class="meta">A region is labelled an animation only when its pixels moved and the tree reports a change inside it. A pixel-only movement \u2014 a cursor, a video frame, a system clock \u2014 is listed but not labelled. Bands follow HapRay: major under ${ANIMATION_BANDS.major}% similar, moderate under ${ANIMATION_BANDS.moderate}%, minor under ${ANIMATION_BANDS.minor}%.</p>`,
5240
+ "<table>",
5241
+ "<thead><tr><th>label</th><th>bounds</th><th>similarity</th><th>tree changes</th></tr></thead>",
5242
+ `<tbody>${rows}</tbody>`,
5243
+ "</table>"
5244
+ ].join("");
5245
+ })();
5122
5246
  const captureLines = [
5123
5247
  diff.a.startedAtMs === void 0 ? void 0 : `a captured at ${diff.a.startedAtMs} ms`,
5124
5248
  diff.b.startedAtMs === void 0 ? void 0 : `b captured at ${diff.b.startedAtMs} ms`
@@ -5143,6 +5267,7 @@ function renderUiDiffHtml(diff) {
5143
5267
  banner,
5144
5268
  screens,
5145
5269
  imageNumbers,
5270
+ animationSection,
5146
5271
  treeRows,
5147
5272
  "<footer>Generated by @ohos-perf/core. No scripts, no network access.</footer>",
5148
5273
  "</main>",
@@ -5193,6 +5318,19 @@ function collectRegions(tree) {
5193
5318
  );
5194
5319
  return regions;
5195
5320
  }
5321
+ function regionCounts(tree) {
5322
+ const counts = /* @__PURE__ */ new Map();
5323
+ const all = [...tree.added, ...tree.removed, ...tree.changed];
5324
+ for (const difference2 of all) {
5325
+ if (difference2.bounds === void 0) continue;
5326
+ const rect = difference2.bounds;
5327
+ const key = `${rect.left},${rect.top},${rect.right},${rect.bottom}`;
5328
+ const found = counts.get(key);
5329
+ if (found === void 0) counts.set(key, { bounds: rect, changes: 1 });
5330
+ else found.changes += 1;
5331
+ }
5332
+ return [...counts.values()];
5333
+ }
5196
5334
  function readSide(dir, side) {
5197
5335
  const layout = createSceneLayout(dir);
5198
5336
  const hasImage = existsSync13(layout.screenshotFile);
@@ -5242,6 +5380,13 @@ async function compareSceneDirs(a, b, opts) {
5242
5380
  };
5243
5381
  };
5244
5382
  const regions = collectRegions(tree);
5383
+ const animations = left.image === void 0 || right.image === void 0 || tree === null ? { animations: [], pixelOnly: [], unmeasured: [] } : analyseAnimations(
5384
+ left.image,
5385
+ right.image,
5386
+ regionCounts(tree),
5387
+ { left: 0, top: 0, right: left.image.width, bottom: left.image.height },
5388
+ opts.tolerance ?? 8
5389
+ );
5245
5390
  const diff = {
5246
5391
  schemaVersion: 1,
5247
5392
  a: side(dirA, left.image, left.nodes),
@@ -5249,6 +5394,9 @@ async function compareSceneDirs(a, b, opts) {
5249
5394
  image,
5250
5395
  tree,
5251
5396
  regions,
5397
+ animations: animations.animations,
5398
+ pixelOnly: animations.pixelOnly,
5399
+ unmeasuredRegions: animations.unmeasured,
5252
5400
  degraded
5253
5401
  };
5254
5402
  const outDir = resolve(opts.outDir);
@@ -6192,8 +6340,8 @@ var PARITY_ROWS = [
6192
6340
  {
6193
6341
  row: 31,
6194
6342
  name: "UI animation analysis",
6195
- status: "partial",
6196
- reason: "A start/end capture pair is compared by the same tree and image comparators, but the animation label itself is not emitted: dHash thresholds are unvalidated and resolution dependent.",
6343
+ status: "ported",
6344
+ reason: "",
6197
6345
  analyzer: "UiAnalyzer"
6198
6346
  },
6199
6347
  {
@@ -18079,6 +18227,7 @@ function renderFlamegraphHtml(input) {
18079
18227
  ].join("\n");
18080
18228
  }
18081
18229
  export {
18230
+ ANIMATION_BANDS,
18082
18231
  BinderAnalyzer,
18083
18232
  BinderQuery,
18084
18233
  CATEGORY_EXTENSIONS,
@@ -18132,6 +18281,7 @@ export {
18132
18281
  MAX_QUERY_LIMIT,
18133
18282
  METRIC_DIRECTIONS,
18134
18283
  MIN_BUFFER_PAGES,
18284
+ MIN_HASH_PIXELS,
18135
18285
  MemMeasureQuery,
18136
18286
  MemoryAnalyzer,
18137
18287
  MemoryMeasureAnalyzer,
@@ -18166,8 +18316,10 @@ export {
18166
18316
  UitestCollector,
18167
18317
  VsyncAnalyzer,
18168
18318
  aggregateUnreleased,
18319
+ analyseAnimations,
18169
18320
  analyzeHap,
18170
18321
  analyzeThreadWakeup,
18322
+ animationSeverity,
18171
18323
  buildDepGraph,
18172
18324
  buildHiprofilerConfig,
18173
18325
  buildInventory,
@@ -18177,6 +18329,7 @@ export {
18177
18329
  categorize,
18178
18330
  classifyNativePath,
18179
18331
  compareImages,
18332
+ compareRegion,
18180
18333
  compareResults,
18181
18334
  compareSceneDirs,
18182
18335
  compareScenes,
@@ -18191,6 +18344,7 @@ export {
18191
18344
  computeVsyncAnomalies,
18192
18345
  connect,
18193
18346
  createSceneLayout,
18347
+ cropRegion,
18194
18348
  decodePng,
18195
18349
  defaultAnalyzers,
18196
18350
  dhash,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohos-perf/core",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "HarmonyOS performance analysis: capability probing, nine collectors, trace ingest, typed queries, twenty analyzers with provenance and fidelity, reports and a scenario runner",
5
5
  "keywords": [
6
6
  "harmonyos",