Skip to content

Instantly share code, notes, and snippets.

@jonnycaley
Last active June 21, 2022 08:10
Show Gist options
  • Save jonnycaley/528d8ce4a68dd9661cc8adefc2413588 to your computer and use it in GitHub Desktop.
Save jonnycaley/528d8ce4a68dd9661cc8adefc2413588 to your computer and use it in GitHub Desktop.
BuildDurationService - build and configuration time
abstract class BuildDurationService : BuildService<BuildServiceParameters.None>, BuildOperationListener, AutoCloseable {
var buildDuration: Long? = null
var configurationDuration: Long? = null
var configurationPhaseFailed = true
override fun started(p0: BuildOperationDescriptor, p1: OperationStartEvent) {}
override fun progress(p0: OperationIdentifier, p1: OperationProgressEvent) {}
override fun finished(buildOperationDescriptor: BuildOperationDescriptor, operationFinishEvent: OperationFinishEvent) {
if (buildOperationDescriptor.details is RunRootBuildWorkBuildOperationType.Details) {
/**
* Runs when build phase finishes, therefore we can assume configuration phase passed
*/
configurationPhaseFailed = false
val details = buildOperationDescriptor.details as RunRootBuildWorkBuildOperationType.Details?
details?.buildStartTime?.let { buildStartTime ->
buildDuration = System.currentTimeMillis() - buildStartTime
val firstTaskStartTime = operationFinishEvent.startTime
this.configurationDuration = firstTaskStartTime - buildStartTime
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment