build.gradle 9.17 KB
Newer Older
Noric Couderc's avatar
Noric Couderc committed
1
2
3
4
5
6
7
8
9
10
11
/*
 * This build file was auto generated by running the Gradle 'init' task
 * by 'noricc' at '9/17/18 11:09 AM' with Gradle 2.10
 *
 * This generated file contains a commented-out sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * user guide available at https://docs.gradle.org/2.10/userguide/tutorial_java_projects.html
 */

plugins {
    id 'java'
12
    // id 'idea'
13
    // If this doesn't work, update gradle using // $ ./gradlew wrapper
Noric Couderc's avatar
Noric Couderc committed
14
    // $ ./gradlew wrapper --gradle-version <version>
15
    id 'org.jetbrains.kotlin.jvm' version "1.3.72"
Noric Couderc's avatar
Noric Couderc committed
16
}
Noric Couderc's avatar
Noric Couderc committed
17

Noric Couderc's avatar
Noric Couderc committed
18
19
20
21
22
23
24
25
repositories {
    mavenCentral()
    jcenter()
    maven {
        url "https://plugins.gradle.org/m2/"
    }
}

26
compileJava {
27
28
    sourceCompatibility = 8
    targetCompatibility = 8
Noric Couderc's avatar
Noric Couderc committed
29
}
Noric Couderc's avatar
Noric Couderc committed
30

31
32
33
34
35
36
37
38
39
40
import java.nio.file.Paths;

// We'll make a plugin for anything that uses PAPI

class PAPIPlugin implements Plugin<Project> {
    def foundPapi(path) {
        return path.toFile().exists();
    }

    def findPapi() {
41
42
43
        def options = [Paths.get("/usr", "local", "lib", "libpapi.so"),
		       Paths.get("/usr", "lib", "x86_64-linux-gnu", "libpapi.so"),
                       Paths.get("/usr", "local", "lib", "x86_64-linux-gnu", "libpapi.so")]
44
45
46
47
48
49
50

        def env = System.getenv()
        if (env.containsKey("PAPI_LIBRARY_PATH")) {
            options.add(Paths.get(env["PAPI_LIBRARY_PATH"].toString(),
                                      "libpapi.so"))
        }

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
        def p = options.find({ foundPapi(it) });

        if (p == null) {
            throw new RuntimeException("Papi not found in the paths $options")
        }

        def path = p.parent
        println("PAPI found in: '$path'")
        return path
    }

    def papi_path = findPapi()

    // We want to define some properties...
    void apply(Project project) {
66
67
        def papi_java_path = "${project.rootProject.projectDir}/papi-java"
        def library_path = "$papi_path:$papi_java_path".toString()
68

Noric Couderc's avatar
Noric Couderc committed
69
        project.ext.papi_library_path = library_path
70
71
72
73
    }
}


74
subprojects {
75
    apply plugin: 'java'
76
    apply plugin: 'kotlin'
77
    apply plugin: PAPIPlugin
78
79
80
81
82

    compileKotlin {
        kotlinOptions {
            jvmTarget = "1.8"
        }
Noric Couderc's avatar
Noric Couderc committed
83
    }
84
85
86
87
88

    compileTestKotlin {
        kotlinOptions {
            jvmTarget = "1.8"
        }
Noric Couderc's avatar
Noric Couderc committed
89
    }
90
91
92

    test {
        useJUnitPlatform()
Noric Couderc's avatar
Noric Couderc committed
93
        systemProperty "java.library.path", papi_library_path
94
95
96
97
98
99
100

        testLogging {
            exceptionFormat = 'full'
        }

        dependsOn cleanTest
    }
Noric Couderc's avatar
Noric Couderc committed
101
}
102

103
104
105
project(':benchmarking-synthetic') {
    dependencies {
        implementation project(':core')
Noric Couderc's avatar
Noric Couderc committed
106
107
108
109
110
111
        compile 'org.json:json:20190722'
        compile 'net.time4j:time4j-core:4.38'
        compile 'org.apache.commons:commons-lang3:3.9'
        compile 'org.openjdk.jmh:jmh-core:1.22'
        annotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.22'
        implementation 'com.google.code.gson:gson:2.8.5'
112
    }
Noric Couderc's avatar
Noric Couderc committed
113
}
114

