Skip to content

deonmenezes/mobile-app-skill / skills/swiftui-expert-skill

swiftui-expert-skill

Verified

Use when writing, reviewing, or refactoring SwiftUI code for iOS or macOS, including state and `@Observable` data flow, view composition, resizable layouts, safe areas, display scale, performance, lists, environment, localization, animation, Liquid Glass, and API migration. Also use for iPhone Duo, foldable, or large-display layouts (`NavigationSplitView` on large displays, iPhone tab sidebar, two-column reflow, foldable grids, `ArrangementView`, `ReservedRegion`), hinge effects, vertical bars, `@State` initialization or synthesized-property diagnostics, `@ContentBuilder` ambiguity, `reorderable` drag/drop, custom `AsyncImage` `URLSession`, swipe actions outside List, item-bound `alert`/`confirmationDialog`, `ToolbarOverflowMenu`, `AnimatableValues`, Document APIs (`Document`/`DocumentReader`), and Instruments `.trace` capture or analysis.

FileKindSize
SKILL.mdskill md11.4 KB
agents/openai.yamlconfig228 B
assets/logo-small.pngbinary29.0 KB
assets/logo.pngbinary389.5 KB
assets/logo.svgother2.0 KB
references/accessibility-patterns.mdmarkdown5.9 KB
references/animation-advanced.mdmarkdown11.2 KB
references/animation-basics.mdmarkdown6.7 KB
references/animation-transitions.mdmarkdown7.9 KB
references/charts-accessibility.mdmarkdown6.1 KB
references/charts.mdmarkdown16.8 KB
references/document-apps.mdmarkdown11.1 KB
references/environment-patterns.mdmarkdown7.1 KB
references/focus-patterns.mdmarkdown8.7 KB
references/image-optimization.mdmarkdown10.4 KB
references/iphone-duo.mdmarkdown7.4 KB
references/latest-apis.mdmarkdown24.8 KB
references/layout-best-practices.mdmarkdown20.6 KB
references/liquid-glass.mdmarkdown12.4 KB
references/list-patterns.mdmarkdown20.5 KB
references/localization.mdmarkdown9.7 KB
references/macos-scenes.mdmarkdown9.5 KB
references/macos-views.mdmarkdown10.8 KB
references/macos-window-styling.mdmarkdown8.6 KB
references/modifier-patterns.mdmarkdown2.5 KB
references/performance-patterns.mdmarkdown11.7 KB
references/previews.mdmarkdown8.1 KB
references/scroll-patterns.mdmarkdown10.6 KB
references/sheet-navigation-patterns.mdmarkdown15.0 KB
references/soft-deprecation.mdmarkdown2.9 KB
references/state-management.mdmarkdown21.5 KB
references/styled-text-editing.mdmarkdown8.7 KB
references/text-patterns.mdmarkdown1.6 KB
references/toolbar-patterns.mdmarkdown9.9 KB
references/trace-analysis.mdmarkdown14.1 KB
references/trace-recording.mdmarkdown5.8 KB
references/view-structure.mdmarkdown28.3 KB
references/webkit-integration.mdmarkdown9.5 KB
scripts/analyze_trace.pyscript9.9 KB
scripts/instruments_parser/__init__.pyscript69 B
scripts/instruments_parser/causes.pyscript5.9 KB
scripts/instruments_parser/correlate.pyscript6.2 KB
scripts/instruments_parser/events.pyscript10.6 KB
scripts/instruments_parser/hangs.pyscript3.4 KB
scripts/instruments_parser/hitches.pyscript4.5 KB
scripts/instruments_parser/summary.pyscript9.1 KB
scripts/instruments_parser/swiftui.pyscript6.6 KB
scripts/instruments_parser/time_profiler.pyscript4.3 KB
scripts/instruments_parser/xctrace.pyscript3.5 KB
scripts/instruments_parser/xml_utils.pyscript7.4 KB
scripts/record_trace.pyscript10.6 KB

scripts/instruments_parser/time_profiler.py

View on GitHub
"""Time Profiler lane parser (schema `time-profile`).

Aggregates CPU samples by leaf symbol, keeps per-sample rows so that other
lanes can correlate by timestamp window.
"""
from __future__ import annotations

