parthchandra commented on code in PR #3708: URL: https://github.com/apache/datafusion-comet/pull/3708#discussion_r2956956075
########## spark/src/main/scala/org/apache/spark/CometSource.scala: ########## @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.spark + +import org.apache.spark.metrics.source.Source + +import com.codahale.metrics.{Counter, Gauge, MetricRegistry} + +import org.apache.comet.CometCoverageStats + +/** + * Exposes following metrics (hooked from CometCoverageStats) + * - operators.native: Total operators executed natively + * - operators.spark: Total operators that fell back to Spark + * - queries.planned: Total queries processed + * - transitions: Total Spark-to-Comet transitions + * - acceleration.ratio: native / (native + spark) + */ +object CometSource extends Source { + override val sourceName = "comet" + override val metricRegistry = new MetricRegistry() + + val NATIVE_OPERATORS: Counter = + metricRegistry.counter(MetricRegistry.name("operators", "native")) + val SPARK_OPERATORS: Counter = metricRegistry.counter(MetricRegistry.name("operators", "spark")) + val QUERIES_PLANNED: Counter = metricRegistry.counter(MetricRegistry.name("queries", "planned")) + val TRANSITIONS: Counter = metricRegistry.counter(MetricRegistry.name("transitions")) + + metricRegistry.register( + MetricRegistry.name("acceleration", "ratio"), + new Gauge[Double] { + override def getValue: Double = { + val native = NATIVE_OPERATORS.getCount + val total = native + SPARK_OPERATORS.getCount + if (total > 0) native.toDouble / total else 0.0 + } + }) + + def recordStats(stats: CometCoverageStats): Unit = { Review Comment: I wasn't saying the approach is wrong. Just pointing out that for these specific metrics, if the Spark application has multiple plans, the accumulated values are not necessarily meaningful. -- 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]
