Skip to content

Commit 6e88acc

Browse files
authored
feat: store traces in memory for deeper inspection (store_traces_as) (#14386)
This PR is a follow-up to #14352 (introducing `postprocess_traces`). It provides a new command `store_traces_as myTraces in cmd` that runs the command `cmd` and stores its traces in-memory under the name `name`. The stored traces can be transformed and viewed using `#postprocess_traces tracePostprocessor myTraces`.
1 parent 4dbad69 commit 6e88acc

7 files changed

Lines changed: 627 additions & 277 deletions

File tree

src/Lean/PostprocessTraces.lean

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,35 @@ module
77

88
prelude
99
public import Lean.PostprocessTraces.Basic
10+
public import Lean.PostprocessTraces.PostprocessTracesCommand
11+
public import Lean.PostprocessTraces.StoredTraces
12+
public import Lean.PostprocessTraces.Postprocessors
13+
14+
/-!
15+
# Experimental: Trace Postprocessors
16+
17+
Trace messages of complex elaboration tasks can be large, and finding the relevant part in
18+
the editor requires a lot of clicking and searching. This module provides trace postprocessors:
19+
functions that transform the trace of a command before it is reported, e.g. by filtering out
20+
irrelevant subtrees, hoisting the interesting ones, or pre-expanding the paths to matches.
21+
22+
A trace postprocessor (`Lean.PostprocessTraces.TracePostprocessor`) receives the array of trace
23+
trees of one trace message and returns the transformed trees. The `Lean.PostprocessTraces` namespace
24+
provides a small set of operations (`filterSubtrees`, `hoist`, `exposeSubtrees`, `countNodes`,
25+
`selfTime`) that compose left-to-right with `>=>`. The selecting operations take a pattern
26+
(`Lean.PostprocessTraces.TracePattern`), a predicate on trace subtrees; built-in patterns select by
27+
trace class (`ofClass`), text (`containsString`), result (`succeeded`, `failed`, `errored`,
28+
`unsuccessful`), and time (`minTimeMs`, `minSelfTimeMs`). Users can define their own postprocessors
29+
and patterns as ordinary functions.
30+
31+
Entry points:
32+
- `postprocess_traces post in cmd` (see `Lean.PostprocessTraces.Command`) transforms the trace
33+
messages produced by `cmd` with `post`.
34+
- `store_traces_as t in cmd` (see `Lean.PostprocessTraces.StoredTraces`) stores the trace messages of
35+
`cmd` under the name `t`, so that slow commands do not have to be re-run while iterating on a
36+
postprocessor.
37+
38+
Traces are stored as `MessageData` (see `MessageData.trace`); `TraceTree` is a structured view of
39+
such messages that takes care of the context wrappers (`MessageData.withContext` etc.) around
40+
trace nodes.
41+
-/

0 commit comments

Comments
 (0)