Skip to content

Commit d787bf4

Browse files
authored
Add rustdoc comments and doc build instructions (#16)
- document the crate using rustdoc comments - explain how to build docs and publish to crates.io
1 parent da36aad commit d787bf4

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,29 @@ There are some actual usages of it as well which can be also used as an example:
3333
* in [blocksense-network/noir: their tracing support for CodeTracer](https://github.com/blocksense-network/noir/tree/blocksense/tooling/tracer)
3434
* in a small toy interpreter to be released as a part of the CodeTracer repo
3535

36-
One can always directly produce the same traces from various languages. We're open for cooperation or discussion on usecases!
36+
One can always directly produce the same traces from various languages. We're open for cooperation or discussion on usecases!
37+
38+
### Building the Documentation
39+
40+
The library API docs can be built locally with:
41+
42+
```bash
43+
cargo doc --all-features --no-deps
44+
```
45+
46+
The generated HTML documentation will be placed under `target/doc`. Open
47+
`target/doc/runtime_tracing/index.html` in a browser to inspect it.
48+
49+
### Publishing to crates.io
50+
51+
After updating the version number in `Cargo.toml`, publish a new release with:
52+
53+
```bash
54+
cargo publish
55+
```
56+
57+
Documentation for released versions will be automatically hosted on
58+
[docs.rs](https://docs.rs/runtime_tracing).
3759

3860
### Legal
3961

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
// but i might be wrong
44
// also for now, allowing it to pass `cargo clippy`
55
#![allow(clippy::from_over_into)]
6+
//! Runtime tracing structures and helpers for the CodeTracer debugger.
7+
//!
8+
//! This crate provides the [`Tracer`] type for emitting trace events and a
9+
//! collection of serializable structures describing the trace format.
10+
//! The format is documented in `docs/` and the README.
611
mod tracer;
712
mod types;
813
pub use crate::tracer::{Tracer, NONE_TYPE_ID, NONE_VALUE};

src/tracer.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Helper for generating trace events from a running program or interpreter.
2+
13
use std::collections::HashMap;
24
use std::env;
35
use std::error::Error;
@@ -11,6 +13,10 @@ use crate::types::{
1113
};
1214
use crate::RValue;
1315

16+
/// State machine used to record [`TraceLowLevelEvent`]s.
17+
///
18+
/// A `Tracer` instance accumulates events and can store them on disk via the
19+
/// `store_trace_*` methods.
1420
pub struct Tracer {
1521
// trace metadata:
1622
workdir: PathBuf,
@@ -40,6 +46,7 @@ pub const NONE_VALUE: ValueRecord = ValueRecord::None { type_id: NONE_TYPE_ID };
4046
pub const TOP_LEVEL_FUNCTION_ID: FunctionId = FunctionId(0);
4147

4248
impl Tracer {
49+
/// Create a new tracer instance for the given program and arguments.
4350
pub fn new(program: &str, args: &[String]) -> Self {
4451
Tracer {
4552
workdir: env::current_dir().expect("can access the current dir"),
@@ -56,6 +63,7 @@ impl Tracer {
5663
}
5764
}
5865

66+
/// Begin tracing of a program starting at the given source location.
5967
pub fn start(&mut self, path: &Path, line: Line) {
6068
let function_id = self.ensure_function_id("<toplevel>", path, line);
6169
self.register_call(function_id, vec![]);

src/types.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Serializable record types for the trace format used by CodeTracer.
2+
//!
3+
//! All structures derive [`serde::Serialize`] and [`serde::Deserialize`].
4+
15
use std::cmp::Ord;
26
use std::ops;
37
use std::path::PathBuf;
@@ -12,6 +16,7 @@ use serde_repr::*;
1216
// afterwards in postprocessing
1317
// this assumption can change in the future
1418

19+
/// Low level building blocks that make up a recorded trace.
1520
#[derive(Debug, Clone, Serialize, Deserialize)]
1621
pub enum TraceLowLevelEvent {
1722
Step(StepRecord),
@@ -321,6 +326,7 @@ impl Into<usize> for TypeId {
321326
// use value::Value for interaction with existing frontend
322327
// TODO: convert between them or
323328
// serialize ValueRecord in a compatible way?
329+
/// Representation of a runtime value captured in a trace.
324330
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
325331
#[serde(tag = "kind")]
326332
pub enum ValueRecord {
@@ -382,6 +388,7 @@ pub enum ValueRecord {
382388
},
383389
}
384390

391+
/// Categories of types recorded in the trace.
385392
#[derive(Debug, Default, Copy, Clone, FromPrimitive, Serialize_repr, Deserialize_repr, PartialEq)]
386393
#[repr(u8)]
387394
pub enum TypeKind {
@@ -440,6 +447,7 @@ pub enum TypeKind {
440447
Slice,
441448
}
442449

450+
/// Kinds of I/O or log events that can appear in a trace.
443451
#[derive(Debug, Default, Copy, Clone, FromPrimitive, Serialize_repr, Deserialize_repr, PartialEq)]
444452
#[repr(u8)]
445453
pub enum EventLogKind {

0 commit comments

Comments
 (0)