Time-consuming to get Gradle Task

monitor task

adding build.gradle(:appp)_

class BuildTimeCostListener implements TaskExecutionListener, BuildListener {
    
    
    private long startTime
    private timeList = []

    @Override
    void beforeExecute(Task task) {
    
    
        //task开始执行之前搜集task的信息
        startTime = System.currentTimeMillis()
    }

    @Override
    void afterExecute(Task task, TaskState taskState) {
    
    
        //task执行完之后,记录结束时的时间
        def ms = System.currentTimeMillis() - startTime
        timeList.add([ms, task.path])
        task.project.logger.warn("cost ${ms} ms")
    }

    @Override
    void buildStarted(Gradle gradle) {
    
    

    }

    @Override
    void settingsEvaluated(Settings settings) {
    
    

    }

    @Override
    void projectsLoaded(Gradle gradle) {
    
    

    }

    @Override
    void projectsEvaluated(Gradle gradle) {
    
    

    }

    @Override
    void buildFinished(BuildResult result) {
    
    
        println(">>>>>>>>>> Main Tasks:")
        for (time in timeList) {
    
    
            if (time[0] > 100) {
    
    
                printf(">>>Task Cost: %8s ms  %s\n", time)
            }
        }
    }
}

gradle.addListener new BuildTimeCostListener()

-profile

./gradlew assembleDebug -profile

Gradle Incremental builds are supported, when you run the build, some Taskare marked as UP-TO-DATE, that's incremental compilation in effect

reference

Android Gradle Learning (8): Statistical Task Execution Duration

gradle view output execution time of each task

Android Compilation Optimization - SegmentFault 思否

Advanced Gradle (1): In-depth understanding of Tasks (qq.com)

[Seven Questions of the Soul] In-depth Exploration of Gradle Automation Construction Technology (V. Analysis of the Implementation Principle of Gradle Plug-in Architecture - Part 2) (qq.com)

Guess you like

Origin blog.csdn.net/b1tb1t/article/details/128908397