-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjmh.gradle
98 lines (82 loc) · 2.96 KB
/
jmh.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Adds JMH integration to a project.
// Include it with:
// apply from: rootProject.file('../jmh.gradle')
sourceSets {
jmh {
compileClasspath += sourceSets.test.runtimeClasspath
runtimeClasspath += sourceSets.test.runtimeClasspath
}
}
dependencies {
jmhCompile project
jmhCompile 'org.openjdk.jmh:jmh-core:1.18'
jmhCompile 'org.openjdk.jmh:jmh-generator-annprocess:1.18'
}
eclipse {
classpath {
plusConfigurations.add(configurations.jmhCompile)
defaultOutputDir = file('build/classes-jmh-ide')
}
}
task ('jmhHelp', description:'Print help for the jmh task', group: 'Development') {
doLast {
println ""
println "Usage of jmh tasks:"
println "~~~~~~~~~~~~~~~~~~~~~~~~~~~"
println "Only execute specific benchmark(s):"
println "\tgw jmh -Pinclude=\".*MyBenchmark.*\""
println ""
println "Specify extra profilers:"
println "\tgw jmh -Pprofilers=\"gc,stack\""
println ""
println "Prominent profilers:"
println "\tcomp - JitCompilations, tune your iterations"
println "\tstack - which methods used most time"
println "\tgc - print garbage collection stats"
println "\ths_thr - thread usage"
println ""
println "Change report format from JSON to one of [CSV, JSON, NONE, SCSV, TEXT]:"
println "\tgw jmh -Pformat=csv"
println ""
println "Specify JVM arguments:"
println "\tgw jmh -PjvmArgs=\"-Dtest.cluster=local\""
println ""
println "Resources:"
println "\thttp://tutorials.jenkov.com/java-performance/jmh.html (Introduction)"
println "\thttp://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/ (Samples)"
}
}
task jmh(type: JavaExec, description: 'Executing JMH benchmarks', group:'Development') {
classpath = sourceSets.jmh.runtimeClasspath
main = 'org.openjdk.jmh.Main'
def include = project.properties.get('include', '');
def exclude = project.properties.get('exclude');
def format = project.properties.get('format', 'json');
def profilers = project.properties.get('profilers');
def jvmArgs = project.properties.get('jvmArgs')
def resultFile = file("build/reports/jmh/result.${format}")
resultFile.parentFile.mkdirs()
args include
if(exclude) {
args '-e', exclude
}
args '-foe', 'true' //fail-on-error
args '-v', 'NORMAL' //verbosity [SILENT, NORMAL, EXTRA]
if(profilers) {
profilers.split(',').each {
args '-prof', it
}
}
args '-jvmArgsPrepend', '-Xmx512m'
args '-jvmArgsPrepend', '-Xms512m'
if(jvmArgs) {
for(jvmArg in jvmArgs.split(' ')) {
args '-jvmArgsPrepend', jvmArg
}
}
args '-rf', format
args '-rff', resultFile
doFirst {
println "\nExecuting JMH with: $args \n"
}
}