changeset 1324:70dfb4a93cf5

7901708: Inconsistency in labelling and usage for dynamically discovered profilers Summary: print FQN for dynamically discovered profilers in profiler list.
author shade
date Tue, 12 Jul 2016 23:46:52 +0300
parents 086e57a61659
children 49e2fb0c9f3b
files jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerFactory.java
diffstat 1 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerFactory.java	Tue Jul 12 22:06:25 2016 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerFactory.java	Tue Jul 12 23:46:52 2016 +0300
@@ -112,6 +112,15 @@
     }
 
     public static void listProfilers(PrintStream out) {
+        int maxLen = 0;
+        for (String s : BUILT_IN.keySet()) {
+            maxLen = Math.max(maxLen, s.length());
+        }
+        for (Class<? extends Profiler> s : ProfilerFactory.getDiscoveredProfilers()) {
+            maxLen = Math.max(maxLen, s.getCanonicalName().length());
+        }
+        maxLen += 2;
+
         StringBuilder supported = new StringBuilder();
         StringBuilder unsupported = new StringBuilder();
 
@@ -121,13 +130,13 @@
                 String descr = (prof != null) ? prof.getDescription() : "(unable to instantiate the profiler)";
 
                 if (prof != null) {
-                    supported.append(String.format("%20s: %s %s\n", s, descr, ""));
+                    supported.append(String.format("%" + maxLen + "s: %s %s\n", s, descr, ""));
                 } else {
-                    unsupported.append(String.format("%20s: %s %s\n", s, descr, ""));
+                    unsupported.append(String.format("%" + maxLen + "s: %s %s\n", s, descr, ""));
                     unsupported.append("\n");
                 }
             } catch (ProfilerException e) {
-                unsupported.append(String.format("%20s: %s %s\n", s, "<none>", ""));
+                unsupported.append(String.format("%" + maxLen + "s: %s %s\n", s, "<none>", ""));
                 unsupported.append(e.getMessage());
                 unsupported.append("\n");
             }
@@ -139,13 +148,13 @@
                 String descr = (prof != null) ? prof.getDescription() : "(unable to instantiate the profiler)";
 
                 if (prof != null) {
-                    supported.append(String.format("%20s: %s %s\n", "<none>", descr, "(discovered)"));
+                    supported.append(String.format("%" + maxLen + "s: %s %s\n", s.getCanonicalName(), descr, "(discovered)"));
                 } else {
-                    unsupported.append(String.format("%20s: %s %s\n", "<none>", descr, "(discovered)"));
+                    unsupported.append(String.format("%" + maxLen + "s: %s %s\n", s.getCanonicalName(), descr, "(discovered)"));
                     unsupported.append("\n");
                 }
             } catch (ProfilerException e) {
-                unsupported.append(String.format("%20s: %s %s\n", s, "<none>", ""));
+                unsupported.append(String.format("%" + maxLen + "s: %s %s\n", s, s.getCanonicalName(), ""));
                 unsupported.append(e.getMessage());
                 unsupported.append("\n");
             }