Skip to content

Commit

Permalink
Merge pull request #11 from cdsap/dv_api_compatibility
Browse files Browse the repository at this point in the history
adding dv compatibility
  • Loading branch information
cdsap authored Jul 25, 2024
2 parents 1bb590f + ceec738 commit 450f276
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 33 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.testprocess") version "0.1.3"
id("io.github.cdsap.testprocess") version "0.1.4"
}
```

Expand All @@ -20,7 +20,7 @@ buildscript {
gradlePluginPortal()
}
dependencies {
classpath("io.github.cdsap:testprocess:0.1.3")
classpath("io.github.cdsap:testprocess:0.1.4")
}
}
Expand All @@ -31,7 +31,7 @@ apply(plugin = "io.github.cdsap.testprocess")
Using the plugins DSL:
``` groovy
plugins {
id "io.github.cdsap.testprocess" version "0.1.3"
id "io.github.cdsap.testprocess" version "0.1.4"
}
```
Expand All @@ -43,7 +43,7 @@ buildscript {
gradlePluginPortal()
}
dependencies {
classpath "io.github.cdsap:testprocess:0.1.3"
classpath "io.github.cdsap:testprocess:0.1.4"
}
}
Expand Down
3 changes: 2 additions & 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 All @@ -16,6 +16,7 @@ java {

dependencies {
implementation("com.gradle.enterprise:com.gradle.enterprise.gradle.plugin:3.12.3")
implementation("com.gradle:develocity-gradle-plugin:3.17.2")
testImplementation("junit:junit:4.13.2")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.cdsap.testprocess

import com.gradle.scan.plugin.BuildScanExtension
import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import io.github.cdsap.testprocess.model.Stats
import io.github.cdsap.testprocess.model.TestProcess
import io.github.cdsap.testprocess.report.BuildScanReport
Expand Down Expand Up @@ -43,9 +43,13 @@ class InfoTestProcessPlugin : Plugin<Project> {
}
}
target.gradle.rootProject {
val develocityConfiguration = extensions.findByType(DevelocityConfiguration::class.java)
val buildScanExtension = extensions.findByType(com.gradle.scan.plugin.BuildScanExtension::class.java)
if (buildScanExtension != null) {
BuildScanReport().buildScanReporting(buildScanExtension,processes,jstatResults,stats)
if (develocityConfiguration != null) {
BuildScanReport().develocityBuildScanReporting(develocityConfiguration,processes,jstatResults,stats)
}
else if (buildScanExtension != null) {
BuildScanReport().gradleEnterpriseBuildScanReporting(buildScanExtension,processes,jstatResults,stats)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.cdsap.testprocess.report

interface BuildScanData {
fun value(key: String, value: String)
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,73 @@
package io.github.cdsap.testprocess.report

import com.gradle.develocity.agent.gradle.DevelocityConfiguration
import com.gradle.scan.plugin.BuildScanExtension
import io.github.cdsap.testprocess.model.Stats
import io.github.cdsap.testprocess.model.TestProcess
import io.github.cdsap.testprocess.parser.JstatParser

class BuildScanReport {
fun buildScanReporting(
fun gradleEnterpriseBuildScanReporting(
buildScanExtension: BuildScanExtension,
processes: MutableMap<Long, TestProcess>,
jstatResults: MutableMap<Long, String>,
stats: Stats
) {
buildScanExtension.buildFinished {
val gradleEnterpriseValue = GradleEnterpriseValue(buildScanExtension)
extracted(processes, jstatResults, stats, gradleEnterpriseValue)
}
}

processes.forEach {
if (!jstatResults.containsKey(it.key)) {
stats.tasksWithoutProcess++
}

fun develocityBuildScanReporting(
develocityConfiguration: DevelocityConfiguration,
processes: MutableMap<Long, TestProcess>,
jstatResults: MutableMap<Long, String>,
stats: Stats
) {
develocityConfiguration.buildScan {
val develocityValue = DevelocityValue(this)
buildFinished {
extracted(processes, jstatResults, stats, develocityValue)
}
if (processes.isNotEmpty()) {
buildScanExtension.value("Test-Process", "${processes.count()} processes created")
buildScanExtension.value(
"Test-Process-Stats",
"processes parsed:${stats.totalProcesses}, jstatCalls:${stats.jstatCalls},tasksWithOutProcesses:${stats.tasksWithoutProcess}"
}

}

private fun extracted(
processes: MutableMap<Long, TestProcess>,
jstatResults: MutableMap<Long, String>,
stats: Stats,
buildScanData: BuildScanData
) {
processes.forEach {
if (!jstatResults.containsKey(it.key)) {
stats.tasksWithoutProcess++
}
}
if (processes.isNotEmpty()) {
buildScanData.value("Test-Process", "${processes.count()} processes created")
buildScanData.value(
"Test-Process-Stats",
"processes parsed:${stats.totalProcesses}, jstatCalls:${stats.jstatCalls},tasksWithOutProcesses:${stats.tasksWithoutProcess}"
)
processes.values.groupBy { it.task }.entries.map {
buildScanData.value(
"Test-Process-processes-by-task-${it.key}",
"${it.value.count()}"
)
processes.values.groupBy { it.task }.entries.map {
buildScanExtension.value(
"Test-Process-processes-by-task-${it.key}",
"${it.value.count()}"
}
processes.map {
if (jstatResults.containsKey(it.key)) {
val jstatInfo = JstatParser().process(jstatResults[it.key]!!)
buildScanData.value(
"Test-Process-process-info-${it.key}",
"[executor:${it.value.executor}, task:${it.value.task}, xmx:${it.value.max}, " +
"usage:${jstatInfo?.usage}Gb, gcTime:${jstatInfo?.gcTime} secs, " +
"gcType:${jstatInfo?.typeGC},uptime:${jstatInfo?.uptime} min ]"
)
}
processes.map {
if (jstatResults.containsKey(it.key)) {
val jstatInfo = JstatParser().process(jstatResults[it.key]!!)
buildScanExtension.value(
"Test-Process-process-info-${it.key}",
"[executor:${it.value.executor}, task:${it.value.task}, xmx:${it.value.max}, " +
"usage:${jstatInfo?.usage}Gb, gcTime:${jstatInfo?.gcTime} secs, " +
"gcType:${jstatInfo?.typeGC},uptime:${jstatInfo?.uptime} min ]"
)
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.github.cdsap.testprocess.report

import com.gradle.develocity.agent.gradle.scan.BuildScanConfiguration

class DevelocityValue(val develocityConfiguration: BuildScanConfiguration) : BuildScanData {
override fun value(key: String, value: String) {
develocityConfiguration.value(key, value)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.cdsap.testprocess.report

import com.gradle.scan.plugin.BuildScanExtension


class GradleEnterpriseValue(val buildScanExtension: BuildScanExtension) : BuildScanData {
override fun value(key: String, value: String) {
buildScanExtension.value(key, value)
}
}

0 comments on commit 450f276

Please sign in to comment.