Skip to content

Commit 1139cf5

Browse files
committed
chore: upgrade runtime_tracing to the new crates codetracer_trace_writer and codetracer_trace_types
1 parent 871bf81 commit 1139cf5

File tree

3 files changed

+81
-67
lines changed

3 files changed

+81
-67
lines changed

gems/codetracer-ruby-recorder/ext/native_tracer/Cargo.lock

Lines changed: 49 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gems/codetracer-ruby-recorder/ext/native_tracer/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ crate-type = ["cdylib"]
1111

1212
[dependencies]
1313
rb-sys = "0.9"
14-
runtime_tracing = "0.15.0"
14+
codetracer_trace_types = "0.16.0"
15+
codetracer_trace_writer = "0.16.0"
1516

1617
[build-dependencies]
1718
rb-sys-env = "0.2"

gems/codetracer-ruby-recorder/ext/native_tracer/src/lib.rs

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ use std::{
1111
string::FromUtf8Error,
1212
};
1313

14+
use codetracer_trace_types::{
15+
CallRecord, EventLogKind, FieldTypeRecord, FullValueRecord, Line, ThreadId, TraceLowLevelEvent,
16+
TypeId, TypeKind, TypeRecord, TypeSpecificInfo, ValueRecord, NONE_TYPE_ID,
17+
};
18+
use codetracer_trace_writer::{
19+
create_trace_writer, trace_writer::TraceWriter, TraceEventsFileFormat,
20+
};
1421
use rb_sys::{
1522
rb_add_event_hook2, rb_cObject, rb_cRange, rb_cRegexp, rb_cStruct, rb_cThread, rb_cTime,
1623
rb_check_typeddata, rb_const_defined, rb_const_get, rb_data_type_struct__bindgen_ty_1,
@@ -28,11 +35,6 @@ use rb_sys::{
2835
RUBY_INTERNAL_THREAD_EVENT_RESUMED, RUBY_INTERNAL_THREAD_EVENT_STARTED,
2936
RUBY_INTERNAL_THREAD_EVENT_SUSPENDED, VALUE,
3037
};
31-
use runtime_tracing::{
32-
create_trace_writer, CallRecord, EventLogKind, FieldTypeRecord, FullValueRecord, Line,
33-
ThreadId, TraceEventsFileFormat, TraceLowLevelEvent, TraceWriter, TypeKind, TypeRecord,
34-
TypeSpecificInfo, ValueRecord,
35-
};
3638

3739
struct InternedSymbols {
3840
to_s: ID,
@@ -93,12 +95,12 @@ struct RecorderData {
9395
set_class: VALUE,
9496
open_struct_class: VALUE,
9597
struct_type_versions: HashMap<String, usize>,
96-
int_type_id: runtime_tracing::TypeId,
97-
float_type_id: runtime_tracing::TypeId,
98-
bool_type_id: runtime_tracing::TypeId,
99-
string_type_id: runtime_tracing::TypeId,
100-
symbol_type_id: runtime_tracing::TypeId,
101-
error_type_id: runtime_tracing::TypeId,
98+
int_type_id: TypeId,
99+
float_type_id: TypeId,
100+
bool_type_id: TypeId,
101+
string_type_id: TypeId,
102+
symbol_type_id: TypeId,
103+
error_type_id: TypeId,
102104
}
103105

104106
struct Recorder {
@@ -120,7 +122,7 @@ fn should_ignore_path(path: &str) -> bool {
120122
PATTERNS.iter().any(|p| path.contains(p))
121123
}
122124

123-
fn value_type_id(val: &ValueRecord) -> runtime_tracing::TypeId {
125+
fn value_type_id(val: &ValueRecord) -> TypeId {
124126
use ValueRecord::*;
125127
match val {
126128
Int { type_id, .. }
@@ -136,7 +138,7 @@ fn value_type_id(val: &ValueRecord) -> runtime_tracing::TypeId {
136138
| Error { type_id, .. }
137139
| BigInt { type_id, .. }
138140
| None { type_id } => *type_id,
139-
Cell { .. } => runtime_tracing::NONE_TYPE_ID,
141+
Cell { .. } => NONE_TYPE_ID,
140142
}
141143
}
142144

@@ -229,12 +231,12 @@ unsafe extern "C" fn ruby_recorder_alloc(klass: VALUE) -> VALUE {
229231
set_class: Qnil.into(),
230232
open_struct_class: Qnil.into(),
231233
struct_type_versions: HashMap::new(),
232-
int_type_id: runtime_tracing::TypeId::default(),
233-
float_type_id: runtime_tracing::TypeId::default(),
234-
bool_type_id: runtime_tracing::TypeId::default(),
235-
string_type_id: runtime_tracing::TypeId::default(),
236-
symbol_type_id: runtime_tracing::TypeId::default(),
237-
error_type_id: runtime_tracing::TypeId::default(),
234+
int_type_id: TypeId::default(),
235+
float_type_id: TypeId::default(),
236+
bool_type_id: TypeId::default(),
237+
string_type_id: TypeId::default(),
238+
symbol_type_id: TypeId::default(),
239+
error_type_id: TypeId::default(),
238240
},
239241
});
240242
let ty = std::ptr::addr_of!(RECORDER_TYPE) as *const rb_data_type_t;
@@ -275,14 +277,13 @@ unsafe extern "C" fn disable_tracing(self_val: VALUE) -> VALUE {
275277

276278
fn begin_trace(
277279
dir: &Path,
278-
format: runtime_tracing::TraceEventsFileFormat,
280+
format: TraceEventsFileFormat,
279281
) -> Result<Box<dyn TraceWriter>, Box<dyn std::error::Error>> {
280282
let mut tracer = create_trace_writer("ruby", &vec![], format);
281283
std::fs::create_dir_all(dir)?;
282284
let events = match format {
283-
runtime_tracing::TraceEventsFileFormat::Json => dir.join("trace.json"),
284-
runtime_tracing::TraceEventsFileFormat::BinaryV0
285-
| runtime_tracing::TraceEventsFileFormat::Binary => dir.join("trace.bin"),
285+
TraceEventsFileFormat::Json => dir.join("trace.json"),
286+
TraceEventsFileFormat::BinaryV0 | TraceEventsFileFormat::Binary => dir.join("trace.bin"),
286287
};
287288
let metadata = dir.join("trace_metadata.json");
288289
let paths = dir.join("trace_paths.json");
@@ -382,7 +383,7 @@ unsafe fn to_value(
382383
}
383384
if RB_FLOAT_TYPE_P(val) {
384385
let f = rb_num2dbl(val);
385-
let type_id = if recorder.float_type_id == runtime_tracing::NONE_TYPE_ID {
386+
let type_id = if recorder.float_type_id == NONE_TYPE_ID {
386387
let id = TraceWriter::ensure_type_id(tracer, TypeKind::Float, "Float");
387388
recorder.float_type_id = id;
388389
id
@@ -658,13 +659,13 @@ unsafe extern "C" fn initialize(self_val: VALUE, out_dir: VALUE, format: VALUE)
658659
.unwrap_or_default()
659660
.as_str()
660661
{
661-
"binaryv0" => runtime_tracing::TraceEventsFileFormat::BinaryV0,
662-
"binary" | "bin" => runtime_tracing::TraceEventsFileFormat::Binary,
663-
"json" => runtime_tracing::TraceEventsFileFormat::Json,
662+
"binaryv0" => TraceEventsFileFormat::BinaryV0,
663+
"binary" | "bin" => TraceEventsFileFormat::Binary,
664+
"json" => TraceEventsFileFormat::Json,
664665
_ => rb_raise(rb_eIOError, c"Unknown format".as_ptr() as *const c_char),
665666
}
666667
} else {
667-
runtime_tracing::TraceEventsFileFormat::Json
668+
TraceEventsFileFormat::Json
668669
};
669670

670671
match rstring_checked(out_dir) {
@@ -683,7 +684,7 @@ unsafe extern "C" fn initialize(self_val: VALUE, out_dir: VALUE, format: VALUE)
683684
);
684685
recorder.data.bool_type_id =
685686
TraceWriter::ensure_type_id(&mut **locked_tracer, TypeKind::Bool, "Bool");
686-
recorder.data.float_type_id = runtime_tracing::NONE_TYPE_ID;
687+
recorder.data.float_type_id = NONE_TYPE_ID;
687688
recorder.data.symbol_type_id = TraceWriter::ensure_type_id(
688689
&mut **locked_tracer,
689690
TypeKind::String,

0 commit comments

Comments
 (0)