Skip to content

Commit 185c235

Browse files
authored
Merge pull request #198 from metafacture/hprofAndJmh
Add infrastructure for profiling and benchmarking.
2 parents 62b2eb2 + a7526fe commit 185c235

File tree

11 files changed

+263
-2
lines changed

11 files changed

+263
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ out/
66
node_modules/
77
xtext-server/
88
package-lock.json
9+
*.hprof.txt
910
*.vsix
1011
/metafix/src/test/resources/org/metafacture/metafix/integration/**/*.diff
1112
/metafix/src/test/resources/org/metafacture/metafix/integration/**/*.err

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66

77
editorconfig {
88
excludes = [
9+
'**/*.hprof.txt',
910
'**/*.out',
1011
'**/*.vsix',
1112
'**/.*',

metafix-runner/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ dependencies {
1111

1212
application {
1313
mainClass = 'org.metafacture.runner.Flux'
14+
15+
if (project.hasProperty('profile')) {
16+
def file = project.getProperty('profile') ?: project.name
17+
applicationDefaultJvmArgs = ["-agentlib:hprof=heap=sites,cpu=samples,file=${file}.hprof.txt"]
18+
}
1419
}

metafix/build.gradle

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id 'maven-publish'
3+
id 'me.champeau.jmh' version '0.6.6'
34
}
45

56
def passSystemProperties = {
@@ -45,6 +46,14 @@ dependencies {
4546
mwe2 "org.eclipse.xtext:org.eclipse.xtext.common.types:${versions.xtext}"
4647
mwe2 "org.eclipse.xtext:org.eclipse.xtext.xtext.generator:${versions.xtext}"
4748
mwe2 'org.eclipse.xtext:xtext-antlr-generator'
49+
50+
jmh "org.metafacture:metafacture-io:${versions.metafacture}"
51+
jmh "org.metafacture:metafacture-json:${versions.metafacture}"
52+
}
53+
54+
jmhJar {
55+
// SLF4J: Class path contains multiple SLF4J bindings.
56+
exclude '/org/slf4j/impl/StaticLoggerBinder.class'
4857
}
4958

5059
test {
@@ -64,7 +73,14 @@ test {
6473
task integrationTest(type: Exec, group: 'Verification') {
6574
executable './integrationTest.sh'
6675

67-
if (project.hasProperty('args')) args project.getProperty('args').split()
76+
if (project.hasProperty('args')) {
77+
args project.getProperty('args').split()
78+
}
79+
80+
if (project.hasProperty('profile')) {
81+
environment.METAFIX_INTEGRATION_TEST_PROFILE = project.getProperty('profile')
82+
}
83+
6884
environment.METAFIX_DISABLE_TO_DO = System.getProperty('org.metafacture.metafix.disableToDo')
6985
}
7086

metafix/integrationTest.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function parse_boolean() {
2525
}
2626

2727
parse_boolean "$METAFIX_DISABLE_TO_DO" && disable_todo=1 || disable_todo=
28+
parse_boolean "$METAFIX_INTEGRATION_TEST_PROFILE" && noprofile= || noprofile=no
2829

2930
[ -t 1 -a -x /usr/bin/colordiff ] && colordiff=colordiff || colordiff=cat
3031

@@ -66,7 +67,7 @@ function die() {
6667
}
6768

6869
function run_metafix() {
69-
$gradle_command -p "$root_directory" :metafix-runner:run --args="$1"
70+
$gradle_command -p "$root_directory" :metafix-runner:run --args="$1" -P${noprofile}profile="${1%.*}"
7071
}
7172

7273
function run_catmandu() {
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2022 hbz NRW
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.metafacture.metafix;
18+
19+
import org.openjdk.jmh.annotations.Benchmark;
20+
import org.openjdk.jmh.annotations.BenchmarkMode;
21+
import org.openjdk.jmh.annotations.Fork;
22+
import org.openjdk.jmh.annotations.Measurement;
23+
import org.openjdk.jmh.annotations.Mode;
24+
import org.openjdk.jmh.annotations.OutputTimeUnit;
25+
import org.openjdk.jmh.annotations.Scope;
26+
import org.openjdk.jmh.annotations.State;
27+
import org.openjdk.jmh.annotations.Warmup;
28+
//import org.openjdk.jmh.profile.GCProfiler;
29+
//import org.openjdk.jmh.profile.StackProfiler;
30+
//import org.openjdk.jmh.runner.Runner;
31+
//import org.openjdk.jmh.runner.RunnerException;
32+
//import org.openjdk.jmh.runner.options.Options;
33+
//import org.openjdk.jmh.runner.options.OptionsBuilder;
34+
35+
import java.util.concurrent.TimeUnit;
36+
37+
@Fork(2)
38+
@Warmup(iterations = 2)
39+
@Measurement(iterations = 4) // checkstyle-disable-line MagicNumber
40+
@BenchmarkMode(Mode.Throughput) // AverageTime
41+
@OutputTimeUnit(TimeUnit.SECONDS)
42+
@State(Scope.Thread)
43+
public abstract class AbstractBenchmark {
44+
45+
public AbstractBenchmark() {
46+
}
47+
48+
@Benchmark
49+
public void benchmark() {
50+
workload();
51+
}
52+
53+
protected abstract void workload();
54+
55+
/*
56+
public static void main(final String[] args) throws RunnerException {
57+
final Options opt = new OptionsBuilder()
58+
.include(MetafixBenchmark.class.getSimpleName())
59+
.addProfiler(StackProfiler.class)
60+
//.addProfiler(GCProfiler.class)
61+
.build();
62+
63+
new Runner(opt).run();
64+
}
65+
*/
66+
67+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2022 hbz NRW
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.metafacture.metafix;
18+
19+
import org.openjdk.jmh.annotations.OutputTimeUnit;
20+
21+
import java.util.concurrent.TimeUnit;
22+
23+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
24+
public class BaselineBenchmark extends AbstractBenchmark {
25+
26+
public BaselineBenchmark() {
27+
}
28+
29+
@Override
30+
protected void workload() {
31+
// this method was intentionally left blank.
32+
}
33+
34+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2022 hbz NRW
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.metafacture.metafix;
18+
19+
import org.openjdk.jmh.annotations.Param;
20+
import org.openjdk.jmh.annotations.Setup;
21+
22+
public class FixParseBenchmark extends AbstractBenchmark {
23+
24+
protected static final String BASE = "src/jmh/resources/org/metafacture/metafix";
25+
26+
private static final String FIXES = BASE + "/fixes/%s" + Metafix.FIX_EXTENSION;
27+
28+
protected String fixFile; // checkstyle-disable-line VisibilityModifier
29+
30+
@Param({ // checkstyle-disable-line AnnotationUseStyle
31+
"nothing"
32+
})
33+
private String fixDef;
34+
35+
public FixParseBenchmark() {
36+
}
37+
38+
@Setup
39+
public void setup() {
40+
fixFile = String.format(FIXES, fixDef);
41+
}
42+
43+
@Override
44+
protected void workload() {
45+
FixStandaloneSetup.parseFix(fixFile);
46+
}
47+
48+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright 2022 hbz NRW
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.metafacture.metafix;
18+
19+
import org.metafacture.framework.helpers.DefaultStreamReceiver;
20+
import org.metafacture.io.FileOpener;
21+
import org.metafacture.io.ObjectStdoutWriter;
22+
import org.metafacture.io.RecordReader;
23+
import org.metafacture.json.JsonDecoder;
24+
import org.metafacture.json.JsonEncoder;
25+
26+
import org.openjdk.jmh.annotations.Param;
27+
28+
import java.io.FileNotFoundException;
29+
import java.io.UncheckedIOException;
30+
31+
public class MetafixBenchmark extends FixParseBenchmark { // checkstyle-disable-line ClassDataAbstractionCoupling
32+
33+
// TODO: Need to inject system properties into JMHTask's JavaExec process.
34+
//private static final boolean DEBUG_OUTPUT = Boolean.parseBoolean(System.getProperty("org.metafacture.metafix.debugBenchmarkOutput"));
35+
private static final boolean DEBUG_OUTPUT = false;
36+
37+
private static final String INPUT = BASE + "/input/%s.json";
38+
39+
private FileOpener fileOpener;
40+
private String inputFile;
41+
42+
@Param({ // checkstyle-disable-line AnnotationUseStyle
43+
"empty"
44+
})
45+
private String input;
46+
47+
public MetafixBenchmark() {
48+
}
49+
50+
@Override
51+
public void setup() {
52+
super.setup();
53+
54+
inputFile = String.format(INPUT, input);
55+
56+
final Metafix metafix;
57+
try {
58+
metafix = new Metafix(fixFile);
59+
}
60+
catch (final FileNotFoundException e) {
61+
throw new UncheckedIOException(e);
62+
}
63+
64+
if (DEBUG_OUTPUT) {
65+
metafix
66+
.setReceiver(new JsonEncoder())
67+
.setReceiver(new ObjectStdoutWriter<String>());
68+
}
69+
else {
70+
metafix
71+
.setReceiver(new DefaultStreamReceiver());
72+
}
73+
74+
fileOpener = new FileOpener();
75+
fileOpener
76+
.setReceiver(new RecordReader())
77+
.setReceiver(new JsonDecoder())
78+
.setReceiver(metafix);
79+
}
80+
81+
@Override
82+
protected void workload() {
83+
fileOpener.process(inputFile);
84+
}
85+
86+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nothing()

0 commit comments

Comments
 (0)