This message was deleted.
# community-support
s
This message was deleted.
a
i did this very thing, but didnt ship it. you cant know if theres a build failure with old funcitonality. but what I did register with `sharedServices`:
Copy code
val provider = target.gradle.sharedServices.registerIfAbsent("TimingsService", TimingsService::class) {
                val apkBuildDir = File(target.projectDir, "app/build/outputs/apk")
                this.parameters.apkDirExists.set(apkBuildDir.exists())
                this.parameters.projectName.set(target.name)
                this.parameters.taskNameList.set(target.gradle.startParameter.taskNames)
            }

if (registry is BuildEventListenerRegistryInternal) {
                registry.onOperationCompletion(provider)
            }
Copy code
abstract class TimingsService :
    BuildService<TimingsService.Params>,
    BuildOperationListener,
    Closeable {
overridding:
Copy code
override fun finished(buildOperation: BuildOperationDescriptor, finishEvent: OperationFinishEvent) {
        val result = finishEvent.result
        val details = buildOperation.details
        if (result is ExecuteTaskBuildOperationType.Result && details is ExecuteTaskBuildOperationDetails) {
            val name = details.task.project.name
            val duration = finishEvent.endTime - finishEvent.startTime
            if (result.skipMessage == null) {
                val total = moduleTimings[name]
                if (total != null) {
                    moduleTimings[name] = total + duration
                } else {
                    moduleTimings[name] = duration
                }
            } else {
                moduleCached[name] = result.skipMessage == TaskExecutionOutcome.FROM_CACHE.message
            }
        }
params are:
Copy code
interface Params : BuildServiceParameters {
        val apkDirExists: Property<Boolean>
        val projectName: Property<String>
        val taskNameList: ListProperty<String>
    }
seemed to โ€œworkโ€
k
that's probably working because you don't have the config cache turned on?
a
we dont now. but this enabled the functionality with it turned on
๐Ÿ‘ 1
didnt the android tools team say they plan to support configuration caching in their tooling? i dont know how compatible it is. i ran into other issues
k
config caching works decently well now if you're careful and keep all the module configs independent
a
oh nice. yeah sorely needed, configuration is like 30-1m of our build no matter what we change. someday weโ€™ll revisit it ๐Ÿ™‚
v
You should not use
BuilOperationListener
or an internal class. Here the proper way is documented: https://docs.gradle.org/current/userguide/build_services.html#operation_listener Make the build service implement
OperationCompletionListener
and register it with
BuildEventsListenerRegistry
. And if you need a hook for build finish, make the service also implement
AutoCloseable
. Those are the supported CC compatible ways.
๐Ÿ‘ 1
a
finishevent on the
OperationCompletedListener
only gives you start and end time, not which module task ran
descriptor be the one?
we want to track exact project name for each completion on buidling
v
event.displayName
=>
"Task :foo:compileJava SUCCESS"
event.descriptor.displayName
=>
"Task :foo:compileJava"
event.descriptor.name
=>
":foo:compileJava"
๐Ÿ‘ 1
a
cool. so we can parse out that format? niceeee. just have to parse the real module name out
is there an event for end to end?
from start of first task to very last one
v
If your build service implements
AutoCloseable
too, it will be triggered somewhen between the last task finished and the build finished. So you could record the start time of the first finished task and remember the task finish time of the last finished task and when the
close
is triggered, you know the last task happened, or you just take the time in the
close
method. You could also take the time when the listener is instaniated, but I'm not fully sure whether this will be after the first task finished or before it is started. By taking the task start time of the first task finished event you are on the safe side, especially if you want to record task execution time.
๐Ÿ‘ 1