Skip to content

Commit cc659e7

Browse files
committed
chore: jfr event throttling
1 parent 7d1c87f commit cc659e7

File tree

2 files changed

+5
-2
lines changed
  • backend/profiling/src/main/kotlin/dev/suresh
  • shared/src/jvmMain/kotlin/dev/suresh

2 files changed

+5
-2
lines changed

backend/profiling/src/main/kotlin/dev/suresh/JFR.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import kotlin.time.toJavaDuration
1616
@Category("Services", BuildConfig.name)
1717
@Period("1 s")
1818
@StackTrace(false)
19+
@Throttle("100/s")
1920
class Counter(@Label("Count") private var count: Long = 0) : Event() {
2021
fun inc() = count++
2122
}

shared/src/jvmMain/kotlin/dev/suresh/Extns.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ fun IntArray.codePointsToString(separator: String = "") =
9999
/** Adds a periodic event to the JFR stream. */
100100
inline fun <reified T : Event> addPeriodicJFREvent(event: T, crossinline block: T.() -> Unit) {
101101
FlightRecorder.addPeriodicEvent(T::class.java) {
102-
block(event)
103-
event.commit()
102+
if (event.shouldCommit()) {
103+
block(event)
104+
event.commit()
105+
}
104106
}
105107
}
106108

0 commit comments

Comments
 (0)