|
| 1 | +/* |
| 2 | + * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. Oracle designates this |
| 8 | + * particular file as subject to the "Classpath" exception as provided |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. |
| 10 | + * |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | + * accompanied this code). |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License version |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | + * |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | + * or visit www.oracle.com if you need additional information or have any |
| 23 | + * questions. |
| 24 | + */ |
| 25 | +package org.openjdk.jmh.validation.tests; |
| 26 | + |
| 27 | +import org.openjdk.jmh.benchmarks.CoreStabilityBench; |
| 28 | +import org.openjdk.jmh.results.Result; |
| 29 | +import org.openjdk.jmh.results.RunResult; |
| 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 | +import org.openjdk.jmh.runner.options.VerboseMode; |
| 35 | +import org.openjdk.jmh.util.Utils; |
| 36 | +import org.openjdk.jmh.validation.AffinitySupport; |
| 37 | +import org.openjdk.jmh.validation.ValidationTest; |
| 38 | + |
| 39 | +import java.io.PrintWriter; |
| 40 | +import java.util.concurrent.ThreadLocalRandom; |
| 41 | + |
| 42 | +public class CoreStabilityTest extends ValidationTest { |
| 43 | + |
| 44 | + @Override |
| 45 | + public void runWith(PrintWriter pw, Options parent) throws RunnerException { |
| 46 | + pw.println("--------- CORE STABILITY TEST"); |
| 47 | + pw.println(); |
| 48 | + |
| 49 | + org.openjdk.jmh.util.Utils.reflow(pw, |
| 50 | + "This test verifies the performance for a single test by running it on different CPUs. " + |
| 51 | + "For perfectly symmetric machines, the performance should be the same across all CPUs. " + |
| 52 | + "If there is a significant difference between the CPUs, this is usually " + |
| 53 | + "indicative of asymmetric machine, making the benchmarks that do not explicitly control " + |
| 54 | + "affinity less reliable.", |
| 55 | + 80, 2); |
| 56 | + pw.println(); |
| 57 | + |
| 58 | + if (!AffinitySupport.isSupported()) { |
| 59 | + pw.println(" Affinity control is not available on this machine, skipping the test."); |
| 60 | + pw.println(); |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + int threads = Utils.figureOutHotCPUs(); |
| 65 | + |
| 66 | + for (int p = 0; p < threads; p++) { |
| 67 | + pw.printf(" CPU %3d: ", p); |
| 68 | + pw.flush(); |
| 69 | + |
| 70 | + Options opts = new OptionsBuilder() |
| 71 | + .parent(parent) |
| 72 | + .include(CoreStabilityBench.class.getCanonicalName()) |
| 73 | + .param("p", String.valueOf(p)) |
| 74 | + .verbosity(VerboseMode.SILENT) |
| 75 | + .build(); |
| 76 | + |
| 77 | + RunResult result = new Runner(opts).runSingle(); |
| 78 | + Result r = result.getPrimaryResult(); |
| 79 | + pw.printf(" %16s", String.format("%.2f \u00b1 %.2f %s%n", r.getScore(), r.getScoreError(), r.getScoreUnit())); |
| 80 | + pw.flush(); |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments