6
6
7
7
use datadog_profiling:: exporter;
8
8
use datadog_profiling:: exporter:: { ProfileExporter , Request } ;
9
- use datadog_profiling:: internal:: ProfiledEndpointsStats ;
9
+ use datadog_profiling:: internal:: EncodedProfile ;
10
10
use ddcommon:: tag:: Tag ;
11
11
use ddcommon_ffi:: slice:: { AsBytes , ByteSlice , CharSlice , Slice } ;
12
- use ddcommon_ffi:: { Error , MaybeError , Timespec } ;
12
+ use ddcommon_ffi:: { Error , Handle , MaybeError , ToInner } ;
13
13
use std:: borrow:: Cow ;
14
14
use std:: ptr:: NonNull ;
15
15
use std:: str:: FromStr ;
@@ -259,16 +259,15 @@ impl From<RequestBuildResult> for Result<Box<Request>, String> {
259
259
/// valid objects created by this module.
260
260
/// NULL is allowed for `optional_additional_tags`, `optional_endpoints_stats`,
261
261
/// `optional_internal_metadata_json` and `optional_info_json`.
262
+ /// Consumes the `SerializedProfile`
262
263
#[ no_mangle]
263
264
#[ must_use]
264
265
pub unsafe extern "C" fn ddog_prof_Exporter_Request_build (
265
266
exporter : Option < & mut ProfileExporter > ,
266
- start : Timespec ,
267
- end : Timespec ,
267
+ mut profile : Handle < EncodedProfile > ,
268
268
files_to_compress_and_export : Slice < File > ,
269
269
files_to_export_unmodified : Slice < File > ,
270
270
optional_additional_tags : Option < & ddcommon_ffi:: Vec < Tag > > ,
271
- optional_endpoints_stats : Option < & ProfiledEndpointsStats > ,
272
271
optional_internal_metadata_json : Option < & CharSlice > ,
273
272
optional_info_json : Option < & CharSlice > ,
274
273
) -> RequestBuildResult {
@@ -290,13 +289,16 @@ pub unsafe extern "C" fn ddog_prof_Exporter_Request_build(
290
289
Err ( err) => return RequestBuildResult :: Err ( err. into ( ) ) ,
291
290
} ;
292
291
292
+ let profile = match profile. take ( ) {
293
+ Ok ( p) => * p,
294
+ Err ( e) => return RequestBuildResult :: Err ( e. into ( ) ) ,
295
+ } ;
296
+
293
297
match exporter. build (
294
- start. into ( ) ,
295
- end. into ( ) ,
298
+ profile,
296
299
files_to_compress_and_export. as_slice ( ) ,
297
300
files_to_export_unmodified. as_slice ( ) ,
298
301
tags. as_ref ( ) ,
299
- optional_endpoints_stats,
300
302
internal_metadata,
301
303
info,
302
304
) {
@@ -575,19 +577,7 @@ mod tests {
575
577
ExporterNewResult :: Err ( _) => panic ! ( "Should not occur!" ) ,
576
578
} ;
577
579
578
- let files_to_compress_and_export: & [ File ] = & [ File {
579
- name : CharSlice :: from ( "foo.pprof" ) ,
580
- file : ByteSlice :: from ( b"dummy contents" as & [ u8 ] ) ,
581
- } ] ;
582
-
583
- let start = Timespec {
584
- seconds : 12 ,
585
- nanoseconds : 34 ,
586
- } ;
587
- let finish = Timespec {
588
- seconds : 56 ,
589
- nanoseconds : 78 ,
590
- } ;
580
+ let profile = EncodedProfile :: test_instance ( ) . unwrap ( ) . into ( ) ;
591
581
let timeout_milliseconds = 90 ;
592
582
unsafe {
593
583
ddog_prof_Exporter_set_timeout ( Some ( exporter. as_mut ( ) ) , timeout_milliseconds)
@@ -597,11 +587,9 @@ mod tests {
597
587
let build_result = unsafe {
598
588
ddog_prof_Exporter_Request_build (
599
589
Some ( exporter. as_mut ( ) ) ,
600
- start,
601
- finish,
602
- Slice :: from ( files_to_compress_and_export) ,
590
+ profile,
591
+ Slice :: empty ( ) ,
603
592
Slice :: empty ( ) ,
604
- None ,
605
593
None ,
606
594
None ,
607
595
None ,
@@ -649,19 +637,7 @@ mod tests {
649
637
ExporterNewResult :: Err ( _) => panic ! ( "Should not occur!" ) ,
650
638
} ;
651
639
652
- let files: & [ File ] = & [ File {
653
- name : CharSlice :: from ( "foo.pprof" ) ,
654
- file : ByteSlice :: from ( b"dummy contents" as & [ u8 ] ) ,
655
- } ] ;
656
-
657
- let start = Timespec {
658
- seconds : 12 ,
659
- nanoseconds : 34 ,
660
- } ;
661
- let finish = Timespec {
662
- seconds : 56 ,
663
- nanoseconds : 78 ,
664
- } ;
640
+ let profile = EncodedProfile :: test_instance ( ) . unwrap ( ) . into ( ) ;
665
641
let timeout_milliseconds = 90 ;
666
642
unsafe {
667
643
ddog_prof_Exporter_set_timeout ( Some ( exporter. as_mut ( ) ) , timeout_milliseconds)
@@ -681,14 +657,12 @@ mod tests {
681
657
let build_result = unsafe {
682
658
ddog_prof_Exporter_Request_build (
683
659
Some ( exporter. as_mut ( ) ) ,
684
- start,
685
- finish,
686
- Slice :: from ( files) ,
660
+ profile,
661
+ Slice :: empty ( ) ,
687
662
Slice :: empty ( ) ,
688
663
None ,
689
664
None ,
690
665
Some ( & raw_internal_metadata) ,
691
- None ,
692
666
)
693
667
} ;
694
668
@@ -724,19 +698,8 @@ mod tests {
724
698
ExporterNewResult :: Err ( _) => panic ! ( "Should not occur!" ) ,
725
699
} ;
726
700
727
- let files: & [ File ] = & [ File {
728
- name : CharSlice :: from ( "foo.pprof" ) ,
729
- file : ByteSlice :: from ( b"dummy contents" as & [ u8 ] ) ,
730
- } ] ;
701
+ let profile = EncodedProfile :: test_instance ( ) . unwrap ( ) . into ( ) ;
731
702
732
- let start = Timespec {
733
- seconds : 12 ,
734
- nanoseconds : 34 ,
735
- } ;
736
- let finish = Timespec {
737
- seconds : 56 ,
738
- nanoseconds : 78 ,
739
- } ;
740
703
let timeout_milliseconds = 90 ;
741
704
unsafe {
742
705
ddog_prof_Exporter_set_timeout ( Some ( exporter. as_mut ( ) ) , timeout_milliseconds)
@@ -748,11 +711,9 @@ mod tests {
748
711
let build_result = unsafe {
749
712
ddog_prof_Exporter_Request_build (
750
713
Some ( exporter. as_mut ( ) ) ,
751
- start,
752
- finish,
753
- Slice :: from ( files) ,
714
+ profile,
715
+ Slice :: empty ( ) ,
754
716
Slice :: empty ( ) ,
755
- None ,
756
717
None ,
757
718
Some ( & raw_internal_metadata) ,
758
719
None ,
@@ -787,19 +748,7 @@ mod tests {
787
748
ExporterNewResult :: Err ( _) => panic ! ( "Should not occur!" ) ,
788
749
} ;
789
750
790
- let files: & [ File ] = & [ File {
791
- name : CharSlice :: from ( "foo.pprof" ) ,
792
- file : ByteSlice :: from ( b"dummy contents" as & [ u8 ] ) ,
793
- } ] ;
794
-
795
- let start = Timespec {
796
- seconds : 12 ,
797
- nanoseconds : 34 ,
798
- } ;
799
- let finish = Timespec {
800
- seconds : 56 ,
801
- nanoseconds : 78 ,
802
- } ;
751
+ let profile = EncodedProfile :: test_instance ( ) . unwrap ( ) . into ( ) ;
803
752
let timeout_milliseconds = 90 ;
804
753
unsafe {
805
754
ddog_prof_Exporter_set_timeout ( Some ( exporter. as_mut ( ) ) , timeout_milliseconds)
@@ -840,11 +789,9 @@ mod tests {
840
789
let build_result = unsafe {
841
790
ddog_prof_Exporter_Request_build (
842
791
Some ( exporter. as_mut ( ) ) ,
843
- start,
844
- finish,
845
- Slice :: from ( files) ,
792
+ profile,
793
+ Slice :: empty ( ) ,
846
794
Slice :: empty ( ) ,
847
- None ,
848
795
None ,
849
796
None ,
850
797
Some ( & raw_info) ,
@@ -904,19 +851,7 @@ mod tests {
904
851
ExporterNewResult :: Err ( _) => panic ! ( "Should not occur!" ) ,
905
852
} ;
906
853
907
- let files: & [ File ] = & [ File {
908
- name : CharSlice :: from ( "foo.pprof" ) ,
909
- file : ByteSlice :: from ( b"dummy contents" as & [ u8 ] ) ,
910
- } ] ;
911
-
912
- let start = Timespec {
913
- seconds : 12 ,
914
- nanoseconds : 34 ,
915
- } ;
916
- let finish = Timespec {
917
- seconds : 56 ,
918
- nanoseconds : 78 ,
919
- } ;
854
+ let profile = EncodedProfile :: test_instance ( ) . unwrap ( ) . into ( ) ;
920
855
let timeout_milliseconds = 90 ;
921
856
unsafe {
922
857
ddog_prof_Exporter_set_timeout ( Some ( exporter. as_mut ( ) ) , timeout_milliseconds)
@@ -928,11 +863,9 @@ mod tests {
928
863
let build_result = unsafe {
929
864
ddog_prof_Exporter_Request_build (
930
865
Some ( exporter. as_mut ( ) ) ,
931
- start,
932
- finish,
933
- Slice :: from ( files) ,
866
+ profile,
867
+ Slice :: empty ( ) ,
934
868
Slice :: empty ( ) ,
935
- None ,
936
869
None ,
937
870
None ,
938
871
Some ( & raw_info) ,
@@ -949,26 +882,17 @@ mod tests {
949
882
950
883
#[ test]
951
884
fn test_build_failure ( ) {
952
- let start = Timespec {
953
- seconds : 12 ,
954
- nanoseconds : 34 ,
955
- } ;
956
- let finish = Timespec {
957
- seconds : 56 ,
958
- nanoseconds : 78 ,
959
- } ;
885
+ let profile = EncodedProfile :: test_instance ( ) . unwrap ( ) . into ( ) ;
960
886
961
887
let build_result = unsafe {
962
888
ddog_prof_Exporter_Request_build (
963
889
None , // No exporter, will fail
964
- start,
965
- finish,
890
+ profile,
966
891
Slice :: empty ( ) ,
967
892
Slice :: empty ( ) ,
968
893
None ,
969
894
None ,
970
895
None ,
971
- None ,
972
896
)
973
897
} ;
974
898
0 commit comments