Skip to main content
Glama
carloshpdoc

memorydetective

Analyze cold/warm launch breakdown

analyzeAppLaunch

Parse app launch trace files to extract total launch time, launch type, per-phase breakdown, and identify the slowest phase.

Instructions

[mg.trace] Parse the app-launch schema from a .trace recorded with the App Launch Instruments template. Returns total launch time, launch type (cold/warm), per-phase breakdown (process-creation, dyld-init, ObjC-init, AppDelegate, first-frame), and the slowest phase.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tracePathYesAbsolute path to a `.trace` bundle recorded with the App Launch template (`xcrun xctrace record --template 'App Launch' --launch <bundleId>`).

Implementation Reference

  • Main handler function that resolves the trace path, runs `xcrun xctrace export` to extract the app-launch table, and delegates to analyzeAppLaunchFromXml for parsing.
    export async function analyzeAppLaunch(
      input: AnalyzeAppLaunchInput,
    ): Promise<AnalyzeAppLaunchResult> {
      const tracePath = resolvePath(input.tracePath);
      if (!existsSync(tracePath)) {
        throw new Error(`Trace bundle not found: ${tracePath}`);
      }
      const result = await runCommand(
        "xcrun",
        [
          "xctrace",
          "export",
          "--input",
          tracePath,
          "--xpath",
          '/trace-toc/run/data/table[@schema="app-launch"]',
        ],
        { timeoutMs: 5 * 60_000 },
      );
      if (result.code !== 0) {
        throw new Error(
          `xctrace export failed (code ${result.code}): ${result.stderr || result.stdout}`,
        );
      }
      return analyzeAppLaunchFromXml(result.stdout, tracePath);
    }
  • Pure function that parses xctrace XML, extracts total duration, launch type (cold/warm/unknown), per-phase breakdown sorted by canonical order, identifies the slowest phase, and builds a diagnosis string.
    export function analyzeAppLaunchFromXml(
      xml: string,
      tracePath: string,
    ): AnalyzeAppLaunchResult {
      const tables = parseXctraceXml(xml);
      const table = tables.find((t) => t.schema === "app-launch");
      if (!table) {
        return {
          ok: true,
          tracePath,
          totalLaunchMs: 0,
          launchType: "unknown",
          phases: [],
          diagnosis: "No app-launch table found in the trace.",
        };
      }
    
      // The app-launch schema can include rows describing per-phase durations and
      // a summary row with the total. xctrace varies the field shape across iOS
      // versions, so we cope with whichever fields turn up.
      const rawPhases: Array<{ phase: string; label: string; durationNs: number }> = [];
      let totalNs = 0;
      let launchType: AnalyzeAppLaunchResult["launchType"] = "unknown";
    
      for (const row of table.rows) {
        const phase =
          asFormatted(row.phase) ??
          asFormatted(row["phase-name"]) ??
          asFormatted(row.category) ??
          "unknown";
        const label =
          asFormatted(row["display-label"]) ??
          asFormatted(row.label) ??
          phase;
        const dn =
          asNumber(row.duration) ??
          asNumber(row["phase-duration"]) ??
          0;
        if (phase === "total" || phase === "launch-total") {
          totalNs = dn;
          const t = asFormatted(row["launch-type"]);
          if (t === "cold" || t === "warm") launchType = t;
          continue;
        }
        if (dn === 0) continue;
        rawPhases.push({ phase, label, durationNs: dn });
      }
    
      // If no explicit total row, sum the phases.
      if (totalNs === 0) {
        totalNs = rawPhases.reduce((sum, p) => sum + p.durationNs, 0);
      }
    
      const totalMs = totalNs / 1_000_000;
    
      const phases: PhaseEntry[] = rawPhases
        .map((p) => ({
          phase: p.phase,
          label: p.label,
          durationMs: p.durationNs / 1_000_000,
          percentOfTotal: totalNs > 0 ? (p.durationNs / totalNs) * 100 : 0,
        }))
        .sort((a, b) => phaseOrder(a.phase) - phaseOrder(b.phase));
    
      const slowestPhase = phases.length === 0
        ? undefined
        : [...phases].sort((a, b) => b.durationMs - a.durationMs)[0];
    
      const diagnosis = buildDiagnosis(totalMs, launchType, slowestPhase);
    
      return {
        ok: true,
        tracePath,
        totalLaunchMs: totalMs,
        launchType,
        phases,
        slowestPhase,
        diagnosis,
      };
    }
  • Zod schema for the tool input: expects a single required `tracePath` (string, absolute path to a .trace bundle).
    export const analyzeAppLaunchSchema = z.object({
      tracePath: z
        .string()
        .min(1)
        .describe(
          "Absolute path to a `.trace` bundle recorded with the App Launch template (`xcrun xctrace record --template 'App Launch' --launch <bundleId>`).",
        ),
    });
  • TypeScript interface for the output result: ok, tracePath, totalLaunchMs, launchType (cold/warm/unknown), phases (PhaseEntry[]), slowestPhase, and diagnosis.
    export interface AnalyzeAppLaunchResult {
      ok: boolean;
      tracePath: string;
      /** Total app launch time as reported by xctrace. */
      totalLaunchMs: number;
      /** "cold" or "warm" launch when discriminable; otherwise "unknown". */
      launchType: "cold" | "warm" | "unknown";
      /** Per-phase breakdown sorted by Apple's canonical order. */
      phases: PhaseEntry[];
      /** Phase that took the largest share of launch time. */
      slowestPhase?: PhaseEntry;
      diagnosis: string;
    }
  • src/index.ts:341-353 (registration)
    MCP server registration: registers 'analyzeAppLaunch' tool with title, description, inputSchema, and a handler that calls analyzeAppLaunch(input) and stringifies the result.
    server.registerTool(
      "analyzeAppLaunch",
      {
        title: "Analyze cold/warm launch breakdown",
        description:
          "[mg.trace] Parse the `app-launch` schema from a `.trace` recorded with the App Launch Instruments template. Returns total launch time, launch type (cold/warm), per-phase breakdown (process-creation, dyld-init, ObjC-init, AppDelegate, first-frame), and the slowest phase.",
        inputSchema: analyzeAppLaunchSchema.shape,
      },
      async (input) => {
        const result = await analyzeAppLaunch(input);
        return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
      },
    );
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses the input requirement (a .trace bundle recorded with the App Launch template) and the output structure (total time, type, phases). It is a read-only parse, and the description adequately covers behavior beyond the schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences: the first defines the action and constraint, the second lists return values. No extra words, front-loaded, and efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has one parameter, no output schema, and no annotations, the description completely covers what the tool does, its input constraints, and its output. No additional information is necessary for correct invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% for the single parameter, but the description adds the constraint that the trace must be recorded with the 'App Launch' template and provides an example command. This adds meaning beyond the schema description, earning a score above the baseline of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description explicitly states it parses the app-launch schema from a .trace file recorded with the App Launch template, and enumerates the returned data (total launch time, launch type, per-phase breakdown). This clearly distinguishes it from sibling tools like analyzeAllocations or analyzeTimeProfile.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for app launch trace analysis but provides no explicit guidance on when not to use or alternatives. The sibling tools are diverse enough that context is clear, but the lack of explicit 'when to use' or 'when to avoid' prevents a higher score.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/carloshpdoc/memorydetective'

If you have feedback or need assistance with the MCP directory API, please join our Discord server