# Runtime evidence

Profiles, benchmark results, test timings and query counts from real runs, joined to the indexed functions so measured costs confirm, order and add to the static performance causes.

**Which of these performance causes actually costs time when the code
runs?** Static analysis finds shapes that waste work. Runtime evidence adds
what a real run showed: a CPU profile, benchmark results, test timings or
per-test query counts, each joined to the indexed function it measured, at
the commit it measured.

- **What it is:** facts about your own functions, from runs you or your agent
  already make. Each row names one indexed function at one commit.
- **What it is not:** a profiler or a benchmark runner. Repowise never runs
  your code to collect evidence.
- **What it never guesses:** an entry that does not join exactly is skipped
  and counted by reason, and a value nobody measured is unknown, never zero.

## The loop

```bash
repowise evidence setup --format json      # 1. what to run here, per build unit
# 2. run the steps in next_call, each in its directory, exactly as printed
repowise evidence add <file> --workload "<name>" --class <class> --commit <sha>   # 3. ingest
repowise evidence status                   # 4. what is stored and how fresh it is
```

`setup` reads each build unit's stack and prints a profiler command that
needs no elevated privileges, the path the profile lands at and the exact
ingest line. Every flag is on [`repowise evidence`](https://docs.repowise.dev/cli/evidence).
`setup --write` adds a CI file that collects coverage and JUnit test results
on every pull request and default-branch push.

## What it reads

| Stack | Profiles | Benchmarks | Test timings |
|---|---|---|---|
| Python | pyinstrument and py-spy (Speedscope JSON, collapsed stacks) | pytest-benchmark JSON | pytest `--junitxml` |
| Go | `go test -cpuprofile` and any pprof CPU profile | `go test -bench -benchmem` output | JUnit XML |
| JavaScript | `node --cpu-prof` (`.cpuprofile`) |  | Vitest, Jest with `jest-junit` |
| Java and Kotlin |  |  | Maven Surefire and Gradle report directories |
| Any command |  | hyperfine JSON | JUnit XML |

Profile JavaScript as it runs from its own sources: positions in compiled
TypeScript or a bundle point at the generated file, not the code you wrote.

Query counts come as a `repowise-evidence-v1` document, the open format
every reader shares, which any tool can write.

## Workload classes

The class says what produced the numbers, so a reader knows how far they
reach.

| Class | The run | What its numbers stand for |
|---|---|---|
| `entry_point` | A real command or a request replay, profiled | Where time goes on that path |
| `load_test` | A load test, profiled | Where time goes under that load |
| `benchmark` | A benchmark run | One series per benchmark |
| `unit_test` | The test suite, profiled or timed | Where time goes while tests run; test-shaped, not production-shaped |

`setup` asks for an entry point first, then a benchmark, then the test
suite, so the first profile is the one closest to real use.

## How it changes the performance queue

With evidence stored, the [performance queue](https://docs.repowise.dev/intelligence/code-health#performance-static-performance-risk)
reads it on every index and update:

- **Confirmed causes lead.** A cause is `confirmed` when its query counts
  grow with the number of items, or when a benchmark, entry point, load test
  or production workload measured its loop owner above the lead bar. The
  queue orders confirmed causes first, then causes a leading workload
  measured, then the rest in their static order.
- **Measured beats guessed.** When a leading run ranks a cause's loop owner
  among its costliest functions, the cause stays in the queue even where the
  static cold-path guess would have set it aside. A unit-test run never does
  this.
- **Query counts confirm or contradict.** For a database cause, `grows`
  confirms it, `flat` (the same statement count over different numbers of
  items) is counter-evidence, and `ran` settles nothing.
- **Hot code with no static cause becomes work.** A function a leading run
  measured above the bar, with no cause inside it, joins the queue as a
  measured hotspot.
- **Every row says what the evidence showed.** `confirmed`, `measured` (with
  the workload), `counter_evidence`, `ran`, or `not_exercised` with the
  workloads that ran and never reached it. Nothing is hidden.

With no evidence stored, the order is the static one and rows carry no mark.

## Where you see it

- **Dashboard:** Code Health's Performance tab shows the measured
  workload, where its time went, the production functions it ranked by self
  time with their share, interval, callers, owner and tests, and an agent
  prompt per row. Unit-test runs sit apart under Measured in tests, and every
  stored run is listed under Runs. A repository with causes and no evidence
  gets one connect row.
- **CLI:** `repowise evidence status`, `repowise evidence tests` (the
  slowest tests and test time per production file), and freshness rows in
  `status`, `health` and `doctor`.
- **MCP:** `get_health(include=["performance"], only=["performance_measured"])`
  lists what each workload's newest run ranked. With nothing stored it says
  `no_runtime_data` and names `repowise evidence setup`.
- **Before and after a change:** [`repowise perf measure`](https://docs.repowise.dev/cli/evidence#repowise-perf-measure)
  compares a command's wall time, and [`repowise perf check`](https://docs.repowise.dev/cli/evidence#repowise-perf-check)
  fails when a Go benchmark allocates more per operation than its baseline.

## Freshness

Evidence from a commit other than HEAD is stored with its commit and reads
as stale; it is never re-mapped onto moved code. The same file added again
against the same index restamps the stored run, and after `repowise update`
it joins afresh. Caps on file size, functions per profile and runs kept are
in the [`evidence:` block](https://docs.repowise.dev/installation/configuration#the-evidence-block).
