<commit_before>/*
 * Copyright 2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.performance.regression.android

import org.gradle.performance.AbstractCrossBuildPerformanceTest
import org.gradle.performance.fixture.BuildExperimentInvocationInfo
import org.gradle.performance.fixture.BuildExperimentListenerAdapter
import org.gradle.performance.fixture.GradleInvocationSpec
import org.gradle.performance.results.BaselineVersion
import org.gradle.util.GFileUtils
import spock.lang.Unroll

class RealLifeAndroidDexingTransformsPerformanceTest extends AbstractCrossBuildPerformanceTest {

    @Unroll
    def "#tasks on #testProject without (android/transform) cache"() {
        given:
        def dexingTransform = "dexing transform"
        def dexingTask = "dexing task"

        runner.testGroup = "Android dexing"
        runner.buildSpec {
            projectName(testProject)
            displayName(dexingTransform)
            warmUpCount warmUpRuns
            invocationCount runs
            listener(cleanTransformsCache())
            invocation {
                defaultInvocation(tasks, memory, delegate)
                args("-Pandroid.enableDexingArtifactTransform=true")
            }
        }

        runner.baseline {
            projectName(testProject)
            displayName(dexingTask)
            warmUpCount warmUpRuns
            invocationCount runs
            listener(cleanTransformsCache())
            invocation {
                defaultInvocation(tasks, memory, delegate)
                args("-Pandroid.enableDexingArtifactTransform=false")
            }
        }

        when:
        def result = runner.run()

        then:
        result.assertEveryBuildSucceeds()
        and:
        def transformResults = result.buildResult(dexingTransform)
        def taskResults = new BaselineVersion("")
        taskResults.with {
            results.name = dexingTask
            results.addAll(result.buildResult(dexingTask))
        }
        def speedStats = taskResults.getSpeedStatsAgainst(dexingTransform, transformResults)
        println(speedStats)
        if (taskResults.significantlySlowerThan(transformResults)) {
            throw new AssertionError(speedStats)
        }

        where:
        testProject         | memory | warmUpRuns | runs | tasks
        'largeAndroidBuild' | '4g'   | 2          | 4    | 'clean phthalic:assembleDebug'
    }

    private BuildExperimentListenerAdapter cleanTransformsCache() {
        new BuildExperimentListenerAdapter() {
            @Override
            void beforeInvocation(BuildExperimentInvocationInfo invocationInfo) {
                GFileUtils.deleteDirectory(new File(invocationInfo.gradleUserHome, "caches/transforms-1/files-1.1"))
            }
        }
    }

    void defaultInvocation(String tasks, String memory, GradleInvocationSpec.InvocationBuilder builder) {
        with(builder) {
            tasksToRun(tasks.split(' '))
            cleanTasks("clean")
            gradleOpts("-Xms${memory}", "-Xmx${memory}")
            useDaemon()
            args("-Dorg.gradle.parallel=true", "-Pandroid.enableBuildCache=false", '-Dcom.android.build.gradle.overrideVersionCheck=true')
        }

    }
}
<commit_msg>Add another cross build performance test<commit_after>/*
 * Copyright 2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.performance.regression.android

import org.gradle.performance.AbstractCrossBuildPerformanceTest
import org.gradle.performance.fixture.BuildExperimentInvocationInfo
import org.gradle.performance.fixture.BuildExperimentListenerAdapter
import org.gradle.performance.fixture.GradleInvocationSpec
import org.gradle.performance.results.BaselineVersion
import org.gradle.performance.results.CrossBuildPerformanceResults
import org.gradle.util.GFileUtils
import spock.lang.Unroll

class RealLifeAndroidDexingTransformsPerformanceTest extends AbstractCrossBuildPerformanceTest {

    private static final String DEXING_TRANSFORM = "dexing transform"
    public static final String DEXING_TASK = "dexing task"

    @Unroll
    def "#tasks on #testProject without (android/transform) cache"() {
        given:
        def invocationOptions = [tasks: tasks, memory: memory, enableAndroidBuildCache: false]

        runner.testGroup = "Android dexing"
        runner.buildSpec {
            projectName(testProject)
            displayName(DEXING_TRANSFORM)
            warmUpCount warmUpRuns
            invocationCount runs
            listener(cleanTransformsCache())
            invocation {
                defaultInvocation(*:invocationOptions, dexingTransforms: true, delegate)
            }
        }

        runner.baseline {
            projectName(testProject)
            displayName(DEXING_TASK)
            warmUpCount warmUpRuns
            invocationCount runs
            listener(cleanTransformsCache())
            invocation {
                defaultInvocation(*:invocationOptions, dexingTransforms: false, delegate)
            }
        }

        when:
        def results = runner.run()

        then:
        results.assertEveryBuildSucceeds()
        and:
        assertDexingTransformIsFaster(results)

        where:
        testProject         | memory | warmUpRuns | runs | tasks
        'largeAndroidBuild' | '5g'   | 2          | 4    | 'clean assembleDebug'
    }

    @Unroll
    def "#tasks on #testProject"() {
        given:
        def dexingTransform = DEXING_TRANSFORM
        def dexingTask = DEXING_TASK

        def invocationOptions = [tasks: tasks, memory: memory, enableAndroidBuildCache: true]

        runner.testGroup = "Android dexing"
        runner.buildSpec {
            projectName(testProject)
            displayName(dexingTransform)
            warmUpCount warmUpRuns
            invocationCount runs
            invocation {
                defaultInvocation(*:invocationOptions, dexingTransforms: true, delegate)
            }
        }

        runner.baseline {
            projectName(testProject)
            displayName(dexingTask)
            warmUpCount warmUpRuns
            invocationCount runs
            invocation {
                defaultInvocation(*:invocationOptions, dexingTransforms: false, delegate)
            }
        }

        when:
        def results = runner.run()

        then:
        results.assertEveryBuildSucceeds()
        and:
        assertDexingTransformIsFaster(results)

        where:
        testProject         | memory | warmUpRuns | runs | tasks
        'largeAndroidBuild' | '5g'   | 2          | 4    | 'clean assembleDebug'
    }

    private static BuildExperimentListenerAdapter cleanTransformsCache() {
        new BuildExperimentListenerAdapter() {
            @Override
            void beforeInvocation(BuildExperimentInvocationInfo invocationInfo) {
                GFileUtils.deleteDirectory(new File(invocationInfo.gradleUserHome, "caches/transforms-1/files-1.1"))
            }
        }
    }

    void defaultInvocation(Map options, GradleInvocationSpec.InvocationBuilder builder) {
        String memory = options.memory
        String[] tasks = options.tasks.toString().split(' ')
        with(builder) {
            tasksToRun(tasks)
            cleanTasks("clean")
            gradleOpts("-Xms${memory}", "-Xmx${memory}")
            useDaemon()
            args("-Dorg.gradle.parallel=true", "-Pandroid.enableBuildCache=${options.enableAndroidBuildCache ?: true}", "-Pandroid.enableDexingArtifactTransform=${options.dexingTransforms}", '-Dcom.android.build.gradle.overrideVersionCheck=true')
        }

    }

    private static void assertDexingTransformIsFaster(CrossBuildPerformanceResults results) {
        def transformResults = results.buildResult(DEXING_TRANSFORM)
        BaselineVersion taskResults = dexingTaskResult(results)
        def speedStats = taskResults.getSpeedStatsAgainst(DEXING_TRANSFORM, transformResults)
        println(speedStats)
        if (taskResults.significantlySlowerThan(transformResults)) {
            throw new AssertionError(speedStats)
        }

    }

    private static BaselineVersion dexingTaskResult(CrossBuildPerformanceResults result) {
        def taskResults = new BaselineVersion("")
        taskResults.with {
            results.name = DEXING_TASK
            results.addAll(result.buildResult(DEXING_TASK))
        }
        taskResults
    }
}

{'fraction_non_alphanumeric': 0.07551342812006319, 'fraction_numerical': 0.003264876250658241, 'mean_word_length': 2.6106463878326998, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3443300', 'n_tokens_mistral': 2485, 'n_tokens_neox': 2364, 'n_words': 550}