1
+ apply plugin : ' java'
2
+ apply plugin : ' idea'
3
+
4
+ configurations {
5
+ current
6
+ baseline {
7
+ resolutionStrategy. cacheChangingModulesFor 0 , ' seconds'
8
+ }
9
+ }
10
+
11
+ dependencies {
12
+ // Use the baseline to avoid using new APIs in the benchmarks
13
+ compileOnly " io.rsocket:rsocket-core:${ perfBaselineVersion} "
14
+ compileOnly " io.rsocket:rsocket-transport-local:${ perfBaselineVersion} "
15
+
16
+ implementation " org.openjdk.jmh:jmh-core:1.21"
17
+ annotationProcessor " org.openjdk.jmh:jmh-generator-annprocess:1.21"
18
+
19
+ current project(' :rsocket-core' )
20
+ current project(' :rsocket-transport-local' )
21
+ baseline " io.rsocket:rsocket-core:${ perfBaselineVersion} " , {
22
+ changing = true
23
+ }
24
+ baseline " io.rsocket:rsocket-transport-local:${ perfBaselineVersion} " , {
25
+ changing = true
26
+ }
27
+ }
28
+
29
+ task jmhProfilers (type : JavaExec , description :' Lists the available profilers for the jmh task' , group : ' Development' ) {
30
+ classpath = sourceSets. main. runtimeClasspath
31
+ main = ' org.openjdk.jmh.Main'
32
+ args ' -lprof'
33
+ }
34
+
35
+ task jmh (type : JmhExecTask , description : ' Executing JMH benchmarks' ) {
36
+ classpath = sourceSets. main. runtimeClasspath + configurations. current
37
+ }
38
+
39
+ task jmhBaseline (type : JmhExecTask , description : ' Executing JMH baseline benchmarks' ) {
40
+ classpath = sourceSets. main. runtimeClasspath + configurations. baseline
41
+ }
42
+
43
+ class JmhExecTask extends JavaExec {
44
+
45
+ private String include;
46
+ private String fullInclude;
47
+ private String exclude;
48
+ private String format = " json" ;
49
+ private String profilers;
50
+ private String jmhJvmArgs;
51
+ private String verify;
52
+
53
+ public JmhExecTask () {
54
+ super ();
55
+ }
56
+
57
+ public String getInclude () {
58
+ return include;
59
+ }
60
+
61
+ @Option (option = " include" , description = " configure bench inclusion using substring" )
62
+ public void setInclude (String include ) {
63
+ this . include = include;
64
+ }
65
+
66
+ public String getFullInclude () {
67
+ return fullInclude;
68
+ }
69
+
70
+ @Option (option = " fullInclude" , description = " explicitly configure bench inclusion using full JMH style regexp" )
71
+ public void setFullInclude (String fullInclude ) {
72
+ this . fullInclude = fullInclude;
73
+ }
74
+
75
+ public String getExclude () {
76
+ return exclude;
77
+ }
78
+
79
+ @Option (option = " exclude" , description = " explicitly configure bench exclusion using full JMH style regexp" )
80
+ public void setExclude (String exclude ) {
81
+ this . exclude = exclude;
82
+ }
83
+
84
+ public String getFormat () {
85
+ return format;
86
+ }
87
+
88
+ @Option (option = " format" , description = " configure report format" )
89
+ public void setFormat (String format ) {
90
+ this . format = format;
91
+ }
92
+
93
+ public String getProfilers () {
94
+ return profilers;
95
+ }
96
+
97
+ @Option (option = " profilers" , description = " configure jmh profiler(s) to use, comma separated" )
98
+ public void setProfilers (String profilers ) {
99
+ this . profilers = profilers;
100
+ }
101
+
102
+ public String getJmhJvmArgs () {
103
+ return jmhJvmArgs;
104
+ }
105
+
106
+ @Option (option = " jvmArgs" , description = " configure additional JMH JVM arguments, comma separated" )
107
+ public void setJmhJvmArgs (String jvmArgs ) {
108
+ this . jmhJvmArgs = jvmArgs;
109
+ }
110
+
111
+ public String getVerify () {
112
+ return verify;
113
+ }
114
+
115
+ @Option (option = " verify" , description = " run in verify mode" )
116
+ public void setVerify (String verify ) {
117
+ this . verify = verify;
118
+ }
119
+
120
+ @TaskAction
121
+ public void exec () {
122
+ setMain(" org.openjdk.jmh.Main" );
123
+ File resultFile = getProject(). file(" build/reports/" + getName() + " /result." + format);
124
+
125
+ if (include != null ) {
126
+ args(" .*" + include + " .*" );
127
+ }
128
+ else if (fullInclude != null ) {
129
+ args(fullInclude);
130
+ }
131
+
132
+ if (exclude != null ) {
133
+ args(" -e" , exclude);
134
+ }
135
+ if (verify != null ) { // execute benchmarks with the minimum amount of execution (only to check if they are working)
136
+ System . out. println (" Running in verify mode" );
137
+ args(" -f" , 1 );
138
+ args(" -wi" , 1 );
139
+ args(" -i" , 1 );
140
+ }
141
+ args(" -foe" , " true" ); // fail-on-error
142
+ args(" -v" , " NORMAL" ); // verbosity [SILENT, NORMAL, EXTRA]
143
+ if (profilers != null ) {
144
+ for (String prof : profilers. split(" ," )) {
145
+ args(" -prof" , prof);
146
+ }
147
+ }
148
+ args(" -jvmArgsPrepend" , " -Xmx3072m" );
149
+ args(" -jvmArgsPrepend" , " -Xms3072m" );
150
+ if (jmhJvmArgs != null ) {
151
+ for (String jvmArg : jmhJvmArgs. split(" " )) {
152
+ args(" -jvmArgsPrepend" , jvmArg);
153
+ }
154
+ }
155
+ args(" -rf" , format);
156
+ args(" -rff" , resultFile);
157
+
158
+ System . out. println (" \n Executing JMH with: " + getArgs() + " \n " );
159
+ resultFile. getParentFile(). mkdirs();
160
+
161
+ super . exec();
162
+ }
163
+ }
0 commit comments