Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
67b3707
feat(separate_trace_types_crate): Types moved to a separate crate: co…
nickysn Oct 2, 2025
cba45cc
chore: formatting
nickysn Oct 7, 2025
4c9bb54
feat(separate_trace_types_crate): Added creates to workspace: codetra…
nickysn Oct 7, 2025
701ad0e
feat(separate_trace_types_crate): Added NONE_TYPE_ID, NONE_VALUE and …
nickysn Oct 7, 2025
1d57cb9
feat(separate_trace_types_crate): Added trait AbstractTraceWriter to …
nickysn Oct 7, 2025
b855e96
feat(separate_trace_types_crate): Added trait TraceWriter to codetrac…
nickysn Oct 7, 2025
e1a73a2
feat(separate_trace_types_crate): Added crate codetracer_trace_format…
nickysn Oct 7, 2025
a5de208
feat(separate_trace_types_crate): Added non_streaming_trace_writer to…
nickysn Oct 7, 2025
d3c4523
feat(separate_trace_types_crate): Added cbor_zstd_writer to codetrace…
nickysn Oct 7, 2025
4b6d831
feat(separate_trace_types_crate): Added create_trace_writer function …
nickysn Oct 7, 2025
ccf9c6a
feat(separate_trace_types_crate): Added trace reader implementations …
nickysn Oct 7, 2025
d2cf976
feat(separate_trace_types_crate): Move duplicated definition of HEADE…
nickysn Oct 7, 2025
bc1e0e5
feat(separate_trace_types_crate): Support wasm32-wasip1 target in cod…
nickysn Oct 7, 2025
876087f
feat(separate_trace_types_crate): Added function create_trace_reader …
nickysn Oct 7, 2025
1af6865
feat(separate_trace_types_crate): Updated runtime_tracing_cli to use …
nickysn Oct 7, 2025
7285ba1
feat(separate_trace_types_crate): Remove all the code from the runtim…
nickysn Oct 7, 2025
8af6f03
feat(separate_trace_types_crate): Moved test test_equality_of_value_r…
nickysn Oct 7, 2025
05cdfac
feat(separate_trace_types_crate): Moved test test_simple_trace to cod…
nickysn Oct 7, 2025
63bb021
feat(separate_trace_types_crate): Moved tests test_binary_roundtrip_v…
nickysn Oct 7, 2025
6ba31be
feat(separate_trace_types_crate): runtime_tracing_cli renamed codetra…
nickysn Oct 7, 2025
47924aa
feat(separate_trace_types_crate): Added description, copyright, etc t…
nickysn Oct 7, 2025
2448c6b
feat(separate_trace_types_crate): Removed the runtime_tracing crate
nickysn Oct 7, 2025
7f6f07d
feat(separate_trace_types_crate): Bump version and required Rust edit…
nickysn Oct 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
[workspace]
resolver = "2"
members = ["runtime_tracing", "runtime_tracing_cli", "trace_formatter"]
members = [
"codetracer_trace_types",
"codetracer_trace_format_capnp",
"codetracer_trace_format_cbor_zstd",
"codetracer_trace_reader",
"codetracer_trace_writer",
"codetracer_trace_util",
"trace_formatter",
]

[workspace.dependencies]
runtime_tracing = { path = "runtime_tracing/" }
trace_formatter = { path = "trace_formatter/"}
codetracer_trace_types = { path = "codetracer_trace_types" }
codetracer_trace_format_capnp = { path = "codetracer_trace_format_capnp" }
codetracer_trace_format_cbor_zstd = { path = "codetracer_trace_format_cbor_zstd" }
codetracer_trace_reader = { path = "codetracer_trace_reader" }
codetracer_trace_writer = { path = "codetracer_trace_writer" }
16 changes: 16 additions & 0 deletions codetracer_trace_format_capnp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "codetracer_trace_format_capnp"
version = "0.16.0"
edition = "2024"
authors = ["Metacraft Labs Ltd"]
description = "A library containing some helpers, used internally in the reading and writing of the CodeTracer db trace format"
repository = "https://github.com/metacraft-labs/runtime_tracing"
license = "MIT"
keywords = ["debugging", "development-tools"]

[dependencies]
codetracer_trace_types.workspace = true
capnp = "0.21.1"

[build-dependencies]
capnpc = "0.21.0"
File renamed without changes.

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions codetracer_trace_format_capnp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod capnptrace;

pub mod trace_capnp {
include!(concat!(env!("OUT_DIR"), "/src/trace_capnp.rs"));
}
9 changes: 9 additions & 0 deletions codetracer_trace_format_cbor_zstd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "codetracer_trace_format_cbor_zstd"
version = "0.16.0"
edition = "2024"
authors = ["Metacraft Labs Ltd"]
description = "A library containing some helpers, used internally in the reading and writing of the CodeTracer db trace format"
repository = "https://github.com/metacraft-labs/runtime_tracing"
license = "MIT"
keywords = ["debugging", "development-tools"]
7 changes: 7 additions & 0 deletions codetracer_trace_format_cbor_zstd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// The next 3 bytes are reserved/version info.
/// The header is 8 bytes in size, ensuring 64-bit alignment for the rest of the file.
pub const HEADERV1: &[u8] = &[
0xC0, 0xDE, 0x72, 0xAC, 0xE2, // The first 5 bytes identify the file as a CodeTracer file (hex l33tsp33k - C0DE72ACE2 for "CodeTracer").
0x01, // Indicates version 1 of the file format
0x00, 0x00,
]; // Reserved, must be zero in this version.
23 changes: 23 additions & 0 deletions codetracer_trace_reader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "codetracer_trace_reader"
version = "0.16.0"
edition = "2024"
authors = ["Metacraft Labs Ltd"]
description = "A library for reading the CodeTracer db trace format"
repository = "https://github.com/metacraft-labs/runtime_tracing"
license = "MIT"
keywords = ["debugging", "development-tools"]