115
116
117
118
119
120
121
122
123
124
125
126
project(':benchmarking-traces') {
    dependencies {
        implementation project(':core')
        compile 'org.json:json:20190722'
        compile 'net.time4j:time4j-core:4.38'
        compile 'org.apache.commons:commons-lang3:3.9'
        compile 'org.openjdk.jmh:jmh-core:1.22'
        annotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.22'
        implementation 'com.google.code.gson:gson:2.8.5'
    }
}

Noric Couderc's avatar
Noric Couderc committed
127
128
129
130
131
132
project(':core') {
    apply plugin: PAPIPlugin
    apply plugin: 'application'

    run {
        systemProperty 'java.library.path', papi_library_path
133
 	applicationDefaultJvmArgs = ['-Xmx6g']
Noric Couderc's avatar
Noric Couderc committed
134
135
136
137
138
        mainClassName = 'se.lth.cs.Main'
        workingDir = '..'
    }
}

139
140
141
142
143
144
145
146
147
148
def jmhOptionsMap = [
    "resultFormat": "-rf",
    "benchmarkParameters" : "-p",
    "iterations": "-i",
    "timeOnIteration": "-r",
    "warmupIterations": "-wi",
    "warmup": "-w",
    "include": "", // No option, just add to end of command
    "fork": "-f",
    "timeUnit": "-tu",
149
150
151
    "failOnError": "-foe",
    "outputFile" : "-rff",
    "logFile" : "-o" // For STDOUT
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
]

def createJMHOptions(optionsMap, valuesMap) {
    def options = []
    for (e in optionsMap) {
        def optionFlag = e.value
        if (!valuesMap.containsKey(e.key)) {
            println("Argument not found: $e.key")
        }
        def argValue = valuesMap[e.key]
        // If one if a map, it's probably the benchmarkParameters
        if (e.key == "benchmarkParameters") {
            // We want for each param a couple
            // -p PARAM=v1,v2,v3
            def arguments = argValue.collect{it.key + "=" + it.value.join(",")}
            arguments.each{
                options.add(optionFlag)
                options.add(it)
            }
        } else {
172
173
174
175
176
177
            if (e.key == "include") {
                // do nothing, we'll add later
            } else {
                options.add(optionFlag)
                options.add(argValue)
            }
178
179
        }
    }
180
181
182
183
184

    for (v in valuesMap["include"]) {
        options.add(v)
    }

185
186
187
188
    return options
}

def jmhTestArgsMap = [
Noric Couderc's avatar
Noric Couderc committed
189
190
191
    include: ["List"], // This parameter seems to be ignored?
    benchmarkParameters:["seed": (0..20).toList().collect{it.toString()},
                         "applicationSize":["1000"],
192
                         "baseStructureSize":["0"]],
193
194
195
196
197
    fork:2,
    timeOnIteration:"250ms",
    iterations:2,
    warmup:"250ms",
    warmupIterations:2,
Noric Couderc's avatar
Noric Couderc committed
198
    outputFile: "jmh-results-test.csv",
199
200
201
202
    fork:2,
    resultFormat:"CSV",
    benchmarkMode:["ss"],
    timeUnit:"ms",
203
    logFile: "jmh-test.log",
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
    failOnError : true,
]

task('jmhTest', type: Exec) {
    dependsOn 'benchmarking-synthetic:shadowJar'
    def options = createJMHOptions(jmhOptionsMap, jmhTestArgsMap)
    workingDir '.'
    commandLine = ['java', '-jar', 'benchmarking-synthetic/build/libs/benchmarks.jar'] + options
}

def jmhFullArgsMap = [
    include: ["List", "Map", "Set"],
    timeOnIteration:"250ms",
    warmup:"250ms",
    warmupIterations:2,
    fork:2,
    resultFormat:"CSV",
    timeUnit:"ms",
    failOnError: true,
223
    benchmarkParameters: ["seed": (0..1000).toList().collect{it.toString()},
224
                          "baseStructureSize": ["0"],
225
                          "applicationSize" : ["1000"],
226
                          "methodSelectionStrategyId" : ["BRAINY"]],
227
    duplicateClassesStrategy:'warn',
228
229
    outputFile : "jmh-results-full.csv",
    logFile: "jmh-full.log",
230
231
232
233
    iterations:5,
]

