/** * `analyzeEnergyImpact`: parses xctrace's energy-impact schema. v1.15 item D. * * The "why is my app draining battery?" investigation. iOS's Energy * Log buckets samples into idle / passive / active / high categories * and counts wakeups. Background apps that keep CPU active for too long * burn battery and get throttled by the OS. wearables / location apps / * background-fetch users are the typical audience for this analyzer. * * Distinct from analyzeTimeProfile (CPU sampling) which tells you which * functions are hot but not how that maps to power draw. The energy * schema is a different sensor: it reads from the OS power-management * subsystem directly. */ import { z } from "zod"; import type { AnalyzeTraceOptions, DataStatus, SupportStatus } from "../types.js"; export declare const analyzeEnergyImpactSchema: z.ZodObject<{ tracePath: z.ZodString; topN: z.ZodDefault; outputFormat: z.ZodOptional>; }, "strip", z.ZodTypeAny, { tracePath: string; topN: number; outputFormat?: "markdown" | "json" | "both" | "verify-fix-table" | undefined; }, { tracePath: string; outputFormat?: "markdown" | "json" | "both" | "verify-fix-table" | undefined; topN?: number | undefined; }>; export type AnalyzeEnergyImpactInput = z.infer; export type EnergyBucket = "idle" | "passive" | "active" | "high" | "unknown"; export interface EnergySample { startNs: number; startFmt?: string; /** Apple's energy bucket classification. */ bucket: EnergyBucket; /** Wakeups per second when present. */ wakeups?: number; /** Raw energy cost score when xctrace exposes one (varies by Xcode version). */ cost?: number; /** Optional sample-level label / event name. */ label?: string; } export interface AnalyzeEnergyImpactResult { ok: boolean; tracePath: string; totals: { rows: number; /** Aggregate wakeups across all samples. */ totalWakeups: number; /** Ratio of samples in `active` + `high` buckets vs total. 0 means fully idle. */ activeRatio: number; /** Per-bucket sample counts. */ bucketCounts: Record; }; /** Top N samples by energy cost desc. */ topByCost: EnergySample[]; diagnosis: string; /** @deprecated v1.14 item I. Use `supportStatus[]`. */ status: DataStatus; /** v1.14+. Unified per-area status. */ supportStatus: SupportStatus[]; } /** Normalize whatever string xctrace puts in the bucket column to our * canonical enum. v1.15. Exported for testing. * * v1.17: priority order fixed. "active" / "foreground" / "passive" / * "background" are checked BEFORE "high" so strings like "highly active" * classify as `active` (per the dominant lexical signal) instead of * `high`. Long-tail edge case from real xctrace output, but observed * enough to warrant the reorder. */ export declare function normalizeBucket(raw: string | undefined): EnergyBucket; /** Pure: turn the energy-impact XML into the analyzed result. */ export declare function analyzeEnergyImpactFromXml(xml: string, tracePath: string, topN?: number): AnalyzeEnergyImpactResult; export declare function analyzeEnergyImpact(input: AnalyzeEnergyImpactInput, options?: AnalyzeTraceOptions): Promise;