SlicerCode conceptsIntermediate9 min read

Runtime Analysis & Dynamic Tracing

Static analysis reads your source; dynamic tracing watches it run. Runtime analysis attaches a debugger to record the concrete arguments, object state, best-effort returns and exceptions your code actually produces — turning assumptions into evidence you can test against, validate specs with, and use to sharpen a flow graph. This guide covers what dynamic tracing is, how it works over the Debug Adapter Protocol, what to capture, how to keep captures private, and how SlicerCode fuses runtime analysis with static flow analysis.

Runtime Analysis vs Static Analysis: Where Dynamic Tracing Fits

Static analysis reads source code without executing it. Parsers, type checkers, linters, and call-graph builders work purely from what is written — they are fast, deterministic, and cover every path in the file, but they only ever see the *shape* of the program, not its behavior. Runtime analysis (also called dynamic analysis or dynamic tracing) is the complement: it observes a program while it executes and records the concrete values, object states, and paths actually taken on a given run.

The distinction matters because the two techniques fail in opposite directions. Static analysis *over-approximates*: behind an interface it must assume every possible implementation could be called. Dynamic tracing *under-approximates*: it only knows the paths your particular run exercised. Neither is a superset of the other, which is exactly why the strongest tooling fuses them — a static skeleton for completeness, runtime evidence for precision.

How SlicerCode does it: on workspace open it builds a static call-, data- and object-flow graph across 6+ languages with tree-sitter (see Code Flow & Graph Analysis), then attaches the debugger to refine that graph with what actually ran. You get the coverage of static analysis and the truth of dynamic tracing in one map. Explore both on the features page.

  • Static analysis: complete over all code paths, but approximate — it reasons about what *could* happen.
  • Dynamic tracing: precise on concrete values, but partial — it only sees what *did* happen on a run.
  • Fused, they cover each other's blind spots: a static skeleton refined by observed execution.
Key takeaway — Static analysis tells you what your code could do; dynamic tracing tells you what it actually did. You want both.

Why Observed Behavior Beats Assumptions

Types and signatures describe intent, not reality. A parameter typed Order might arrive with null fields, an empty line-item list, an unexpected enum, or a subclass the author never anticipated. Feature flags, config, and environment variables decide which branch actually runs. Responses from databases, queues, and HTTP services shape the data flowing through your call stack. None of that is knowable from source alone — you have to watch the program run.

This is also why hand-written fixtures are risky. When a developer guesses that a function returns { status: 'ok', total: 42 }, the test asserts on the guess, not on behavior; it passes and proves nothing. Values captured from a real execution are different — they are *golden* ground truth, the exact shapes and numbers the code produced, so an assertion built on them fails only when behavior genuinely changes.

The principle is simple: prefer evidence over inference. Every place where you would otherwise assume a value — a fixture, a mock's return, a requirement's expected output — is a place where an observed value is strictly more trustworthy.

Key takeaway — Signatures describe intent; runtime values describe behavior. Assertions grounded in observed values catch real regressions instead of encoding a guess.

How Dynamic Tracing Works: The Debug Adapter Protocol

Modern dynamic tracing usually rides on the Debug Adapter Protocol (DAP) — the same standard your editor uses to talk to a language's debug backend (debugpy for Python, the JDWP-backed adapter for Java, the Node inspector for JS/TS, Delve for Go, and so on). DAP gives a uniform, language-agnostic interface: set breakpoints, and on each stop read the call stack, scopes, and variables; step; or evaluate an expression in the paused frame.

To trace with breakpoints, you arm them at the points you care about — typically function entries (and, where available, exits) — and on every stop you read that frame's arguments and locals, snapshot them, and continue. Return values are the subtle part: many runtimes do not expose a clean return at function entry, so a tracer infers a best-effort return from exit frames or the locals in scope rather than claiming certainty it doesn't have.

How SlicerCode does it: it attaches to the VS Code debugger, arms breakpoints on every function in the flow you choose, and records each call's arguments, object state, best-effort return and thrown exceptions (plus timing and heap deltas). Crucially, it only resumes stops on *its own* breakpoints, so it never hijacks a debugging session you started. See the runtime analysis feature and the runtime docs.

  • DAP = a standard editor-to-debugger protocol, so one tracing approach works across ~6 languages.
  • Breakpoint-based tracing reads frames on each stop: arguments, locals, object state.
  • Returns are best-effort — inferred from exit frames/locals, not asserted as certain.

