changeset 1057:87eea88f9819

7901126: Print JMH version in the run output
author shade
date Thu, 11 Dec 2014 16:42:22 +0300
parents 73451bc77ee0
children 86754261b8bb
files jmh-core/pom.xml jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java jmh-core/src/main/java/org/openjdk/jmh/util/Version.java jmh-core/src/main/resources/jmh.properties
diffstat 5 files changed, 112 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/pom.xml	Wed Dec 10 16:08:49 2014 +0300
+++ b/jmh-core/pom.xml	Thu Dec 11 16:42:22 2014 +0300
@@ -75,6 +75,8 @@
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <timestamp>${maven.build.timestamp}</timestamp>
+        <maven.build.timestamp.format>EEE MMM dd HH:mm:ss zzz yyyy</maven.build.timestamp.format>
     </properties>
 
     <build>
@@ -135,6 +137,13 @@
                 <artifactId>wagon-ssh</artifactId>
             </extension>
         </extensions>
+
+        <resources>
+            <resource>
+                <directory>src/main/resources/</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
     </build>
 
     <repositories>
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Wed Dec 10 16:08:49 2014 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseRunner.java	Thu Dec 11 16:42:22 2014 +0300
@@ -35,6 +35,7 @@
 import org.openjdk.jmh.util.Multimap;
 import org.openjdk.jmh.util.TreeMultimap;
 import org.openjdk.jmh.util.Utils;
+import org.openjdk.jmh.util.Version;
 
 import java.lang.management.GarbageCollectorMXBean;
 import java.lang.management.ManagementFactory;
@@ -86,6 +87,8 @@
                     realOpts = "<none>";
                 }
 
+                Version.printVersion(out);
+                out.println("# VM invoker: " + params.getJvm());
                 out.println("# VM invoker: " + params.getJvm());
                 out.println("# VM options: " + realOpts + (opts.equals(realOpts) ? "" : " *** WARNING: some JVM options are ignored in non-forked runs ***"));
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Wed Dec 10 16:08:49 2014 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Thu Dec 11 16:42:22 2014 +0300
@@ -48,6 +48,7 @@
 import org.openjdk.jmh.util.TreeMultimap;
 import org.openjdk.jmh.util.UnCloseablePrintStream;
 import org.openjdk.jmh.util.Utils;
+import org.openjdk.jmh.util.Version;
 
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -593,6 +594,7 @@
                 opts = "<none>";
             }
 
+            Version.printVersion(out);
             out.println("# VM invoker: " + params.getJvm());
             out.println("# VM options: " + opts);
             out.startBenchmark(params);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/Version.java	Thu Dec 11 16:42:22 2014 +0300
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.util;
+
+import org.openjdk.jmh.runner.format.OutputFormat;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+public class Version {
+
+    public static void printVersion(OutputFormat pw) {
+        Properties p = new Properties();
+        InputStream s = Version.class.getResourceAsStream("/jmh.properties");
+        String time = null;
+        if (s != null) {
+            try {
+                p.load(s);
+                time = (String) p.get("jmh.buildTime");
+
+                Date parse = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(time);
+                long diff = (System.currentTimeMillis() - parse.getTime()) / TimeUnit.DAYS.toMillis(1);
+
+                pw.print("# JMH " + p.get("jmh.version") + " (released ");
+                if (diff > 0) {
+                    pw.print(String.format("%d days ago", diff));
+                    if (diff > 30) {
+                        pw.print(", please consider updating!");
+                    }
+                } else {
+                    pw.print("today");
+                }
+                pw.println(")");
+            } catch (IOException e) {
+                pw.println("# Can not figure out JMH version");
+            } catch (ParseException e) {
+                pw.println("# Can not figure out JMH version, unable to parse the build time: " + time);
+            }
+        } else {
+            pw.println("# Can not figure out JMH version, no jmh.properties");
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/main/resources/jmh.properties	Thu Dec 11 16:42:22 2014 +0300
@@ -0,0 +1,27 @@
+#
+# Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+jmh.version=${project.version}
+jmh.buildTime=${timestamp}
\ No newline at end of file