diff --git a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/kyuubi/SQLOperationListener.scala b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/kyuubi/SQLOperationListener.scala index 0bf7de9e3ea..4342c0c7fbe 100644 --- a/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/kyuubi/SQLOperationListener.scala +++ b/externals/kyuubi-spark-sql-engine/src/main/scala/org/apache/spark/kyuubi/SQLOperationListener.scala @@ -149,14 +149,6 @@ class SQLOperationListener( val stageInfo = stageCompleted.stageInfo val stageId = stageInfo.stageId val stageAttempt = SparkStageAttempt(stageInfo.stageId, stageInfo.attemptNumber()) - val taskMetrics = stageInfo.taskMetrics - if (taskMetrics != null) { - info(s"stageId=${stageCompleted.stageInfo.stageId}, " + - s"stageRunTime=${formatDuration(taskMetrics.executorRunTime)}, " + - s"stageCpuTime=${formatDuration(taskMetrics.executorCpuTime / 1000000)}") - operationRunTime.getAndAdd(taskMetrics.executorRunTime) - operationCpuTime.getAndAdd(taskMetrics.executorCpuTime) - } activeStages.synchronized { if (activeStages.remove(stageAttempt) != null) { stageInfo.getStatusString match { @@ -167,6 +159,14 @@ class SQLOperationListener( } } } + val taskMetrics = stageInfo.taskMetrics + if (taskMetrics != null) { + info(s"stageId=${stageCompleted.stageInfo.stageId}, " + + s"stageRunTime=${formatDuration(taskMetrics.executorRunTime)}, " + + s"stageCpuTime=${formatDuration(taskMetrics.executorCpuTime / 1000000)}") + operationRunTime.getAndAdd(taskMetrics.executorRunTime) + operationCpuTime.getAndAdd(taskMetrics.executorCpuTime) + } withOperationLog(super.onStageCompleted(stageCompleted)) } }