What a Trace Captures: Arguments, Object State, Returns and Exceptions

A useful trace is more than a log line. Per invocation it records the concrete arguments, the object state (and how it mutates as the call proceeds), a best-effort return, and any exception thrown — the four facts you need to reconstruct what a function actually did with real inputs. Timing and heap deltas ride along as secondary signals for spotting slow or allocation-heavy steps.

Object *shape* often matters as much as object *value*. Which fields were present, how deep the nesting went, how large a collection was — these are the details that make a golden-value assertion meaningful and that a hand-written fixture almost always gets subtly wrong. Snapshotting complex state at each step gives you assertions you could never have written by hand.

Finally, a capture is only valuable if it is stable. Captures are persisted locally and replayable across runs, so a generated assertion reproduces deterministically instead of flaking on values that were only true once.

  • Per call: arguments, object state, best-effort return, exceptions — plus timing and heap deltas.
  • Capture object *shape* (fields, nesting, collection sizes), not just scalar values.
  • Persisted locally and replayable so generated assertions stay deterministic.

Refining Flow Graphs With What Actually Ran

A static call graph honestly can't tell you which implementation runs behind an interface. Dependency injection, dynamic dispatch, plugin registries, and polymorphism all produce ambiguous edges — one call site with several plausible targets. A static builder labels each edge resolved, ambiguous, unresolved, or cycle, but it cannot collapse the ambiguity on its own.

A runtime capture resolves it. By observing which concrete method actually executed, dynamic tracing collapses ambiguous and polymorphic edges to the real target, annotates edges with hit counts, and highlights the executed path through the graph. External systems on that path — Kafka, databases, HTTP services, queues, caches — are detected statically and then confirmed by what the run touched.

How SlicerCode does it: it starts from the static call/data/object flow and lets a runtime capture refine it, so polymorphic edges point at what really ran. The result opens as an interactive graph in its own editor tab — or mirrors to a browser via a deep link — and any node explains itself on click. More in Code Flow & Graph Analysis and on the flow feature page.

Key takeaway — Static graphs mark polymorphic edges as ambiguous; a runtime trace collapses them to the implementation that actually ran, with hit counts and the executed path highlighted.

Seeding Tests From Runtime Captures

The highest-leverage use of a trace is generating tests from it. Instead of fabricating inputs and guessing outputs, you seed a test with the exact arguments a function received and assert against the exact value it returned — real fixtures and real golden assertions, idiomatic to the stack you're in (JUnit/AssertJ, pytest, Jest/Vitest, Go table tests, RSpec, and more).

Generation should be verified, not just written. A deterministic, self-repairing generator compiles the test, runs it, and repairs assertions, imports, and mocks in a loop until the suite is green — so a red test never lands on your desk. Note that the coverage this produces is line coverage (via JaCoCo, coverage.py, c8, or go cover) plus executed-flow coverage, not branch coverage.

How SlicerCode does it: captures feed directly into test generation, so assertions use observed returns rather than invented ones, and every suite is compiled, run, and repaired until it passes. See AI Test Generation and the runtime feature.

  • Seed inputs and golden outputs from real captures — no fabricated fixtures.
  • Deterministic and self-repairing: compile → run → repair until green.
  • Coverage measured as line coverage (JaCoCo/coverage.py/c8/go cover) + executed-flow — not branch.

Grounding PRD Validation in Runtime Values

Requirements checks are only as honest as the evidence behind them. Reading source and comments tells you what the code *claims* to do; runtime values tell you what it *does*. Grounding a spec check in observed behavior closes that gap — you validate against the numbers the code actually produced, not against a docstring that drifted from reality.

How SlicerCode does it: PRD validation scores a flow against its requirements across four dimensions — the code, the executed flow, the changes still to make, and your existing tests — and re-computes its calculations from observed runtime values rather than trusting the source at face value. It returns a scored, readable report with a match percentage, what's covered, and exactly what's missing. See PRD Validation and the PRD feature.

