chia7712 commented on a change in pull request #8836:
URL: https://github.com/apache/kafka/pull/8836#discussion_r440078358



##########
File path: core/src/main/scala/kafka/tools/ConsumerPerformance.scala
##########
@@ -45,40 +45,47 @@ object ConsumerPerformance extends LazyLogging {
     val totalMessagesRead = new AtomicLong(0)
     val totalBytesRead = new AtomicLong(0)
     var metrics: mutable.Map[MetricName, _ <: Metric] = null
-    val joinGroupTimeInMs = new AtomicLong(0)
+    var joinGroupTimeInMs: Double = 0
 
     if (!config.hideHeader)
       printHeader(config.showDetailedStats)
 
     var startMs, endMs = 0L
     val consumer = new KafkaConsumer[Array[Byte], Array[Byte]](config.props)
+    metrics = consumer.metrics.asScala
     startMs = System.currentTimeMillis
-    consume(consumer, List(config.topic), config.numMessages, 
config.recordFetchTimeoutMs, config, totalMessagesRead, totalBytesRead, 
joinGroupTimeInMs, startMs)
+    consume(consumer, List(config.topic), config.numMessages, 
config.recordFetchTimeoutMs, config, totalMessagesRead, totalBytesRead, 
startMs, metrics)
     endMs = System.currentTimeMillis
 
-    if (config.printMetrics) {
-      metrics = consumer.metrics.asScala
+    breakable {

Review comment:
       Could you use ```find``` to replace the ```break```? for example:
   ```scala
       metrics.find {
         case (name, _) => name.name() == "rebalance-latency-avg"
       }.map {
         case (_, metric) => joinGroupTimeInMs = 
metric.metricValue.asInstanceOf[Double]
       }.getOrElse(0)
   ```




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to