lukecwik commented on code in PR #23041:
URL: https://github.com/apache/beam/pull/23041#discussion_r964023508


##########
buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy:
##########
@@ -1411,8 +1413,13 @@ class BeamModulePlugin implements Plugin<Project> {
 
         project.tasks.register("jmh", JavaExec)  {
           dependsOn project.classes
-          mainClass = "org.openjdk.jmh.Main"
+          mainClass = "org.apache.beam.sdk.testutils.jmh.Main"
           classpath = project.sourceSets.main.runtimeClasspath
+
+          environment([
+            'INFLUXDB_MEASUREMENT': 'java_jmh_' + (getPath().split(':') - ['', 
'sdks', 'java', 'jmh']).join('_')

Review Comment:
   Why is it important to split up the JMH benchmarks under different 
measurements?



##########
sdks/java/testing/test-utils/src/main/java/org/apache/beam/sdk/testutils/jmh/Main.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.beam.sdk.testutils.jmh;
+
+import static java.util.function.Function.identity;
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+import static org.openjdk.jmh.annotations.Mode.SingleShotTime;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.testutils.publishing.InfluxDBPublisher;
+import org.apache.beam.sdk.testutils.publishing.InfluxDBPublisher.DataPoint;
+import org.apache.beam.sdk.testutils.publishing.InfluxDBSettings;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.infra.BenchmarkParams;
+import org.openjdk.jmh.results.BenchmarkResult;
+import org.openjdk.jmh.results.BenchmarkResultMetaData;
+import org.openjdk.jmh.results.Result;
+import org.openjdk.jmh.results.RunResult;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.CommandLineOptionException;
+import org.openjdk.jmh.runner.options.CommandLineOptions;
+
+/**
+ * Custom main wrapper around the {@link Runner JMH runner} that supports 
publishing benchmarks to
+ * InfluxDB.
+ *
+ * <p>If {@link InfluxDBSettings} can be inferred from the environment, 
benchmark results will be
+ * published to InfluxDB. Otherwise this will just delegate to the default 
{@link
+ * org.openjdk.jmh.Main JMH Main} class.
+ *
+ * <p>Use the following environment variables to configure {@link 
InfluxDBSettings}:

Review Comment:
   Can we document what attributes we are inserting into the influx db so that 
people who are writing a benchmark know what this will produce (particularly 
for folks using parameterized benchmarks) and under what generated measurement 
name?
   



##########
sdks/java/testing/test-utils/src/main/java/org/apache/beam/sdk/testutils/jmh/Main.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.beam.sdk.testutils.jmh;
+
+import static java.util.function.Function.identity;
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
+import static org.openjdk.jmh.annotations.Mode.SingleShotTime;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.testutils.publishing.InfluxDBPublisher;
+import org.apache.beam.sdk.testutils.publishing.InfluxDBPublisher.DataPoint;
+import org.apache.beam.sdk.testutils.publishing.InfluxDBSettings;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.infra.BenchmarkParams;
+import org.openjdk.jmh.results.BenchmarkResult;
+import org.openjdk.jmh.results.BenchmarkResultMetaData;
+import org.openjdk.jmh.results.Result;
+import org.openjdk.jmh.results.RunResult;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.CommandLineOptionException;
+import org.openjdk.jmh.runner.options.CommandLineOptions;
+
+/**
+ * Custom main wrapper around the {@link Runner JMH runner} that supports 
publishing benchmarks to
+ * InfluxDB.
+ *
+ * <p>If {@link InfluxDBSettings} can be inferred from the environment, 
benchmark results will be
+ * published to InfluxDB. Otherwise this will just delegate to the default 
{@link
+ * org.openjdk.jmh.Main JMH Main} class.
+ *
+ * <p>Use the following environment variables to configure {@link 
InfluxDBSettings}:
+ *
+ * <ul>
+ *   <li>{@link #INFLUXDB_HOST}
+ *   <li>{@link #INFLUXDB_DATABASE}
+ *   <li>{@link #INFLUXDB_MEASUREMENT}
+ * </ul>
+ */
+public class Main {
+  private static final String INFLUXDB_HOST = "INFLUXDB_HOST";
+  private static final String INFLUXDB_DATABASE = "INFLUXDB_DATABASE";
+  private static final String INFLUXDB_MEASUREMENT = "INFLUXDB_MEASUREMENT";
+
+  public static void main(String[] args)
+      throws CommandLineOptionException, IOException, RunnerException {
+    final CommandLineOptions opts = new CommandLineOptions(args);
+    final InfluxDBSettings influxDB = influxDBSettings();
+
+    if (influxDB == null
+        || isSingleShotTimeOnly(opts.getBenchModes())
+        || opts.shouldHelp()
+        || opts.shouldList()
+        || opts.shouldListWithParams()
+        || opts.shouldListProfilers()
+        || opts.shouldListResultFormats()) {
+      // delegate to JMH runner
+      org.openjdk.jmh.Main.main(args);
+      return;
+    }
+
+    final Runner runner = new Runner(opts);
+    final Collection<RunResult> results = runner.run();
+
+    final Collection<DataPoint> dataPoints =
+        results.stream()
+            .filter(r -> r.getParams().getMode() != SingleShotTime)

Review Comment:
   How do we filter out runs that failed?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to