diff --git a/common/utils/src/main/scala/org/apache/spark/internal/LogKey.scala b/common/utils/src/main/scala/org/apache/spark/internal/LogKey.scala index 12d456a371d07..c365797cec690 100644 --- a/common/utils/src/main/scala/org/apache/spark/internal/LogKey.scala +++ b/common/utils/src/main/scala/org/apache/spark/internal/LogKey.scala @@ -692,6 +692,7 @@ private[spark] object LogKeys { case object RPC_ENDPOINT_REF extends LogKey case object RPC_MESSAGE_CAPACITY extends LogKey case object RPC_SSL_ENABLED extends LogKey + case object RULE_EXECUTOR_NAME extends LogKey case object RULE_NAME extends LogKey case object RUN_ID extends LogKey case object SCALA_VERSION extends LogKey diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala index 256e1440122d8..76d36fab2096a 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/rules/RuleExecutor.scala @@ -87,13 +87,13 @@ class PlanChangeLogger[TreeType <: TreeNode[_]] extends Logging { } } - def logMetrics(metrics: QueryExecutionMetrics): Unit = { + def logMetrics(name: String, metrics: QueryExecutionMetrics): Unit = { val totalTime = metrics.time / NANOS_PER_MILLIS.toDouble val totalTimeEffective = metrics.timeEffective / NANOS_PER_MILLIS.toDouble // scalastyle:off line.size.limit val message: MessageWithContext = log""" - |=== Metrics of Executed Rules === + |=== Metrics of Executed Rules ${MDC(RULE_EXECUTOR_NAME, name)} === |Total number of runs: ${MDC(NUM_RULE_OF_RUNS, metrics.numRuns)} |Total time: ${MDC(TOTAL_TIME, totalTime)} ms |Total number of effective runs: ${MDC(NUM_EFFECTIVE_RULE_OF_RUNS, metrics.numEffectiveRuns)} @@ -118,6 +118,12 @@ class PlanChangeLogger[TreeType <: TreeNode[_]] extends Logging { abstract class RuleExecutor[TreeType <: TreeNode[_]] extends Logging { + /** Name for this rule executor, automatically inferred based on class name. */ + protected def name: String = { + val className = getClass.getName + if (className endsWith "$") className.dropRight(1) else className + } + /** * An execution strategy for rules that indicates the maximum number of executions. If the * execution reaches fix point (i.e. converge) before maxIterations, it will stop. @@ -307,7 +313,7 @@ abstract class RuleExecutor[TreeType <: TreeNode[_]] extends Logging { planChangeLogger.logBatch(batch.name, batchStartPlan, curPlan) } - planChangeLogger.logMetrics(RuleExecutor.getCurrentMetrics() - beforeMetrics) + planChangeLogger.logMetrics(name, RuleExecutor.getCurrentMetrics() - beforeMetrics) curPlan }