Skip to content

Commit 91d6ac3

Browse files
committed
refactor: try_new2 -> try_new_with_dictionary
1 parent aaf1b01 commit 91d6ac3

File tree

4 files changed

+19
-69
lines changed

4 files changed

+19
-69
lines changed

libdd-profiling/benches/add_samples.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ pub fn bench_add_sample_vs_add2(c: &mut Criterion) {
149149

150150
c.bench_function("profile_add_sample2_frames_x1000", |b| {
151151
b.iter(|| {
152-
let mut profile = profiling::internal::Profile::try_new2(
153-
dict.try_clone().unwrap(),
152+
let mut profile = profiling::internal::Profile::try_new_with_dictionary(
154153
&sample_types2,
155154
None,
155+
dict.try_clone().unwrap(),
156156
)
157157
.unwrap();
158158
let (locations, values) = make_stack_api2(frames2.as_slice());

libdd-profiling/src/api2.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2025-Present Datadog, Inc. https://www.datadoghq.com/
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use crate::profiles::datatypes::{self, FunctionId2, MappingId2, StringId2};
4+
use crate::profiles::datatypes::{FunctionId2, MappingId2, StringId2};
55

66
#[derive(Copy, Clone, Debug, Default)]
77
#[repr(C)]
@@ -55,24 +55,3 @@ impl<'a> Label<'a> {
5555
}
5656
}
5757
}
58-
#[repr(C)]
59-
#[derive(Clone, Copy, Debug)]
60-
pub struct ValueType2 {
61-
pub type_id: StringId2,
62-
pub unit_id: StringId2,
63-
}
64-
65-
impl From<ValueType2> for datatypes::ValueType {
66-
fn from(value: ValueType2) -> datatypes::ValueType {
67-
datatypes::ValueType {
68-
type_id: value.type_id.into(),
69-
unit_id: value.unit_id.into(),
70-
}
71-
}
72-
}
73-
74-
#[derive(Copy, Clone, Debug)]
75-
pub struct Period2 {
76-
pub r#type: ValueType2,
77-
pub value: i64,
78-
}

libdd-profiling/src/internal/owned_types/mod.rs

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use crate::api;
5-
use crate::api2::{Period2, ValueType2};
6-
use crate::profiles::collections::StringRef;
7-
use std::ops::Deref;
85

96
#[cfg_attr(test, derive(bolero::generator::TypeGenerator))]
107
#[derive(Clone, Debug)]
@@ -23,22 +20,6 @@ impl<'a> From<&'a api::ValueType<'a>> for ValueType {
2320
}
2421
}
2522

26-
impl From<ValueType2> for ValueType {
27-
fn from(value_type2: ValueType2) -> ValueType {
28-
let typ: StringRef = value_type2.type_id.into();
29-
let unit: StringRef = value_type2.unit_id.into();
30-
ValueType {
31-
typ: Box::from(typ.0.deref()),
32-
unit: Box::from(unit.0.deref()),
33-
}
34-
}
35-
}
36-
impl From<&ValueType2> for ValueType {
37-
fn from(value_type2: &ValueType2) -> ValueType {
38-
ValueType::from(*value_type2)
39-
}
40-
}
41-
4223
impl<'a> From<&'a ValueType> for api::ValueType<'a> {
4324
fn from(value: &'a ValueType) -> Self {
4425
Self::new(&value.typ, &value.unit)
@@ -52,6 +33,13 @@ pub struct Period {
5233
pub value: i64,
5334
}
5435

36+
impl<'a> From<api::Period<'a>> for Period {
37+
#[inline]
38+
fn from(period: api::Period<'a>) -> Self {
39+
Period::from(&period)
40+
}
41+
}
42+
5543
impl<'a> From<&'a api::Period<'a>> for Period {
5644
#[inline]
5745
fn from(period: &'a api::Period<'a>) -> Self {
@@ -61,12 +49,3 @@ impl<'a> From<&'a api::Period<'a>> for Period {
6149
}
6250
}
6351
}
64-
65-
impl From<Period2> for Period {
66-
fn from(period2: Period2) -> Period {
67-
Period {
68-
typ: ValueType::from(period2.r#type),
69-
value: 0,
70-
}
71-
}
72-
}

libdd-profiling/src/internal/profile/mod.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub use profiles_dictionary_translator::*;
1212
use self::api::UpscalingInfo;
1313
use super::*;
1414
use crate::api::ManagedStringId;
15-
use crate::api2::{Period2, ValueType2};
1615
use crate::collections::identifiable::*;
1716
use crate::collections::string_storage::{CachedProfileId, ManagedStringStorage};
1817
use crate::collections::string_table::{self, StringTable};
@@ -384,7 +383,7 @@ impl Profile {
384383
///
385384
/// All other fields are default.
386385
///
387-
/// It's recommended to use [`Profile::try_new2`] instead.
386+
/// It's recommended to use [`Profile::try_new_with_dictionary`] instead.
388387
pub fn try_new(
389388
sample_types: &[api::ValueType],
390389
period: Option<api::Period>,
@@ -397,14 +396,13 @@ impl Profile {
397396
)
398397
}
399398

400-
/// Tries to create a profile with the given period and sample types. The
401-
/// [`StringId2`]s should belong to the provided [`ProfilesDictionary`].
399+
/// Tries to create a profile with the given period and sample types.
402400
#[inline(never)]
403401
#[cold]
404-
pub fn try_new2(
402+
pub fn try_new_with_dictionary(
403+
sample_types: &[api::ValueType],
404+
period: Option<api::Period>,
405405
profiles_dictionary: crate::profiles::collections::Arc<ProfilesDictionary>,
406-
sample_types: &[ValueType2],
407-
period: Option<Period2>,
408406
) -> io::Result<Self> {
409407
let mut owned_sample_types = Vec::new();
410408
// Using try_reserve_exact because it will be converted to a Box<[]>,
@@ -2707,7 +2705,7 @@ mod api_tests {
27072705

27082706
#[test]
27092707
#[cfg_attr(miri, ignore)]
2710-
fn test_try_new2_and_try_add_sample2() {
2708+
fn test_try_new_with_dictionary_and_try_add_sample2() {
27112709
struct Frame {
27122710
file_name: &'static str,
27132711
line_number: u32,
@@ -2716,14 +2714,7 @@ mod api_tests {
27162714

27172715
// Create a ProfilesDictionary with realistic data from Ruby app
27182716
let dict = crate::profiles::datatypes::ProfilesDictionary::try_new().unwrap();
2719-
2720-
// Create sample types
2721-
let samples_type = dict.try_insert_str2("samples").unwrap();
2722-
let count_unit = dict.try_insert_str2("count").unwrap();
2723-
let sample_types = vec![ValueType2 {
2724-
type_id: samples_type,
2725-
unit_id: count_unit,
2726-
}];
2717+
let sample_types = vec![api::ValueType::new("samples", "count")];
27272718

27282719
// Ruby stack trace (leaf-to-root order)
27292720
// Taken from a Ruby app, everything here is source-available
@@ -2784,7 +2775,8 @@ mod api_tests {
27842775

27852776
// Create profile with dictionary
27862777
let mut profile =
2787-
Profile::try_new2(dict.try_clone().unwrap(), &sample_types, None).unwrap();
2778+
Profile::try_new_with_dictionary(&sample_types, None, dict.try_clone().unwrap())
2779+
.unwrap();
27882780

27892781
assert_eq!(profile.only_for_testing_num_aggregated_samples(), 0);
27902782

0 commit comments

Comments
 (0)