task('jmhFull', type: Exec) {
234
    dependsOn 'benchmarking-synthetic:shadowJar'
235
    def options = createJMHOptions(jmhOptionsMap, jmhFullArgsMap)
236
    workingDir '.'
237
    commandLine = ['java', '-jar', 'benchmarking-synthetic/build/libs/benchmarks.jar'] + options
238
}
239
240


241
242
def seedsFileName = "seeds-benchmarks.csv"

243
244
245
246
247
248
249
// A task where you run benchmarks with different seeds
// a print a file listing a list of seeds that should
// provide a good coverage (each collection wins "n" benchmarks)
task('sampleSeeds', type: Exec) {
    dependsOn 'benchmarking-synthetic:shadowJar'
    workingDir '.'
    commandLine = ['java', '-cp', 'benchmarking-synthetic/build/libs/benchmarks.jar', 'se.lth.cs.jmh.Main',
250
                   '--target-size', '100', '--number-iterations', '30', '--output-file', seedsFileName]
251
}
252
253
254
255
256
257
258
259

task('compareMethodSelections', type: Exec) {
    dependsOn 'benchmarking-synthetic:shadowJar'
    workingDir '.'
    commandLine = ['java', '-Djava.library.path=/usr/lib/x86_64-linux-gnu:./papi-java',
                   '-cp', 'benchmarking-synthetic/build/libs/benchmarks.jar',
                   'se.lth.cs.jmh.Main',
                   '--mode', 'compare-generation-schemes',
260
261
262
                   '--target-size', '100',
                   '--seed-limit', '1000',
                   '--number-iterations', '30', '--output-file', 'comparison-generation-schemes.csv']
263
}
264
265

import java.nio.file.Paths
Noric Couderc's avatar
Noric Couderc committed
266
import java.util.TreeSet
267
268
269
270
271

// Benchmarking sampled seeds with JMH
// This transforms a list of loaded seeds into the JMH table of arguments
def loadSeeds(filename, baseMap) {
    def p = Paths.get(filename)
272
273
274
    if (!p.toFile().exists()) {
        return baseMap
    }
275
    def i = p.toFile().newInputStream()
Noric Couderc's avatar
Noric Couderc committed
276
277
    def seeds = new TreeSet()
    def interfaces = new TreeSet()
278
279
280
281
282
283
284
285
286
287
288
289
    def lineNumber = 0
    def append = { split ->
        if (lineNumber == 0) {
            // do nothing
        } else {
            seeds.add(split[0])
            interfaces.add(split[1])
        }
        lineNumber++
    }
    i.splitEachLine(",", append)

Noric Couderc's avatar
Noric Couderc committed
290
291
    println("File parsed. Lines: " + lineNumber)

292
293
294
    def newMap = baseMap.clone()

    // '+' is the operator you use for merging maps
Noric Couderc's avatar
Noric Couderc committed
295
296
297
298
    newMap["benchmarkParameters"] = baseMap["benchmarkParameters"] + ["seed": seeds]

    newMap = newMap + ["include": interfaces]

299
300
    return newMap
}
301

302
import java.io.InputStream
303

304
305
306
def optionsToString(List<String> options) {
    def joined = String.join(" ", options.collect { it -> it.toString()})
    return new ByteArrayInputStream(joined.bytes)
307
308
309
310
311
312
}

task('jmhSeeds', type: Exec) {
    dependsOn 'benchmarking-synthetic:shadowJar'
    def loadedParameters = loadSeeds(seedsFileName, jmhFullArgsMap)
    def options = createJMHOptions(jmhOptionsMap, loadedParameters)
313
    standardInput = optionsToString(options)
314
    workingDir '.'
315
316
    commandLine = ['java', '-cp', 'benchmarking-synthetic/build/libs/benchmarks.jar',
                   'se.lth.cs.jmh.SeedSamplerJMHReader']
317
}