@@ -180,7 +180,7 @@ fn compile_probe(
180180 #[ cfg( not( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ) ]
181181 compile_error ! ( "USDT only supports x86_64 and AArch64 architectures" ) ;
182182
183- let impl_block = quote ! {
183+ let extern_block = quote ! {
184184 unsafe extern "C" {
185185 #[ allow( unused) ]
186186 #[ link_name = #stability]
@@ -198,26 +198,43 @@ fn compile_probe(
198198 #[ link_name = #probe]
199199 fn #extern_probe_fn( #( #ffi_param_list, ) * ) ;
200200 }
201+ } ;
202+
203+ let call = quote ! {
201204 unsafe {
202- if #is_enabled_fn( ) != 0 {
203- #arg_lambda
204- #type_check_fn
205- #unpacked_args
206- :: std:: arch:: asm!(
207- ".reference {typedefs}" ,
208- #call_instruction,
209- ".reference {stability}" ,
210- typedefs = sym #typedef_fn,
211- extern_probe_fn = sym #extern_probe_fn,
212- stability = sym #stability_fn,
213- #in_regs
214- options( nomem, nostack, preserves_flags)
215- ) ;
216- }
205+ :: std:: arch:: asm!(
206+ ".reference {typedefs}" ,
207+ #call_instruction,
208+ ".reference {stability}" ,
209+ typedefs = sym #typedef_fn,
210+ extern_probe_fn = sym #extern_probe_fn,
211+ stability = sym #stability_fn,
212+ #in_regs
213+ options( nomem, nostack, preserves_flags)
214+ ) ;
215+ }
216+ } ;
217+
218+ let eager = quote ! {
219+ #extern_block
220+ #arg_lambda
221+ #type_check_fn
222+ #unpacked_args
223+ #call
224+ } ;
225+
226+ let lazy = quote ! {
227+ #extern_block
228+ if unsafe { #is_enabled_fn( ) } != 0 {
229+ :: usdt:: cold( ) ;
230+ #arg_lambda
231+ #type_check_fn
232+ #unpacked_args
233+ #call
217234 }
218235 } ;
219236
220- common:: build_probe_macro ( config, probe_name, types, impl_block )
237+ common:: build_probe_macro ( config, probe_name, types, eager , lazy )
221238}
222239
223240#[ derive( Debug , Default , Clone ) ]
0 commit comments