|
| 1 | +## runtime_tracing |
| 2 | + |
| 3 | +A format and helper library for [CodeTracer](https://github.com/metacraft-labs/CodeTracer.git) traces |
| 4 | + |
| 5 | +### format |
| 6 | + |
| 7 | +A CodeTracer trace for its db backend consists of record data, metadata for the recorded program and copy of the relevant source/repository files. |
| 8 | +It's self contained, so one can debug a record of a version of a program from a different commit or branch. |
| 9 | +The record data consists of a stream of objects, each of which describes a certain program event: call, step, return etc. |
| 10 | + |
| 11 | +A trace contains several files: |
| 12 | +* `trace.json` – the event data in JSON format |
| 13 | +* `trace.bin` – the same event stream encoded in a binary format (see |
| 14 | + [docs/trace_binary_spec.md](docs/trace_binary_spec.md)) |
| 15 | +* `trace_metadata.json` – metadata for the recorded program |
| 16 | +* `trace_paths.json` – a list of the recorded files |
| 17 | +* `files/` – a folder including all the source/repository files copied into the trace. |
| 18 | + |
| 19 | +The event stream can be stored either as JSON (`trace.json`) or in the |
| 20 | +binary format (`trace.bin`). Both representations correspond to the Rust |
| 21 | +types in `src/types.rs`. |
| 22 | + |
| 23 | +We plan on |
| 24 | +* defining a more precise document or a list of examples or a specification. |
| 25 | +* producing a more optimized version of the format. A binary variant is now |
| 26 | + available as `trace.bin`. |
| 27 | + |
| 28 | +A future goal of this format is to make it possible to stream traces: to be able to replay them while they're still being recorded. |
| 29 | +This is one of the reasons for the decision to maintain a single "stream" of events currently. |
| 30 | + |
| 31 | +### tracer library |
| 32 | + |
| 33 | +We also define a Rust tracer library in `src/tracer.rs` which can be used as a helper to instrument Rust-based language interpreters and vm-s. |
| 34 | +It can make it easier to migrate to newer versions of the format, hiding many details behind its helpers. |
| 35 | +There are a few examples and tests of its usage in `src/lib.rs`. |
| 36 | + |
| 37 | +There are some actual usages of it as well which can be also used as an example: |
| 38 | +* in [blocksense-network/noir: their tracing support for CodeTracer](https://github.com/blocksense-network/noir/tree/blocksense/tooling/tracer) |
| 39 | +* in a small toy interpreter to be released as a part of the CodeTracer repo |
| 40 | + |
| 41 | +One can always directly produce the same traces from various languages. We're open for cooperation or discussion on usecases! |
| 42 | + |
| 43 | +### Building the Documentation |
| 44 | + |
| 45 | +The library API docs can be built locally with: |
| 46 | + |
| 47 | +```bash |
| 48 | +cargo doc --all-features --no-deps |
| 49 | +``` |
| 50 | + |
| 51 | +The generated HTML documentation will be placed under `target/doc`. Open |
| 52 | +`target/doc/runtime_tracing/index.html` in a browser to inspect it. |
| 53 | + |
| 54 | +### Publishing to crates.io |
| 55 | + |
| 56 | +After updating the version number in `Cargo.toml`, publish a new release with: |
| 57 | + |
| 58 | +```bash |
| 59 | +cargo publish |
| 60 | +``` |
| 61 | + |
| 62 | +Documentation for released versions will be automatically hosted on |
| 63 | +[docs.rs](https://docs.rs/runtime_tracing). |
| 64 | + |
| 65 | +### Legal |
| 66 | + |
| 67 | +Authored and maintained by Metacraft Labs, Ltd |
| 68 | + |
| 69 | +LICENSE: MIT |
0 commit comments