from collections import defaultdict
from pathlib import Path
from typing import Any

from . import xctrace, xml_utils

PREFERRED_SCHEMAS = ("time-profile",)
FALLBACK_SCHEMAS = ("time-sample",)  # no symbolication; used only if nothing else


def analyze(
    trace_path: Path,
    toc_schemas: frozenset[str],
    top_n: int = 10,
    window: tuple[int, int] | None = None,
    run: int = 1,
) -> dict[str, Any]:
    schema = _pick_schema(toc_schemas)
    if schema is None:
        return {
            "lane": "time-profiler",
            "available": False,
            "notes": ["Time Profiler data not present in trace."],
        }

    xml_bytes = xctrace.export_schema(trace_path, schema, run=run)
    stream = xml_utils.RowStream(xml_bytes)

    samples: list[dict] = []
    symbol_weight: dict[str, int] = defaultdict(int)
    symbol_samples: dict[str, int] = defaultdict(int)
    symbol_thread: dict[str, str] = {}
    processes: set[str] = set()
    total_weight = 0
    min_time: int | None = None
    max_time: int | None = None

    for row in stream:
        time_el = row.get("time")
        weight_el = row.get("weight")
        thread_el = row.get("thread")
        stack_el = row.get("stack")
        if stack_el is None or time_el is None or thread_el is None:
            continue

        sample_time_ns = xml_utils.int_text(stream.resolve(time_el))
        if not xml_utils.in_window(sample_time_ns, window):
            continue
        weight_ns = xml_utils.int_text(stream.resolve(weight_el)) or 0
        frames = xml_utils.extract_backtrace(stack_el, stream, max_frames=20)
        if not frames:
            continue

        thread = xml_utils.extract_thread(thread_el, stream)
        process_name = (thread.get("process") or {}).get("name")
        if process_name:
            processes.add(process_name)

        leaf = xml_utils.top_symbol(frames)
        symbol_weight[leaf] += weight_ns
        symbol_samples[leaf] += 1
        symbol_thread.setdefault(
            leaf, "main" if thread["is_main"] else thread.get("name", "")
        )
        total_weight += weight_ns

        if sample_time_ns is not None:
            min_time = sample_time_ns if min_time is None else min(min_time, sample_time_ns)
            max_time = sample_time_ns if max_time is None else max(max_time, sample_time_ns)

            samples.append({
                "time_ns": sample_time_ns,
                "weight_ns": weight_ns,
                "thread_name": thread["name"],
                "is_main": thread["is_main"],
                "process": process_name,
                "leaf_symbol": leaf,
                "frames": frames[:5],
            })

    samples.sort(key=lambda s: s["time_ns"])

    top = sorted(
        symbol_weight.items(), key=lambda kv: kv[1], reverse=True
    )[:top_n]
    top_offenders = [
        {
            "symbol": sym,
            "weight_ns": w,
            "weight_ms": round(w / 1_000_000, 2),
            "samples": symbol_samples[sym],
            "percent": round(100.0 * w / total_weight, 2) if total_weight else 0.0,
            "thread": symbol_thread.get(sym, ""),
        }
        for sym, w in top
    ]

    notes: list[str] = []
    if schema in FALLBACK_SCHEMAS:
        notes.append(
            f"Using fallback schema `{schema}`; backtraces may be unsymbolicated."
        )

    return {
        "lane": "time-profiler",
        "available": True,
        "schema_used": schema,
        "metrics": {
            "total_samples": len(samples),
            "total_weight_ns": total_weight,
            "total_weight_ms": round(total_weight / 1_000_000, 2),
            "window_start_ns": min_time,
            "window_end_ns": max_time,
            "processes": sorted(processes),
        },
        "top_offenders": top_offenders,
        "notes": notes,
        # Internal: retained for correlation. Stripped before JSON emission
        # if --slim is requested by the orchestrator.
        "_samples": samples,
    }


def _pick_schema(available: frozenset[str]) -> str | None:
    for s in PREFERRED_SCHEMAS + FALLBACK_SCHEMAS:
        if s in available:
            return s
    return None
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall