Skip to content

Commit 6811e6b

Browse files
committed
feat: add header to the beginning of the binary file
1 parent 0bcb1fe commit 6811e6b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

runtime_tracing/src/capnptrace.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ use crate::trace_capnp::trace;
33
use capnp::serialize_packed;
44
use crate::{TraceLowLevelEvent, VariableId};
55

6+
/// The first 5 bytes identify the file as a CodeTracer file (hex l33tsp33k - C0DE72ACE2 for "CodeTracer").
7+
/// The next 3 bytes are reserved/version info. In the initial version, they are zero. Non-zero values might
8+
/// indicate incompatible future versions.
9+
/// The header is 8 bytes in size, ensuring 64-bit alignment for the rest of the file.
10+
const HEADER: &'static [u8] = &[0xC0, 0xDE, 0x72, 0xAC, 0xE2, 0x00, 0x00, 0x00];
11+
612
fn conv_typekind(kind: crate::TypeKind) -> trace::TypeKind {
713
match kind {
814
crate::TypeKind::Seq => trace::TypeKind::Seq,
@@ -208,7 +214,7 @@ fn conv_valuerecord(
208214
}
209215
}
210216

211-
pub fn write_trace(q: &Vec<crate::TraceLowLevelEvent>, output: impl std::io::Write) -> ::capnp::Result<()> {
217+
pub fn write_trace(q: &Vec<crate::TraceLowLevelEvent>, output: &mut impl std::io::Write) -> ::capnp::Result<()> {
212218
let mut message = ::capnp::message::Builder::new_default();
213219

214220
let trace = message.init_root::<trace::Builder>();
@@ -303,6 +309,8 @@ pub fn write_trace(q: &Vec<crate::TraceLowLevelEvent>, output: impl std::io::Wri
303309
}
304310
}
305311

312+
output.write(HEADER)?;
313+
306314
serialize_packed::write_message(output, &message)
307315
}
308316

runtime_tracing/src/tracer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ impl Tracer {
307307
fs::write(path, json)?;
308308
}
309309
TraceEventsFileFormat::Binary => {
310-
let file = fs::File::create(path)?;
311-
crate::capnptrace::write_trace(&self.events, file)?;
310+
let mut file = fs::File::create(path)?;
311+
crate::capnptrace::write_trace(&self.events, &mut file)?;
312312
}
313313
}
314314
Ok(())

0 commit comments

Comments
 (0)