@@ -96,27 +96,14 @@ impl From<anyhow::Result<internal::EncodedProfile>> for SerializeResult {
9696 }
9797}
9898
99- #[ repr( C ) ]
100- #[ derive( Copy , Clone ) ]
101- pub struct ValueType < ' a > {
102- pub type_ : CharSlice < ' a > ,
103- pub unit : CharSlice < ' a > ,
104- }
105-
106- impl < ' a > ValueType < ' a > {
107- pub fn new ( type_ : & ' a str , unit : & ' a str ) -> Self {
108- Self {
109- type_ : type_. into ( ) ,
110- unit : unit. into ( ) ,
111- }
112- }
113- }
99+ /// Sample types supported by Datadog profilers.
100+ /// These correspond to the ValueType entries used in pprof profiles.
101+ /// Re-exported from libdd_profiling::api for FFI use.
102+ pub use api:: SampleType ;
114103
115- #[ repr( C ) ]
116- pub struct Period < ' a > {
117- pub type_ : ValueType < ' a > ,
118- pub value : i64 ,
119- }
104+ /// Re-export Period from the API for consistency.
105+ /// The FFI Period is identical to the API Period.
106+ pub use api:: Period ;
120107
121108#[ repr( C ) ]
122109#[ derive( Copy , Clone , Default ) ]
@@ -283,24 +270,6 @@ impl<'a> From<&'a Mapping<'a>> for api::StringIdMapping {
283270 }
284271}
285272
286- impl < ' a > From < & ' a ValueType < ' a > > for api:: ValueType < ' a > {
287- fn from ( vt : & ' a ValueType < ' a > ) -> Self {
288- Self :: new (
289- vt. type_ . try_to_utf8 ( ) . unwrap_or ( "" ) ,
290- vt. unit . try_to_utf8 ( ) . unwrap_or ( "" ) ,
291- )
292- }
293- }
294-
295- impl < ' a > From < & ' a Period < ' a > > for api:: Period < ' a > {
296- fn from ( period : & ' a Period < ' a > ) -> Self {
297- Self {
298- r#type : api:: ValueType :: from ( & period. type_ ) ,
299- value : period. value ,
300- }
301- }
302- }
303-
304273impl < ' a > TryFrom < & ' a Function < ' a > > for api:: Function < ' a > {
305274 type Error = Utf8Error ;
306275
@@ -423,7 +392,7 @@ impl<'a> From<Sample<'a>> for api::StringIdSample<'a> {
423392/// `ddog_prof_Profile_drop` when you are done with the profile.
424393///
425394/// # Arguments
426- /// * `sample_types`
395+ /// * `sample_types` - A slice of SampleType enums
427396/// * `period` - Optional period of the profile. Passing None/null translates to zero values.
428397/// * `start_time` - Optional time the profile started at. Passing None/null will use the current
429398/// time.
@@ -434,7 +403,7 @@ impl<'a> From<Sample<'a>> for api::StringIdSample<'a> {
434403#[ no_mangle]
435404#[ must_use]
436405pub unsafe extern "C" fn ddog_prof_Profile_new (
437- sample_types : Slice < ValueType > ,
406+ sample_types : Slice < SampleType > ,
438407 period : Option < & Period > ,
439408) -> ProfileNewResult {
440409 profile_new ( sample_types, period, None )
@@ -446,7 +415,7 @@ pub unsafe extern "C" fn ddog_prof_Profile_new(
446415/// # Arguments
447416/// * `out` - a non-null pointer to an uninitialized Profile.
448417/// * `dict`: a valid reference to a ProfilesDictionary handle.
449- /// * `sample_types`
418+ /// * `sample_types` - A slice of SampleType enums
450419/// * `period` - Optional period of the profile. Passing None/null translates to zero values.
451420///
452421/// # Safety
@@ -463,7 +432,7 @@ pub unsafe extern "C" fn ddog_prof_Profile_new(
463432pub unsafe extern "C" fn ddog_prof_Profile_with_dictionary (
464433 out : * mut Profile ,
465434 dict : & ArcHandle < ProfilesDictionary > ,
466- sample_types : Slice < ValueType > ,
435+ sample_types : Slice < SampleType > ,
467436 period : Option < & Period > ,
468437) -> ProfileStatus {
469438 ensure_non_null_out_parameter ! ( out) ;
@@ -481,18 +450,15 @@ pub unsafe extern "C" fn ddog_prof_Profile_with_dictionary(
481450
482451unsafe fn profile_with_dictionary (
483452 dict : & ArcHandle < ProfilesDictionary > ,
484- sample_types : Slice < ValueType > ,
453+ sample_types : Slice < SampleType > ,
485454 period : Option < & Period > ,
486455) -> Result < Profile , ProfileError > {
487456 let sample_types = sample_types. try_as_slice ( ) ?;
488457 let dict = dict. try_clone_into_arc ( ) ?;
489458
490- let mut types = Vec :: new ( ) ;
491- types. try_reserve_exact ( sample_types. len ( ) ) ?;
492- types. extend ( sample_types. iter ( ) . map ( api:: ValueType :: from) ) ;
493- let period = period. map ( Into :: into) ;
459+ let period = period. copied ( ) ;
494460
495- match internal:: Profile :: try_new_with_dictionary ( & types , period, dict) {
461+ match internal:: Profile :: try_new_with_dictionary ( sample_types , period, dict) {
496462 Ok ( ok) => Ok ( Profile :: new ( ok) ) ,
497463 Err ( err) => Err ( ProfileError :: from ( err) ) ,
498464 }
@@ -503,30 +469,30 @@ unsafe fn profile_with_dictionary(
503469#[ must_use]
504470/// TODO: @ivoanjo Should this take a `*mut ManagedStringStorage` like Profile APIs do?
505471pub unsafe extern "C" fn ddog_prof_Profile_with_string_storage (
506- sample_types : Slice < ValueType > ,
472+ sample_types : Slice < SampleType > ,
507473 period : Option < & Period > ,
508474 string_storage : ManagedStringStorage ,
509475) -> ProfileNewResult {
510476 profile_new ( sample_types, period, Some ( string_storage) )
511477}
512478
513479unsafe fn profile_new (
514- sample_types : Slice < ValueType > ,
480+ sample_types : Slice < SampleType > ,
515481 period : Option < & Period > ,
516482 string_storage : Option < ManagedStringStorage > ,
517483) -> ProfileNewResult {
518- let types: Vec < api :: ValueType > = sample_types. into_slice ( ) . iter ( ) . map ( Into :: into ) . collect ( ) ;
519- let period = period. map ( Into :: into ) ;
484+ let types = sample_types. into_slice ( ) ;
485+ let period = period. copied ( ) ;
520486
521487 let result = match string_storage {
522- None => internal:: Profile :: try_new ( & types, period)
488+ None => internal:: Profile :: try_new ( types, period)
523489 . context ( "failed to initialize a profile without managed string storage" ) ,
524490 Some ( s) => {
525491 let string_storage = match get_inner_string_storage ( s, true ) {
526492 Ok ( string_storage) => string_storage,
527493 Err ( err) => return ProfileNewResult :: Err ( err. into ( ) ) ,
528494 } ;
529- internal:: Profile :: try_with_string_storage ( & types, period, string_storage)
495+ internal:: Profile :: try_with_string_storage ( types, period, string_storage)
530496 . context ( "failed to initialize a profile with managed string storage" )
531497 }
532498 } ;
@@ -937,9 +903,9 @@ mod tests {
937903 #[ test]
938904 fn ctor_and_dtor ( ) -> Result < ( ) , Error > {
939905 unsafe {
940- let sample_type: * const ValueType = & ValueType :: new ( "samples" , "count" ) ;
906+ let sample_type = SampleType :: CpuSamples ;
941907 let mut profile = Result :: from ( ddog_prof_Profile_new (
942- Slice :: from_raw_parts ( sample_type, 1 ) ,
908+ Slice :: from_raw_parts ( & sample_type, 1 ) ,
943909 None ,
944910 ) ) ?;
945911 ddog_prof_Profile_drop ( & mut profile) ;
@@ -950,9 +916,9 @@ mod tests {
950916 #[ test]
951917 fn add_failure ( ) -> Result < ( ) , Error > {
952918 unsafe {
953- let sample_type: * const ValueType = & ValueType :: new ( "samples" , "count" ) ;
919+ let sample_type = SampleType :: CpuSamples ;
954920 let mut profile = Result :: from ( ddog_prof_Profile_new (
955- Slice :: from_raw_parts ( sample_type, 1 ) ,
921+ Slice :: from_raw_parts ( & sample_type, 1 ) ,
956922 None ,
957923 ) ) ?;
958924
@@ -977,9 +943,9 @@ mod tests {
977943 #[ cfg_attr( miri, ignore) ]
978944 fn aggregate_samples ( ) -> anyhow:: Result < ( ) > {
979945 unsafe {
980- let sample_type: * const ValueType = & ValueType :: new ( "samples" , "count" ) ;
946+ let sample_type = SampleType :: CpuSamples ;
981947 let mut profile = Result :: from ( ddog_prof_Profile_new (
982- Slice :: from_raw_parts ( sample_type, 1 ) ,
948+ Slice :: from_raw_parts ( & sample_type, 1 ) ,
983949 None ,
984950 ) ) ?;
985951
@@ -1039,9 +1005,9 @@ mod tests {
10391005 }
10401006
10411007 unsafe fn provide_distinct_locations_ffi ( ) -> Profile {
1042- let sample_type: * const ValueType = & ValueType :: new ( "samples" , "count" ) ;
1008+ let sample_type = SampleType :: CpuSamples ;
10431009 let mut profile = Result :: from ( ddog_prof_Profile_new (
1044- Slice :: from_raw_parts ( sample_type, 1 ) ,
1010+ Slice :: from_raw_parts ( & sample_type, 1 ) ,
10451011 None ,
10461012 ) )
10471013 . unwrap ( ) ;
0 commit comments