[dependencies]
codetracer_trace_types.workspace = true
codetracer_trace_format_capnp.workspace = true
codetracer_trace_format_cbor_zstd.workspace = true
fscommon = "0.1.1"
serde_json = "1.0"
cbor4ii = { version = "1.0.0", features = ["serde1", "use_std"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
zeekstd = "0.6.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
ruzstd = "0.8.1"
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::io::{self, BufRead, BufReader, Read, Seek, Write};

use codetracer_trace_format_cbor_zstd::HEADERV1;
use fscommon::StreamSlice;

use zeekstd::Decoder;

use crate::{TraceLowLevelEvent, cbor_zstd_writer::HEADERV1};
use codetracer_trace_types::TraceLowLevelEvent;

fn is_at_eof<R: BufRead>(reader: &mut R) -> io::Result<bool> {
let buffer = reader.fill_buf()?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use fscommon::StreamSlice;

use ruzstd::decoding::StreamingDecoder;

use crate::{TraceLowLevelEvent, cbor_zstd_writer::HEADERV1};
use codetracer_trace_format_cbor_zstd::HEADERV1;
use codetracer_trace_types::TraceLowLevelEvent;

fn is_at_eof<R: BufRead>(reader: &mut R) -> io::Result<bool> {
let buffer = reader.fill_buf()?;
Expand Down
22 changes: 22 additions & 0 deletions codetracer_trace_reader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
mod trace_readers;

#[cfg(target_arch = "wasm32")]
#[path = "./cbor_zstd_reader_wasm.rs"]
mod cbor_zstd_reader;

#[cfg(not(target_arch = "wasm32"))]
mod cbor_zstd_reader;

#[derive(Debug, Clone, Copy)]
pub enum TraceEventsFileFormat {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a problem that we define this enum twice: if we import both libraries somewhere ( i assume there is not a good central place to put it into)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to have separate enums for the reader and the writer. The fact that the enum was shared before lead to hacks, such as specifying BinaryV0 and BinaryV1 separately, which makes sense for the writer (which can write both versions of the format), but not for the reader (which detects the binary format version from the file header, and handles BinaryV0 and BinaryV1 the same). The question is whether they should have the same name (in different modules), or different. Also, I still haven't unified BinaryV0 and BinaryV1 for the reader, but it can be done, as soon as this PR is merged. And it will not break the writer API, which is one of the goals of this PR - being able to update the reader API, without changing the writer API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but if they are different at some points, then we would need to be able to easily reasonably map the one enum to the other one: I assume that would be easy for us as maintainers of the libraries, and for the users , probably the documentation would clarify any questions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll think of some way to map them to each other, or at least, map them to some structure of strings like ID and description - for easy implementation of GUI/TUI, because that's what we actually need. But I'm planning to do this in a future PR.

Json,
BinaryV0,
Binary,
}

pub fn create_trace_reader(format: TraceEventsFileFormat) -> Box<dyn trace_readers::TraceReader> {
match format {
TraceEventsFileFormat::Json => Box::new(trace_readers::JsonTraceReader {}),
TraceEventsFileFormat::BinaryV0 | TraceEventsFileFormat::Binary => Box::new(trace_readers::BinaryTraceReader {}),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use std::{
path::Path,
};

use crate::{TraceEventsFileFormat, TraceLowLevelEvent, capnptrace::HEADER, cbor_zstd_writer::HEADERV1};
use crate::TraceEventsFileFormat;
use codetracer_trace_format_cbor_zstd::HEADERV1;
use codetracer_trace_types::TraceLowLevelEvent;
use codetracer_trace_format_capnp::capnptrace::HEADER;

pub trait TraceReader {
fn load_trace_events(&mut self, path: &Path) -> Result<Vec<TraceLowLevelEvent>, Box<dyn Error>>;
Expand Down Expand Up @@ -44,7 +47,7 @@ impl TraceReader for BinaryTraceReader {
match ver {
Some(TraceEventsFileFormat::BinaryV0) => {
let mut buf_reader = BufReader::new(file);
Ok(crate::capnptrace::read_trace(&mut buf_reader)?)
Ok(codetracer_trace_format_capnp::capnptrace::read_trace(&mut buf_reader)?)
}
Some(TraceEventsFileFormat::Binary) => Ok(crate::cbor_zstd_reader::read_trace(&mut file)?),
Some(TraceEventsFileFormat::Json) => {
Expand Down
18 changes: 18 additions & 0 deletions codetracer_trace_types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "codetracer_trace_types"
version = "0.16.0"
edition = "2024"
authors = ["Metacraft Labs Ltd"]
description = "A library for the schema for the CodeTracer db trace format"
repository = "https://github.com/metacraft-labs/runtime_tracing"
license = "MIT"
keywords = ["debugging", "development-tools"]

[dependencies]
base64 = "0.22.1"
num-traits = "0.2"
num-derive = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_repr = "0.1"
schemars = "0.8.2"
File renamed without changes.
13 changes: 13 additions & 0 deletions codetracer_trace_types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mod base64;
mod types;
pub use types::*;

#[test]
fn test_equality_of_value_records() {
let a = ValueRecord::Int { i: 0, type_id: TypeId(0) }; // just an example type_id
let b = ValueRecord::Int { i: 0, type_id: TypeId(0) };
let different = ValueRecord::Int { i: 1, type_id: TypeId(0) };

assert_eq!(a, b);
assert_ne!(a, different);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ use schemars::JsonSchema;
// afterwards in postprocessing
// this assumption can change in the future

pub const NONE_TYPE_ID: TypeId = TypeId(0);
pub const NONE_VALUE: ValueRecord = ValueRecord::None { type_id: NONE_TYPE_ID };

pub const TOP_LEVEL_FUNCTION_ID: FunctionId = FunctionId(0);

/// Low level building blocks that make up a recorded trace.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TraceLowLevelEvent {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "runtime_tracing_cli"
version = "0.1.0"
edition = "2021"
name = "codetracer_trace_util"
version = "0.2.0"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.40", features = ["derive"] }
runtime_tracing.workspace = true
codetracer_trace_reader.workspace = true
codetracer_trace_writer.workspace = true
trace_formatter.workspace = true
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::path::Path;

use crate::fmt_trace_cmd::FmtTraceCommand;
use clap::{Args, Parser, Subcommand};
use runtime_tracing::{create_trace_reader, create_trace_writer, TraceEventsFileFormat, TraceWriter};
use codetracer_trace_reader::create_trace_reader;
use codetracer_trace_writer::{create_trace_writer, trace_writer::TraceWriter};
mod fmt_trace_cmd;

#[derive(Debug, Clone, Args)]
Expand All @@ -27,11 +28,21 @@ struct RuntimeTracingCli {
command: RuntimeTracingCliCommand,
}

fn determine_file_format_from_name(s: &str) -> Option<TraceEventsFileFormat> {
fn determine_input_file_format_from_name(s: &str) -> Option<codetracer_trace_reader::TraceEventsFileFormat> {
if s.ends_with(".json") {
Some(TraceEventsFileFormat::Json)
Some(codetracer_trace_reader::TraceEventsFileFormat::Json)
} else if s.ends_with(".bin") {
Some(TraceEventsFileFormat::Binary)
Some(codetracer_trace_reader::TraceEventsFileFormat::Binary)
} else {
None
}
}

fn determine_output_file_format_from_name(s: &str) -> Option<codetracer_trace_writer::TraceEventsFileFormat> {
if s.ends_with(".json") {
Some(codetracer_trace_writer::TraceEventsFileFormat::Json)
} else if s.ends_with(".bin") {
Some(codetracer_trace_writer::TraceEventsFileFormat::Binary)
} else {
None
}
Expand All @@ -42,8 +53,8 @@ fn main() {

match args.command {
RuntimeTracingCliCommand::Convert(convert_command) => {
let input_file_format = determine_file_format_from_name(&convert_command.input_file).unwrap();
let output_file_format = determine_file_format_from_name(&convert_command.output_file).unwrap();
let input_file_format = determine_input_file_format_from_name(&convert_command.input_file).unwrap();
let output_file_format = determine_output_file_format_from_name(&convert_command.output_file).unwrap();
let mut trace_reader = create_trace_reader(input_file_format);
let mut trace_writer = create_trace_writer("", &[], output_file_format);
let mut trace_events = trace_reader.load_trace_events(Path::new(&convert_command.input_file)).unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use runtime_tracing::{TraceEventsFileFormat, TraceWriter, create_trace_reader, create_trace_writer};
use std::fs;
use std::path::Path;

fn test_binary_roundtrip(ver: TraceEventsFileFormat, binfile: &str) {
use codetracer_trace_reader::create_trace_reader;
use codetracer_trace_writer::create_trace_writer;
use codetracer_trace_writer::trace_writer::TraceWriter;

fn test_binary_roundtrip(ver: codetracer_trace_writer::TraceEventsFileFormat, binfile: &str) {
let json_path = Path::new("tests/data/trace.json");

let mut json_reader = create_trace_reader(TraceEventsFileFormat::Json);
let mut json_reader = create_trace_reader(codetracer_trace_reader::TraceEventsFileFormat::Json);
let original = json_reader.load_trace_events(json_path).unwrap();

let bin_path_str = format!("tests/data/{}", binfile);
Expand All @@ -16,7 +19,7 @@ fn test_binary_roundtrip(ver: TraceEventsFileFormat, binfile: &str) {
TraceWriter::append_events(bin_writer.as_mut(), &mut original.clone());
bin_writer.finish_writing_trace_events().unwrap();

let mut bin_reader = create_trace_reader(TraceEventsFileFormat::Binary);
let mut bin_reader = create_trace_reader(codetracer_trace_reader::TraceEventsFileFormat::Binary);
let tracer2_events = bin_reader.load_trace_events(bin_path).unwrap();

fs::remove_file(bin_path).unwrap();
Expand All @@ -29,10 +32,10 @@ fn test_binary_roundtrip(ver: TraceEventsFileFormat, binfile: &str) {

#[test]
fn test_binary_roundtrip_v0() {
test_binary_roundtrip(TraceEventsFileFormat::BinaryV0, "trace.v0.bin");
test_binary_roundtrip(codetracer_trace_writer::TraceEventsFileFormat::BinaryV0, "trace.v0.bin");
}

#[test]
fn test_binary_roundtrip_v1() {
test_binary_roundtrip(TraceEventsFileFormat::Binary, "trace.v1.bin");
test_binary_roundtrip(codetracer_trace_writer::TraceEventsFileFormat::Binary, "trace.v1.bin");
}
22 changes: 22 additions & 0 deletions codetracer_trace_writer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "codetracer_trace_writer"
version = "0.16.0"
edition = "2024"
authors = ["Metacraft Labs Ltd"]
description = "A library for writing the CodeTracer db trace format"
repository = "https://github.com/metacraft-labs/runtime_tracing"
license = "MIT"
keywords = ["debugging", "development-tools"]

[dependencies]
codetracer_trace_types.workspace = true
codetracer_trace_format_capnp.workspace = true
codetracer_trace_format_cbor_zstd.workspace = true
serde_json = "1.0"
cbor4ii = { version = "1.0.0", features = ["serde1", "use_std"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
zeekstd = "0.6.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
ruzstd = "0.8.1"
Loading