Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 13 additions & 3 deletions runtime_tracing/src/abstract_trace_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
21 changes: 21 additions & 0 deletions runtime_tracing/src/capnptrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -702,6 +714,15 @@ pub fn read_trace(input: &mut impl std::io::BufRead) -> ::capnp::Result<Vec<crat
Ok(trace::trace_low_level_event::Which::DropVariable(variable_id)) => {
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!()
Expand Down
8 changes: 8 additions & 0 deletions runtime_tracing/src/trace.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ struct Trace {
variableCell @18 :VariableCellRecord;
dropVariable @19 :VariableId;

threadStart @21 :ThreadId;
threadExit @22 :ThreadId;
threadSwitch @23 :ThreadId;

dropLastStep @20 :Void;
}
}
Expand Down Expand Up @@ -115,6 +119,10 @@ struct Trace {
i @0 :Int64;
}

struct ThreadId {
i @0 :UInt64;
}

struct CallRecord {
functionId @0 :FunctionId;
args @1 :List(FullValueRecord);
Expand Down
13 changes: 13 additions & 0 deletions runtime_tracing/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -245,6 +249,15 @@ impl Into<usize> for FunctionId {
}
}

#[derive(Hash, Debug, Default, Copy, Clone, Serialize, Deserialize, Ord, PartialOrd, Eq, PartialEq)]
pub struct ThreadId(pub u64);

impl Into<u64> for ThreadId {
fn into(self) -> u64 {
self.0
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CallRecord {
// pub key: CallKey,
Expand Down