LantaoJin commented on a change in pull request #22874: [SPARK-25865][CORE] Add GC information to ExecutorMetrics URL: https://github.com/apache/spark/pull/22874#discussion_r245867274
########## File path: core/src/main/scala/org/apache/spark/metrics/ExecutorMetricType.scala ########## @@ -99,6 +102,60 @@ case object ProcessTreeMetrics extends ExecutorMetricType { } } +case object GarbageCollectionMetrics extends ExecutorMetricType with Logging { + import GC_TYPE._ + override val names = Seq( + "MinorGCCount", + "MinorGCTime", + "MajorGCCount", + "MajorGCTime" + ) + + private lazy val youngGenGarbageCollector: Seq[String] = { + Seq(`copy`, `psScavenge`, `parNew`, `g1Young`) ++ /* additional young gc we added */ + SparkEnv.get.conf.get(config.EVENT_LOG_ADDITIONAL_YOUNG_GENERATION_GARBAGE_COLLECTORS) + } + + private lazy val oldGenGarbageCollector: Seq[String] = { + Seq(`markSweepCompact`, `psMarkSweep`, `cms`, `g1Old`) ++ /* additional old gc we added */ + SparkEnv.get.conf.get(config.EVENT_LOG_ADDITIONAL_OLD_GENERATION_GARBAGE_COLLECTORS) + } + + override private[spark] def getMetricValues(memoryManager: MemoryManager): Array[Long] = { + val gcMetrics = Array[Long](names.length) // minorCount, minorTime, majorCount, majorTime + if (SparkEnv.get.conf.get(config.EVENT_LOG_GARBAGE_COLLECTION_METRICS)) { + ManagementFactory.getGarbageCollectorMXBeans.asScala.foreach { mxBean => + if (youngGenGarbageCollector.contains(mxBean.getName)) { + gcMetrics(0) = mxBean.getCollectionCount + gcMetrics(1) = mxBean.getCollectionTime + } else if (oldGenGarbageCollector.contains(mxBean.getName)) { + gcMetrics(2) = mxBean.getCollectionCount + gcMetrics(3) = mxBean.getCollectionTime + } else { + logDebug(s"${mxBean.getName} is an unsupported garbage collector." + + s"Add it to ${config.EVENT_LOG_ADDITIONAL_YOUNG_GENERATION_GARBAGE_COLLECTORS} " + + s"or ${config.EVENT_LOG_ADDITIONAL_OLD_GENERATION_GARBAGE_COLLECTORS} to enable.") + } + } + } + gcMetrics + } +} + +private[spark] object GC_TYPE { + // Young Gen + val copy = "Copy" + val psScavenge = "PS Scavenge" + val parNew = "ParNew" + val g1Young = "G1 Young Generation" + + // Old Gen + val markSweepCompact = "MarkSweepCompact" + val psMarkSweep = "PS MarkSweep" + val cms = "ConcurrentMarkSweep" + val g1Old = "G1 Old Generation" Review comment: Yes, I will use two Seqs instead. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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 With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org