Skip to content

Commit

Permalink
Merge pull request #19 from cdsap/updating_zgc_support
Browse files Browse the repository at this point in the history
Updating zgc support
  • Loading branch information
cdsap committed May 5, 2023
2 parents 438ceb2 + 78cf437 commit 263e287
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 48 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Apply the plugin in the main `build.gradle(.kts)` configuration file:
Using the plugins DSL:
``` groovy
plugins {
id("io.github.cdsap.kotlinprocess") version "0.1.3"
id("io.github.cdsap.kotlinprocess") version "0.1.4"
}
```

Expand All @@ -20,7 +20,7 @@ buildscript {
gradlePluginPortal()
}
dependencies {
classpath("io.github.cdsap:infokotlinprocess:0.1.3")
classpath("io.github.cdsap:infokotlinprocess:0.1.4")
}
}
Expand All @@ -31,7 +31,7 @@ apply(plugin = "io.github.cdsap.kotlinprocess")
Using the plugins DSL:
``` groovy
plugins {
id "io.github.cdsap.kotlinprocess" version "0.1.3"
id "io.github.cdsap.kotlinprocess" version "0.1.4"
}
```
Expand All @@ -43,7 +43,7 @@ buildscript {
gradlePluginPortal()
}
dependencies {
classpath "io.github.cdsap:infokotlinprocess:0.1.3"
classpath "io.github.cdsap:infokotlinprocess:0.1.4"
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "io.github.cdsap"
version = "0.1.3"
version = "0.1.4"

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ConsolidateProcesses {
capacity = jStatData[it.key]?.capacity?.toGigsFromKb()!!,
gcTime = jStatData[it.key]?.gcTime?.toMinutes()!!,
uptime = jStatData[it.key]?.uptime?.toMinutes()!!,
type = jStatData[it.key]?.typeGC!!
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ data class Process(
val usage: Double,
val capacity: Double,
val gcTime: Double,
val uptime: Double
val uptime: Double,
val type: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ data class ProcessJstat(
val usage: Double,
val capacity: Double,
val gcTime: Double,
val uptime: Double
val uptime: Double,
val typeGC: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class BuildScanOutput(
"Kotlin-Process-${it.pid}-gcTime",
"${it.gcTime} minutes"
)
buildScanExtension.value(
"Kotlin-Process-${it.pid}-gcType",
it.type
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ConsoleOutput(private val processes: List<Process>) {
body {
row {
cell("Kotlin processes") {
columnSpan = 6
columnSpan = 7
}
}
row {
Expand All @@ -27,6 +27,7 @@ class ConsoleOutput(private val processes: List<Process>) {
cell("Usage")
cell("Capacity")
cell("GC Time")
cell("GC Type")
cell("Uptime")
}

Expand All @@ -37,6 +38,7 @@ class ConsoleOutput(private val processes: List<Process>) {
cell("${it.usage} Gb")
cell("${it.capacity} Gb")
cell("${it.gcTime} minutes")
cell(it.type)
cell("${it.uptime} minutes")
}
}
Expand Down
125 changes: 98 additions & 27 deletions src/main/kotlin/io/github/cdsap/kotlinprocess/parser/JStatData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class JStatData {
val rawHeaders = lines[currentIndex].split("\\s+".toRegex()).filter { it != "" }
val rawValues = lines[++currentIndex].split("\\s+".toRegex()).filter { it != "" }

val (headers, value) = removeConcurrentGCTimes(rawHeaders, rawValues)
val typeOfCollector = getCollector(rawHeaders, rawValues)

val (headers, value) = preparePairsByCollector(typeOfCollector, rawHeaders, rawValues)

if (headers.size == value.size && checkValuesAraValid(value)) {
val process = lines[++currentIndex].split("\\s+".toRegex())
Expand All @@ -35,39 +37,94 @@ class JStatData {
aux++
}
processes[process.first()] = ProcessJstat(
capacity = totalCapacity(jspMapValues),
usage = usage(jspMapValues),
capacity = totalCapacity(typeOfCollector, jspMapValues),
usage = usage(typeOfCollector, jspMapValues),
gcTime = gcTime(jspMapValues),
uptime = uptime(jspMapValues)
uptime = uptime(jspMapValues),
typeGC = typeOfCollector.name
)

}
}
return processes
}

// When using ParallelGC argument concurrent gc times are not informed, generating an output like
//Timestamp S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT CGC CGCT GCT
// 298.0 22.0 20.0 0.0 0.0 1.0 1.8 1.0 0.9 4.0 8.3 6.0 5.0 4 0.3 4 0.7 - - 1
// We need to remove the entries CGC and CGCT from the headers and values
private fun removeConcurrentGCTimes(
private fun getCollector(rawHeaders: List<String>, rawValues: List<String>): TypeCollector {
val socHeaderPosition = rawHeaders.indexOf("S0C")
val soc = rawValues[socHeaderPosition]
if (soc == "-") {
return TypeCollector.Z
} else {
val socCGC = rawHeaders.indexOf("CGC")
val cgc = rawValues[socCGC]
if (cgc == "-") {
return TypeCollector.PARALLEL
} else {
return TypeCollector.G1
}
}
}

private fun preparePairsByCollector(
typeOfCollector: TypeCollector,
rawHeaders: List<String>,
rawValues: List<String>
): Pair<List<String>, List<String>> {
return if (rawHeaders.contains("CGC") && rawHeaders.contains("CGCT")
&& rawHeaders.size == rawValues.size ) {
val concurrentGCTime = rawHeaders.indexOf("CGC")
val concurrentGCTimeTotal = rawHeaders.indexOf("CGCT")

val headers = rawHeaders.toMutableList()
headers.removeAt(concurrentGCTime)
headers.removeAt(concurrentGCTimeTotal - 1)
val value = rawValues.toMutableList()
value.removeAt(concurrentGCTime)
value.removeAt(concurrentGCTimeTotal - 1)
Pair(headers.toList(), value.toList())
} else {
Pair(rawHeaders, rawValues)
when (typeOfCollector) {
TypeCollector.G1 -> {
return Pair(rawHeaders, rawValues)
}

TypeCollector.PARALLEL -> {
val concurrentGCTime = rawHeaders.indexOf("CGC")
val concurrentGCTimeTotal = rawHeaders.indexOf("CGCT")

val headers = rawHeaders.toMutableList()
headers.removeAt(concurrentGCTime)
headers.removeAt(concurrentGCTimeTotal - 1)
val value = rawValues.toMutableList()
value.removeAt(concurrentGCTime)
value.removeAt(concurrentGCTimeTotal - 1)
return Pair(headers.toList(), value.toList())
}

TypeCollector.Z -> {
val soc = rawHeaders.indexOf("S0C")
val s1c = rawHeaders.indexOf("S1C")
val sou = rawHeaders.indexOf("S0U")
val s1u = rawHeaders.indexOf("S1U")
val ec = rawHeaders.indexOf("EC")
val eu = rawHeaders.indexOf("EU")
val ygc = rawHeaders.indexOf("YGC")
val ygct = rawHeaders.indexOf("YGCT")
val fgc = rawHeaders.indexOf("FGC")
val fgct = rawHeaders.indexOf("FGCT")

val headers = rawHeaders.toMutableList()
headers.removeAt(soc)
headers.removeAt(s1c - 1)
headers.removeAt(sou - 2)
headers.removeAt(s1u - 3)
headers.removeAt(ec - 4)
headers.removeAt(eu - 5)
headers.removeAt(ygc - 6)
headers.removeAt(ygct - 7)
headers.removeAt(fgc - 8)
headers.removeAt(fgct - 9)

val value = rawValues.toMutableList()
value.removeAt(soc)
value.removeAt(s1c - 1)
value.removeAt(sou - 2)
value.removeAt(s1u - 3)
value.removeAt(ec - 4)
value.removeAt(eu - 5)
value.removeAt(ygc - 6)
value.removeAt(ygct - 7)
value.removeAt(fgc - 8)
value.removeAt(fgct - 9)
return Pair(headers.toList(), value.toList())
}
}
}

Expand All @@ -82,12 +139,20 @@ class JStatData {
return true
}

private fun totalCapacity(jspMapValues: Map<String, Double>): Double {
return jspMapValues["EC"]!! + jspMapValues["OC"]!! + jspMapValues["S0C"]!! + jspMapValues["S1C"]!!
private fun totalCapacity(typeOfCollector: TypeCollector, jspMapValues: Map<String, Double>): Double {
if(typeOfCollector == TypeCollector.Z) {
return jspMapValues["OC"]!! + jspMapValues["MC"]!!
} else {
return jspMapValues["EC"]!! + jspMapValues["OC"]!! + jspMapValues["S0C"]!! + jspMapValues["S1C"]!!
}
}

private fun usage(jspMapValues: Map<String, Double>): Double {
return jspMapValues["S0U"]!! + jspMapValues["S1U"]!! + jspMapValues["EU"]!! + jspMapValues["OU"]!!
private fun usage(typeOfCollector: TypeCollector, jspMapValues: Map<String, Double>): Double {
if(typeOfCollector == TypeCollector.Z) {
return jspMapValues["OU"]!! + jspMapValues["MU"]!!
} else {
return jspMapValues["S0U"]!! + jspMapValues["S1U"]!! + jspMapValues["EU"]!! + jspMapValues["OU"]!!
}
}

private fun gcTime(jspMapValues: Map<String, Double>): Double {
Expand All @@ -98,3 +163,9 @@ class JStatData {
return jspMapValues["Timestamp"]!!
}
}

enum class TypeCollector {
G1,
PARALLEL,
Z
}

0 comments on commit 263e287

Please sign in to comment.