Skip to content

Commit 17c8187

Browse files
noctellajenkins
authored andcommitted
util/util-jvm: Add gc pause stats for all collectors
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
1 parent c1570b0 commit 17c8187

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ Note that ``PHAB_ID=#`` and ``RB_ID=#`` correspond to associated messages in com
77
Unreleased
88
----------
99

10+
New Features
11+
~~~~~~~~~~~~
12+
13+
* util-jvm: Add gc pause stats for all collector pools, including G1. ``PHAB_ID=D1176049``
14+
15+
1016
24.5.0
1117
------
1218

util-jvm/src/main/scala/com/twitter/jvm/JvmStats.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.twitter.jvm
22

3+
import com.sun.management.GarbageCollectionNotificationInfo
34
import com.twitter.conversions.StringOps._
45
import com.twitter.finagle.stats.MetricBuilder.GaugeType
56
import com.twitter.finagle.stats.Bytes
@@ -9,6 +10,10 @@ import com.twitter.finagle.stats.exp.Expression
910
import com.twitter.finagle.stats.exp.ExpressionSchema
1011
import java.lang.management.BufferPoolMXBean
1112
import java.lang.management.ManagementFactory
13+
import javax.management.Notification
14+
import javax.management.NotificationEmitter
15+
import javax.management.NotificationListener
16+
import javax.management.openmbean.CompositeData
1217
import scala.collection.mutable
1318
import scala.jdk.CollectionConverters._
1419

@@ -186,6 +191,26 @@ object JvmStats {
186191
gc.getCollectionTime.toFloat
187192
}
188193

194+
val gcPauseStat = gcStats.stat(name, "pause_msec")
195+
gc.asInstanceOf[NotificationEmitter].addNotificationListener(
196+
new NotificationListener {
197+
override def handleNotification(
198+
notification: Notification,
199+
handback: Any
200+
): Unit = {
201+
notification.getType
202+
if (notification.getType == GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION) {
203+
gcPauseStat.add(
204+
GarbageCollectionNotificationInfo
205+
.from(notification.getUserData
206+
.asInstanceOf[CompositeData]).getGcInfo.getDuration)
207+
}
208+
}
209+
},
210+
null,
211+
null
212+
)
213+
189214
gcStats.registerExpression(
190215
ExpressionSchema(s"gc_cycles", Expression(poolCycles.metadata))
191216
.withLabel(ExpressionSchema.Role, "jvm")

0 commit comments

Comments
 (0)