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
+ profile : * mut 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,20 @@ pub unsafe extern "C" fn ddog_prof_Exporter_Request_build(
290
289
Err ( err) => return RequestBuildResult :: Err ( err. into ( ) ) ,
291
290
} ;
292
291
292
+ if profile. is_null ( ) {
293
+ return RequestBuildResult :: Err ( anyhow:: anyhow!( "profile pointer was null" ) . into ( ) ) ;
294
+ }
295
+
296
+ let profile = match ( * profile) . take ( ) {
297
+ Ok ( p) => * p,
298
+ Err ( e) => return RequestBuildResult :: Err ( e. into ( ) ) ,
299
+ } ;
300
+
293
301
match exporter. build (
294
- start. into ( ) ,
295
- end. into ( ) ,
302
+ profile,
296
303
files_to_compress_and_export. as_slice ( ) ,
297
304
files_to_export_unmodified. as_slice ( ) ,
298
305
tags. as_ref ( ) ,
299
- optional_endpoints_stats,
300
306
internal_metadata,
301
307
info,
302
308
) {
@@ -575,19 +581,7 @@ mod tests {
575
581
ExporterNewResult :: Err ( _) => panic ! ( "Should not occur!" ) ,
576
582
} ;
577
583
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
- } ;
584
+ let profile = & mut EncodedProfile :: test_instance ( ) . unwrap ( ) . into ( ) ;
591
585
let timeout_milliseconds = 90 ;
592
586
unsafe {
593
587
ddog_prof_Exporter_set_timeout ( Some ( exporter. as_mut ( ) ) , timeout_milliseconds)
@@ -597,11 +591,9 @@ mod tests {
597
591
let build_result = unsafe {
598
592
ddog_prof_Exporter_Request_build (
599
593
Some ( exporter. as_mut ( ) ) ,
600
- start,
601
- finish,
602
- Slice :: from ( files_to_compress_and_export) ,
594
+ profile,
595
+ Slice :: empty ( ) ,
603
596
Slice :: empty ( ) ,
604
- None ,
605
597
None ,
606
598
None ,
607
599
None ,
@@ -610,7 +602,7 @@ mod tests {
610
602
611
603
let parsed_event_json = parsed_event_json ( build_result) ;
612
604
613
- assert_eq ! ( parsed_event_json[ "attachments" ] , json!( [ "foo .pprof" ] ) ) ;
605
+ assert_eq ! ( parsed_event_json[ "attachments" ] , json!( [ "profile .pprof" ] ) ) ;
614
606
assert_eq ! ( parsed_event_json[ "endpoint_counts" ] , json!( null) ) ;
615
607
assert_eq ! (
616
608
parsed_event_json[ "start" ] ,
@@ -649,19 +641,7 @@ mod tests {
649
641
ExporterNewResult :: Err ( _) => panic ! ( "Should not occur!" ) ,
650
642
} ;
651
643
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
- } ;
644
+ let profile = & mut EncodedProfile :: test_instance ( ) . unwrap ( ) . into ( ) ;
665
645
let timeout_milliseconds = 90 ;
666
646
unsafe {
667
647
ddog_prof_Exporter_set_timeout ( Some ( exporter. as_mut ( ) ) , timeout_milliseconds)
@@ -681,11 +661,9 @@ mod tests {
681
661
let build_result = unsafe {
682
662
ddog_prof_Exporter_Request_build (
683
663
Some ( exporter. as_mut ( ) ) ,
684
- start,
685
- finish,
686
- Slice :: from ( files) ,
664
+ profile,
665
+ Slice :: empty ( ) ,
687
666
Slice :: empty ( ) ,
688
- None ,
689
667
None ,
690
668
Some ( & raw_internal_metadata) ,
691
669
None ,
@@ -724,19 +702,8 @@ mod tests {
724
702
ExporterNewResult :: Err ( _) => panic ! ( "Should not occur!" ) ,
725
703
} ;
726
704
727
- let files: & [ File ] = & [ File {
728
- name : CharSlice :: from ( "foo.pprof" ) ,
729
- file : ByteSlice :: from ( b"dummy contents" as & [ u8 ] ) ,
730
- } ] ;
705
+ let profile = & mut EncodedProfile :: test_instance ( ) . unwrap ( ) . into ( ) ;
731
706
732
- let start = Timespec {
733
- seconds : 12 ,
734
- nanoseconds : 34 ,
735
- } ;
736
- let finish = Timespec {
737
- seconds : 56 ,
738
- nanoseconds : 78 ,
739
- } ;
740
707
let timeout_milliseconds = 90 ;
741
708
unsafe {
742
709
ddog_prof_Exporter_set_timeout ( Some ( exporter. as_mut ( ) ) , timeout_milliseconds)
@@ -748,11 +715,9 @@ mod tests {
748
715
let build_result = unsafe {
749
716
ddog_prof_Exporter_Request_build (
750
717
Some ( exporter. as_mut ( ) ) ,
751
- start,
752
- finish,
753
- Slice :: from ( files) ,
718
+ profile,
719
+ Slice :: empty ( ) ,
754
720
Slice :: empty ( ) ,
755
- None ,
756
721
None ,
757
722
Some ( & raw_internal_metadata) ,
758
723
None ,
@@ -787,19 +752,7 @@ mod tests {
787
752
ExporterNewResult :: Err ( _) => panic ! ( "Should not occur!" ) ,
788
753
} ;
789
754
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
- } ;
755
+ let profile = & mut EncodedProfile :: test_instance ( ) . unwrap ( ) . into ( ) ;
803
756
let timeout_milliseconds = 90 ;
804
757
unsafe {
805
758
ddog_prof_Exporter_set_timeout ( Some ( exporter. as_mut ( ) ) , timeout_milliseconds)
@@ -840,11 +793,9 @@ mod tests {
840
793
let build_result = unsafe {
841
794
ddog_prof_Exporter_Request_build (
842
795
Some ( exporter. as_mut ( ) ) ,
843
- start,
844
- finish,
845
- Slice :: from ( files) ,
796
+ profile,
797
+ Slice :: empty ( ) ,
846
798
Slice :: empty ( ) ,
847
- None ,
848
799
None ,
849
800
None ,
850
801
Some ( & raw_info) ,
@@ -904,19 +855,7 @@ mod tests {
904
855
ExporterNewResult :: Err ( _) => panic ! ( "Should not occur!" ) ,
905
856
} ;
906
857
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
- } ;
858
+ let profile = & mut EncodedProfile :: test_instance ( ) . unwrap ( ) . into ( ) ;
920
859
let timeout_milliseconds = 90 ;
921
860
unsafe {
922
861
ddog_prof_Exporter_set_timeout ( Some ( exporter. as_mut ( ) ) , timeout_milliseconds)
@@ -928,11 +867,9 @@ mod tests {
928
867
let build_result = unsafe {
929
868
ddog_prof_Exporter_Request_build (
930
869
Some ( exporter. as_mut ( ) ) ,
931
- start,
932
- finish,
933
- Slice :: from ( files) ,
870
+ profile,
871
+ Slice :: empty ( ) ,
934
872
Slice :: empty ( ) ,
935
- None ,
936
873
None ,
937
874
None ,
938
875
Some ( & raw_info) ,
@@ -949,26 +886,17 @@ mod tests {
949
886
950
887
#[ test]
951
888
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
- } ;
889
+ let profile = & mut EncodedProfile :: test_instance ( ) . unwrap ( ) . into ( ) ;
960
890
961
891
let build_result = unsafe {
962
892
ddog_prof_Exporter_Request_build (
963
893
None , // No exporter, will fail
964
- start,
965
- finish,
894
+ profile,
966
895
Slice :: empty ( ) ,
967
896
Slice :: empty ( ) ,
968
897
None ,
969
898
None ,
970
899
None ,
971
- None ,
972
900
)
973
901
} ;
974
902
0 commit comments