diff --git a/runtime_tracing/src/abstract_trace_writer.rs b/runtime_tracing/src/abstract_trace_writer.rs index 4f350bf..a93997b 100644 --- a/runtime_tracing/src/abstract_trace_writer.rs +++ b/runtime_tracing/src/abstract_trace_writer.rs @@ -7,9 +7,7 @@ use std::{ }; use crate::{ - AssignCellRecord, AssignCompoundItemRecord, AssignmentRecord, CallRecord, CellValueRecord, CompoundValueRecord, FullValueRecord, FunctionId, - FunctionRecord, Line, NONE_TYPE_ID, PathId, RValue, RecordEvent, ReturnRecord, StepRecord, TraceLowLevelEvent, TraceMetadata, TypeId, TypeKind, - TypeRecord, TypeSpecificInfo, VariableCellRecord, VariableId, tracer::TOP_LEVEL_FUNCTION_ID, + tracer::TOP_LEVEL_FUNCTION_ID, AssignCellRecord, AssignCompoundItemRecord, AssignmentRecord, CallRecord, CellValueRecord, CompoundValueRecord, FullValueRecord, FunctionId, FunctionRecord, Line, PathId, RValue, RecordEvent, ReturnRecord, StepRecord, ThreadId, TraceLowLevelEvent, TraceMetadata, TypeId, TypeKind, TypeRecord, TypeSpecificInfo, VariableCellRecord, VariableId, NONE_TYPE_ID }; pub struct AbstractTraceWriterData { @@ -280,6 +278,18 @@ pub trait AbstractTraceWriter { RValue::Compound(variable_ids) } + fn thread_start(&mut self, thread_id: ThreadId) { + self.add_event(TraceLowLevelEvent::ThreadStart(thread_id)); + } + + fn thread_exit(&mut self, thread_id: ThreadId) { + self.add_event(TraceLowLevelEvent::ThreadExit(thread_id)); + } + + fn thread_switch(&mut self, thread_id: ThreadId) { + self.add_event(TraceLowLevelEvent::ThreadSwitch(thread_id)); + } + fn drop_last_step(&mut self) { self.add_event(TraceLowLevelEvent::DropLastStep); } diff --git a/runtime_tracing/src/capnptrace.rs b/runtime_tracing/src/capnptrace.rs index 5005f77..07eb176 100644 --- a/runtime_tracing/src/capnptrace.rs +++ b/runtime_tracing/src/capnptrace.rs @@ -441,6 +441,18 @@ pub fn write_trace(q: &[crate::TraceLowLevelEvent], output: &mut impl std::io::W let mut ret_place = ret.init_place(); ret_place.set_p(vcr.place.0.try_into().unwrap()); } + TraceLowLevelEvent::ThreadStart(tid) => { + let mut ret = event.init_thread_start(); + ret.set_i(tid.0); + } + TraceLowLevelEvent::ThreadExit(tid) => { + let mut ret = event.init_thread_exit(); + ret.set_i(tid.0); + } + TraceLowLevelEvent::ThreadSwitch(tid) => { + let mut ret = event.init_thread_switch(); + ret.set_i(tid.0); + } } } @@ -702,6 +714,15 @@ pub fn read_trace(input: &mut impl std::io::BufRead) -> ::capnp::Result { TraceLowLevelEvent::DropVariable(crate::VariableId(variable_id?.get_i().try_into().unwrap())) } + Ok(trace::trace_low_level_event::Which::ThreadStart(thread_id)) => { + TraceLowLevelEvent::ThreadStart(crate::ThreadId(thread_id?.get_i())) + } + Ok(trace::trace_low_level_event::Which::ThreadExit(thread_id)) => { + TraceLowLevelEvent::ThreadExit(crate::ThreadId(thread_id?.get_i())) + } + Ok(trace::trace_low_level_event::Which::ThreadSwitch(thread_id)) => { + TraceLowLevelEvent::ThreadSwitch(crate::ThreadId(thread_id?.get_i())) + } Ok(trace::trace_low_level_event::Which::DropLastStep(())) => TraceLowLevelEvent::DropLastStep, Err(_) => { panic!() diff --git a/runtime_tracing/src/trace.capnp b/runtime_tracing/src/trace.capnp index 083fc31..5f1f37c 100644 --- a/runtime_tracing/src/trace.capnp +++ b/runtime_tracing/src/trace.capnp @@ -31,6 +31,10 @@ struct Trace { variableCell @18 :VariableCellRecord; dropVariable @19 :VariableId; + threadStart @21 :ThreadId; + threadExit @22 :ThreadId; + threadSwitch @23 :ThreadId; + dropLastStep @20 :Void; } } @@ -115,6 +119,10 @@ struct Trace { i @0 :Int64; } + struct ThreadId { + i @0 :UInt64; + } + struct CallRecord { functionId @0 :FunctionId; args @1 :List(FullValueRecord); diff --git a/runtime_tracing/src/types.rs b/runtime_tracing/src/types.rs index 0b4b47d..11e8fe8 100644 --- a/runtime_tracing/src/types.rs +++ b/runtime_tracing/src/types.rs @@ -49,6 +49,10 @@ pub enum TraceLowLevelEvent { VariableCell(VariableCellRecord), DropVariable(VariableId), + ThreadStart(ThreadId), + ThreadExit(ThreadId), + ThreadSwitch(ThreadId), + // normal event, workaround for cases when we need to drop // a step event, but the trace needs to be append-only DropLastStep, @@ -245,6 +249,15 @@ impl Into for FunctionId { } } +#[derive(Hash, Debug, Default, Copy, Clone, Serialize, Deserialize, Ord, PartialOrd, Eq, PartialEq)] +pub struct ThreadId(pub u64); + +impl Into for ThreadId { + fn into(self) -> u64 { + self.0 + } +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct CallRecord { // pub key: CallKey,