Yicong-Huang commented on code in PR #59246:
URL: https://github.com/apache/spark/pull/59246#discussion_r4192015495


##########
python/pyspark/eval_handlers/_pandas.py:
##########
@@ -66,6 +68,21 @@ def __init__(
         self._return_schema = StructType(
             [StructField("_%d" % i, rt) for i, (_, _, _, rt) in 
enumerate(udfs)]
         )
+        self._input_timer: ContextManager[None] = nullcontext()
+        self._udf_timer: ContextManager[None] = nullcontext()
+        self._output_timer: ContextManager[None] = nullcontext()
+
+    def set_worker_metrics(self, metrics: "WorkerMetrics") -> None:
+        super().set_worker_metrics(metrics)
+        # Bind scopes once per task; each batch reuses them without creating 
new timers.
+        # These phases run on the main thread even when a reader thread 
prefetches input.
+        # The callback timer includes profiling work when a profiler wraps the 
UDF.
+        self._input_timer = metrics.measure("pythonInputConversionTime")
+        self._udf_timer = metrics.measure("pythonUDFExecutionTime")
+        self._output_timer = metrics.measure("pythonOutputConversionTime")
+        # Advertise timing support even when the task has no input batches.
+        metrics.set("pythonNumTimingReports", 1)
+        metrics.set("pythonNumTimedBatches", 0)

Review Comment:
   this is general metrics (not specific to pandas) right?
   
   can we either define metrics collection on worker, or on the base handler 
instead, so that it is general enough?



-- 
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