tschwarzinger commented on issue #19658:
URL: https://github.com/apache/datafusion/issues/19658#issuecomment-4646384824

   Is there anything special about how `AsyncFuncExec` works? I've just 
stumbled across this issue and thought whether simply wrapping the future 
returned by `invoke_with_args` using something like this:
   
   ```rust
   /// A wrapper that measures the CPU time spent actively polling.
   struct MeasurePoll<F> {
       inner: Pin<Box<F>>,
       time_metric: Time,
   }
   
   impl<F: Future> Future for MeasurePoll<F> {
       type Output = F::Output;
   
       fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> 
Poll<Self::Output> {
           let cloned_inner = self.time_metric.clone();
           let handle = cloned_inner.timer();
           let result = self.inner.as_mut().poll(cx);
           drop(handle);
           result
       }
   }
   ```
   
   The intent of this wrapper is to stop the timer every time `Poll::Pending` 
is being returned.
   
   We've used it like this but we have not tested this thoroughly so there 
might be an issue with this approach.
   
   ```rust
   let physical_plan_future = state
           .query_planner()
           .create_physical_plan(&optimized_plan, &state);
       let physical_plan = MeasurePoll {
           inner: Box::pin(physical_plan_future),
           time_metric: planning_compute.clone(),
       }
       .await?;
   
       let planning_compute_nanos =
           u64::try_from(planning_compute.value()).unwrap_or(u64::MAX);
       let explanation = QueryExplanation {
           planning_latency: planning_time_start.elapsed(),
           planning_compute: Duration::from_nanos(planning_compute_nanos),
           initial_logical_plan: logical_plan,
           optimized_logical_plan: optimized_plan,
           execution_plan: Arc::clone(&physical_plan),
       };
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to