Skip to content

Commit

Permalink
util/util-jvm: Add gc pause stats for all collectors
Browse files Browse the repository at this point in the history
Problem

Currently we only have gc pause stats for the ParNew collector, but
we'd like to be able to see this information for the G1 pools.

Solution

Add collection duration stats for all collector pools. Keep the jvm/gc/eden/pause_msec
stat for compatibility, but this will be the same as jvm/gc/ParNew/pause_msec.

Differential Revision: https://phabricator.twitter.biz/D1176049
  • Loading branch information
jcrossley authored and jenkins committed Oct 11, 2024
1 parent c1570b0 commit 17c8187
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Note that ``PHAB_ID=#`` and ``RB_ID=#`` correspond to associated messages in com
Unreleased
----------

New Features
~~~~~~~~~~~~

* util-jvm: Add gc pause stats for all collector pools, including G1. ``PHAB_ID=D1176049``


24.5.0
------

Expand Down
25 changes: 25 additions & 0 deletions util-jvm/src/main/scala/com/twitter/jvm/JvmStats.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.twitter.jvm

import com.sun.management.GarbageCollectionNotificationInfo
import com.twitter.conversions.StringOps._
import com.twitter.finagle.stats.MetricBuilder.GaugeType
import com.twitter.finagle.stats.Bytes
Expand All @@ -9,6 +10,10 @@ import com.twitter.finagle.stats.exp.Expression
import com.twitter.finagle.stats.exp.ExpressionSchema
import java.lang.management.BufferPoolMXBean
import java.lang.management.ManagementFactory
import javax.management.Notification
import javax.management.NotificationEmitter
import javax.management.NotificationListener
import javax.management.openmbean.CompositeData
import scala.collection.mutable
import scala.jdk.CollectionConverters._

Expand Down Expand Up @@ -186,6 +191,26 @@ object JvmStats {
gc.getCollectionTime.toFloat
}

val gcPauseStat = gcStats.stat(name, "pause_msec")
gc.asInstanceOf[NotificationEmitter].addNotificationListener(
new NotificationListener {
override def handleNotification(
notification: Notification,
handback: Any
): Unit = {
notification.getType
if (notification.getType == GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION) {
gcPauseStat.add(
GarbageCollectionNotificationInfo
.from(notification.getUserData
.asInstanceOf[CompositeData]).getGcInfo.getDuration)
}
}
},
null,
null
)

gcStats.registerExpression(
ExpressionSchema(s"gc_cycles", Expression(poolCycles.metadata))
.withLabel(ExpressionSchema.Role, "jvm")
Expand Down

0 comments on commit 17c8187

Please sign in to comment.