Class MeasureEnergyTask
java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
com.patbaumgartner.greener.gradle.MeasureEnergyTask
- All Implemented Interfaces:
Comparable<org.gradle.api.Task>,org.gradle.api.internal.DynamicObjectAware,org.gradle.api.internal.TaskInternal,org.gradle.api.Named,org.gradle.api.plugins.ExtensionAware,org.gradle.api.Task,org.gradle.util.Configurable<org.gradle.api.Task>
@DisableCachingByDefault(because="Energy measurement depends on live system state")
public abstract class MeasureEnergyTask
extends org.gradle.api.DefaultTask
Gradle task that measures the energy consumption of a Spring Boot application using
Joular Core.
This task mirrors the Maven greener:measure goal.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.gradle.api.Named
org.gradle.api.Named.Namer -
Field Summary
Fields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract org.gradle.api.provider.ListProperty<String>Additional application arguments passed to the Spring Boot process.abstract org.gradle.api.provider.Property<Boolean>Whentrue, the measurement result is automatically promoted to the baseline after a successful run.abstract org.gradle.api.file.RegularFilePropertyPath to the JSON baseline file.abstract org.gradle.api.provider.Property<String>Base URL of the Spring Boot application.abstract org.gradle.api.provider.Property<String>Branch name to record in the baseline when auto-updating.abstract org.gradle.api.provider.Property<String>Git commit SHA to record in the baseline when auto-updating.abstract org.gradle.api.provider.Property<String>Optional external command used as the training workload (e.g.abstract org.gradle.api.file.RegularFilePropertyPath to an external shell script file used as the training workload.abstract org.gradle.api.provider.Property<Boolean>Whentrue, the build is failed if energy consumption regressed beyondgetThreshold().abstract org.gradle.api.provider.Property<String>Health-check path used to detect application readiness.abstract org.gradle.api.provider.Property<Integer>Idle-baseline window (seconds) measured before workload.abstract org.gradle.api.provider.Property<Integer>Number of independent measurement iterations.abstract org.gradle.api.file.RegularFilePropertyPath to the Joular Code Java agent jar.abstract org.gradle.api.file.RegularFilePropertyPath to the Joular Code Javajoularcodejava.propertiesfile.abstract org.gradle.api.file.RegularFilePropertyFull path to the Joular Core binary (optional; auto-downloaded when absent).abstract org.gradle.api.provider.Property<String>Hardware component to monitor:cpu,gpu, orall.abstract org.gradle.api.provider.Property<String>Joular Core release version to download whengetJoularCoreBinaryPath()is not set.abstract org.gradle.api.provider.ListProperty<String>Additional JVM arguments passed when starting the Spring Boot process.protected abstract org.gradle.api.file.ProjectLayoutGets the project layout.abstract org.gradle.api.provider.Property<Integer>Duration in seconds of the actual measurement window after warmup.protected abstract org.gradle.api.provider.ProviderFactoryGets the provider factory.abstract org.gradle.api.provider.Property<com.patbaumgartner.greener.core.model.RegressionMetric>Regression metric.abstract org.gradle.api.file.DirectoryPropertyDirectory where the HTML report is written.abstract org.gradle.api.provider.Property<Integer>Number of HTTP requests per second (passed asRPSenvironment variable).abstract org.gradle.api.provider.Property<Boolean>getSkip()Whentrue, the task execution is skipped entirely.abstract org.gradle.api.file.RegularFilePropertyPath to the executable Spring Boot fat-jar.abstract org.gradle.api.provider.Property<Integer>Seconds to wait for the application health endpoint before aborting.abstract org.gradle.api.provider.Property<Double>Maximum allowed percentage increase in total energy before the build is failed.abstract org.gradle.api.provider.Property<Boolean>Whentrue, the report output directory gets a timestamp suffix (e.g.abstract org.gradle.api.provider.Property<Integer>getTopN()Number of top energy-consuming methods to show in the HTML report.abstract org.gradle.api.provider.Property<Boolean>Enable Joular Core VM mode.abstract org.gradle.api.file.RegularFilePropertyPath to the VM power file that Joular Core reads whengetVmMode()istrue.abstract org.gradle.api.provider.Property<Integer>Warmup duration in seconds.voidRuns the energy measurement workflow.Methods inherited from class org.gradle.api.DefaultTask
compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesServiceMethods inherited from class org.gradle.api.internal.AbstractTask
acceptServiceReferences, appendParallelSafeAction, doNotTrackState, doNotTrackStateIf, getAsDynamicObject, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonsNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, restoreOnlyIf, restoreTaskActions, setImpliesSubProjectsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gradle.api.Task
doNotTrackState, notCompatibleWithConfigurationCache
-
Constructor Details
-
MeasureEnergyTask
public MeasureEnergyTask()
-
-
Method Details
-
getLayout
@Inject protected abstract org.gradle.api.file.ProjectLayout getLayout()Gets the project layout.- Returns:
- the project layout
-
getProviders
@Inject protected abstract org.gradle.api.provider.ProviderFactory getProviders()Gets the provider factory.- Returns:
- the provider factory
-
getSpringBootJar
@InputFile @PathSensitive(ABSOLUTE) @Optional public abstract org.gradle.api.file.RegularFileProperty getSpringBootJar()Path to the executable Spring Boot fat-jar. When omitted the task auto-detects a single jar inbuild/libs/.- Returns:
- the Spring Boot jar property
-
getJvmArgs
Additional JVM arguments passed when starting the Spring Boot process.- Returns:
- the JVM arguments property
-
getAppArgs
Additional application arguments passed to the Spring Boot process.- Returns:
- the application arguments property
-
getJoularCoreBinaryPath
@InputFile @PathSensitive(ABSOLUTE) @Optional public abstract org.gradle.api.file.RegularFileProperty getJoularCoreBinaryPath()Full path to the Joular Core binary (optional; auto-downloaded when absent).- Returns:
- the Joular Core binary path property
-
getJoularCoreVersion
Joular Core release version to download whengetJoularCoreBinaryPath()is not set. See Joular Core releases for available versions.- Returns:
- the Joular Core version property
-
getJoularCoreComponent
Hardware component to monitor:cpu,gpu, orall.- Returns:
- the Joular Core component property
-
getJoularCodeJavaAgentPath
@InputFile @PathSensitive(ABSOLUTE) @Optional public abstract org.gradle.api.file.RegularFileProperty getJoularCodeJavaAgentPath()Path to the Joular Code Java agent jar. When set, the agent is attached to the Spring Boot JVM via-javaagent:for per-method energy monitoring.- Returns:
- the Joular Code Java agent path property
-
getJoularCodeJavaConfigPath
@InputFile @PathSensitive(ABSOLUTE) @Optional public abstract org.gradle.api.file.RegularFileProperty getJoularCodeJavaConfigPath()Path to the Joular Code Javajoularcodejava.propertiesfile. Used only whengetJoularCodeJavaAgentPath()is also set.- Returns:
- the Joular Code Java config path property
-
getBaseUrl
Base URL of the Spring Boot application.- Returns:
- the base URL property
-
getRequestsPerSecond
Number of HTTP requests per second (passed asRPSenvironment variable).- Returns:
- the requests per second property
-
getExternalTrainingCommand
@Input @Optional public abstract org.gradle.api.provider.Property<String> getExternalTrainingCommand()Optional external command used as the training workload (e.g.k6 run script.js). TheAPP_URLenvironment variable is set togetBaseUrl().- Returns:
- the external training command property
-
getExternalTrainingScriptFile
@InputFile @PathSensitive(ABSOLUTE) @Optional public abstract org.gradle.api.file.RegularFileProperty getExternalTrainingScriptFile()Path to an external shell script file used as the training workload. Takes precedence overgetExternalTrainingCommand()when set.Available environment variables in the script:
APP_URL,APP_HOST,APP_PORT,WARMUP_SECONDS,MEASURE_SECONDS,TOTAL_SECONDS,RPS.See
examples/workloads/for wrk, wrk2, oha, and Gatling examples.- Returns:
- the external training script file property
-
getVmMode
Enable Joular Core VM mode.In VM mode Joular Core cannot read RAPL counters directly and instead reads the VM's total power from a file written by the host - see
getVmPowerFilePath(). The host must write the VM's instantaneous power (Watts) to that file once per second.- Returns:
- the VM mode property
-
getVmPowerFilePath
@InputFile @PathSensitive(ABSOLUTE) @Optional public abstract org.gradle.api.file.RegularFileProperty getVmPowerFilePath()Path to the VM power file that Joular Core reads whengetVmMode()istrue. The file must contain a single floating-point number (e.g.45.2).- Returns:
- the VM power file path property
-
getWarmupDurationSeconds
Warmup duration in seconds. The application runs under load during warmup so the JIT compiler warms up, but energy data from this phase is discarded.- Returns:
- the warmup duration property
-
getMeasureDurationSeconds
Duration in seconds of the actual measurement window after warmup.- Returns:
- the measure duration property
-
getStartupTimeoutSeconds
Seconds to wait for the application health endpoint before aborting.- Returns:
- the startup timeout property
-
getHealthCheckPath
Health-check path used to detect application readiness.- Returns:
- the health check path property
-
getBaselineFile
@InputFile @PathSensitive(ABSOLUTE) @Optional public abstract org.gradle.api.file.RegularFileProperty getBaselineFile()Path to the JSON baseline file.- Returns:
- the baseline file property
-
getThreshold
Maximum allowed percentage increase in total energy before the build is failed. For example10means a 10 % regression is tolerated.- Returns:
- the threshold property
-
getFailOnRegression
Whentrue, the build is failed if energy consumption regressed beyondgetThreshold().- Returns:
- the fail on regression property
-
getReportOutputDir
@OutputDirectory @Optional public abstract org.gradle.api.file.DirectoryProperty getReportOutputDir()Directory where the HTML report is written.- Returns:
- the report output directory property
-
getAutoUpdateBaseline
Whentrue, the measurement result is automatically promoted to the baseline after a successful run. This eliminates the need to callupdateEnergyBaselineseparately.- Returns:
- the auto-update baseline property
-
getCommitSha
Git commit SHA to record in the baseline when auto-updating.- Returns:
- the commit SHA property
-
getBranch
Branch name to record in the baseline when auto-updating.- Returns:
- the branch property
-
getTimestampReports
Whentrue, the report output directory gets a timestamp suffix (e.g.greener-reports-20260404-153012) and alatestsymlink is created pointing to the most recent run.- Returns:
- the timestamp reports property
-
getSkip
Whentrue, the task execution is skipped entirely.- Returns:
- the skip property
-
getTopN
Number of top energy-consuming methods to show in the HTML report.- Returns:
- the top N property
-
getIterations
Number of independent measurement iterations. Withiterations >= 2the comparator gains run-to-run statistics and applies Welch's t-test + Cohen's d.- Returns:
- the iterations property
-
getRegressionMetric
@Input public abstract org.gradle.api.provider.Property<com.patbaumgartner.greener.core.model.RegressionMetric> getRegressionMetric()Regression metric.ENERGY_PER_REQUEST(default) normalises by successful requests so throughput improvements don't masquerade as energy regressions;TOTAL_ENERGYcompares raw Joules.- Returns:
- the regression metric property
-
getIdleProbeSeconds
Idle-baseline window (seconds) measured before workload. Subtracted from workload energy. Set to 0 to disable.- Returns:
- the idle-probe seconds property
-
measureEnergy
Runs the energy measurement workflow.- Throws:
IOException- if an I/O error occurs during measurementInterruptedException- if the measurement is interrupted
-