Skip to content

Build trace Gradle plugin#

This plugin is a primitive analog of Gradle build scan. Use it if you can't use a build scan for any reason.

This plugin collects tasks execution time in a trace event format.

Getting started#

Apply the plugin in the root buildscript:

plugins {
    id("com.avito.android.build-trace")
}

buildTrace {
    enabled.set(true)
}
Setup plugins

In the settings.gradle:

pluginManagement {
    repositories {
        mavenCentral()
    }
    resolutionStrategy {
        eachPlugin {
            String pluginId = requested.id.id
            if (pluginId.startsWith("com.avito.android")) {
                def artifact = pluginId.replace("com.avito.android.", "")
                useModule("com.avito.android:$artifact:$avitoToolsVersion")
            }
        }
    }
}

avitoToolsVersion could be exact version, or property in project's gradle.properties. The latest version could be found on project's release page.

Run a build. You will get a message in a log:

Build trace: <path to the project>/outputs/build-trace/build.trace

Inspecting a trace#

The trace file can be opened by multiple tools.

Chrome tracing

chrome://tracing

This is a legacy viewer.

Use WASD keys and search field for navigation.

Perfetto

This is a modern alternative for trace files.

Here you can also make analytical queries by SQL:

-- Slowest tasks
SELECT slice.name AS TASK_PATH, slice.dur / 1000000 AS DURATION_MS
FROM slice
ORDER BY slice.dur DESC

Critical path#

To understand the critical path better see critical path.
Tasks on this path are highlighted in a trace.

You can find them by query:

SELECT slice.name AS TASK_PATH, slice.ts / 1000000 AS START_MS, slice.dur / 1000000 AS DURATION_MS
FROM slice JOIN args ON slice.arg_set_id = args.arg_set_id
WHERE args.flat_KEY = "args.CRITICAL_PATH"
ORDER BY slice.ts ASC

Known issues#

  • Tasks' completion time is long after a real time (#8630). In a trace it looks like a task is completed right after the another from the same module.