Key takeaway — A PRD check grounded in runtime values scores what the code actually produced, across code, executed flow, remaining changes, and tests — not what a comment promises.

Redaction and Privacy: Keeping Captured Values Safe

Real values are the point of dynamic tracing — and also its risk. A capture of a live request can contain API keys, tokens, passwords, and personal data. Any responsible runtime analysis must redact secrets and PII before those values are persisted, generated into tests, or sent anywhere, and it should keep captures local by default.

There is also a trust boundary to respect: tracing *executes your code*. That is not a read-only operation, so it should be opt-in and gated. In SlicerCode, runtime capture is off by default (slicercode.allowRuntimeCapture), the tool that runs code under the debugger prompts on each call, and captured values are redacted before anything leaves the IDE and persisted locally.

Practically: trace against non-production or synthetic data where you can, and skim the generated fixtures before committing them — redaction is a safety net, not a license to capture live customer records.

  • Secrets and PII are redacted before captures are persisted or leave the IDE.
  • Capture is opt-in and gated (executes your code); each run still prompts.
  • Best practice: trace non-prod/synthetic data and review generated fixtures.

A Practical Dynamic Tracing Workflow

Putting it together, a typical loop looks like this: enable capture (slicercode.allowRuntimeCapture), pick the flow or scope you want to trace, then run your app under the debugger — or trigger the detected route directly from the in-panel request tool, which appends the route to your app's slicercode.baseUrl. Stop the capture, and the recorded values are ready to use.

From one capture you can now do three high-value things without leaving the editor: generate a runtime-seeded test with real assertions, validate a PRD against the values the flow actually produced, and read executed-flow plus line coverage lit up on the graph. Each reuses the same captured evidence, so the picture stays consistent.

Runtime analysis runs in VS Code today; IntelliJ and a CLINK are on the way (see the roadmap). To try it, grab the extension from the download page and follow the runtime docs.

  • Enable capture → pick a scope → run under the debugger or trigger a route via baseUrl → stop.
  • One capture powers three outputs: runtime-seeded tests, PRD validation, and coverage.
  • Available in VS Code now; IntelliJ + CLI coming soon.

Frequently asked questions

What is the difference between static and dynamic analysis?

Static analysis reads source code without running it — parsers, type checkers, and call-graph builders — so it sees every code path but only approximates behavior. Dynamic analysis (runtime tracing) executes the program and records the concrete values and paths actually taken, so it is precise but only covers the runs you exercise. They are complementary, not interchangeable.

How does runtime analysis capture real values from running code?

It attaches to the debugger over the Debug Adapter Protocol (DAP), arms breakpoints at the functions of interest, and on each stop reads that frame's arguments, locals, and object state, inferring a best-effort return from exit frames. SlicerCode does this against the VS Code debugger and only resumes its own breakpoints so it won't disrupt a debugging session you started.

Does dynamic tracing expose secrets or PII?

It can, because it records real values — which is why redaction is essential. SlicerCode redacts secrets and PII before captures are persisted or leave the IDE, keeps captures local, and gates the feature behind an opt-in setting (slicercode.allowRuntimeCapture) that prompts on each run because tracing executes your code.

Can you generate tests from runtime data?

Yes. Captured arguments become fixtures and captured returns become golden assertions, so tests reflect real behavior instead of guessed values. SlicerCode seeds tests from captures across 6+ languages and compiles, runs, and repairs each one until it passes.

Does dynamic analysis replace static analysis?

No — they solve opposite problems. Static analysis is complete but approximate; dynamic tracing is precise but only covers the paths a run exercised. The best results come from fusing them: a static flow graph refined by observed execution, which is exactly how SlicerCode resolves polymorphic edges to what actually ran.

Which languages does SlicerCode's runtime analysis support?

Runtime capture and the surrounding flow analysis work across 6+ languages — Java, Kotlin, Python, JavaScript/TypeScript, Go, and Ruby — using each ecosystem's debug adapter. It runs in VS Code today, with IntelliJ and a CLI coming soon.

See it in your codebase

SlicerCode brings the agent, flow graphs, runtime capture, PRD validation and test generation into VS Code.