MCPcopy Create free account
hub / github.com/apache/datafusion / trace_block

Function trace_block

datafusion/common-runtime/src/trace_utils.rs:167–188  ·  view source on GitHub ↗

Optionally instruments a blocking closure with custom tracing. If a tracer has been injected via `set_tracer`, the closure is wrapped so that its return value is boxed (erasing its type), passed to the tracer, and then the result is downcast back to the original type. If no tracer is set, the closure is returned unmodified (except for being boxed). # Type Parameters `T` - The concrete return typ

(f: F)

Source from the content-addressed store, hash-verified

165/// # Parameters
166/// * `f` - The blocking closure to potentially instrument.
167pub fn trace_block<T, F>(f: F) -> Box<dyn FnOnce() -> T + Send>
168where
169 F: FnOnce() -> T + Send + 'static,
170 T: Send + 'static,
171{
172 // Erase the closure’s return type first:
173 let erased_closure = Box::new(|| {
174 let result = f();
175 Box::new(result) as Box<dyn Any + Send>
176 });
177
178 // Forward through the global tracer:
179 let traced_closure = get_tracer().trace_block(erased_closure);
180
181 // Downcast from `Box<dyn Any + Send>` back to `T`:
182 Box::new(move || {
183 let any_box = traced_closure();
184 *any_box
185 .downcast::<T>()
186 .expect("Tracer must preserve the closure’s return type!")
187 })
188}

Callers 3

spawn_blockingMethod · 0.85
spawn_blockingMethod · 0.85
spawn_blocking_onMethod · 0.85

Calls 3

newFunction · 0.85
get_tracerFunction · 0.85
trace_blockMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…