< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/SnippetCounter.java

Print this page




  76             }
  77 
  78             StringBuilder buf = new StringBuilder(String.format("Counters: %s%n", name));
  79 
  80             String formatString = "  %" + maxNameLen + "s: %6.2f%%%," + (String.format("%,d", total).length() + 2) + "d  // %s%n";
  81             for (SnippetCounter c : counters) {
  82                 double percent = total == 0D ? 0D : ((double) (c.value * 100)) / total;
  83                 buf.append(String.format(formatString, c.name, percent, c.value, c.description));
  84             }
  85             buf.append(String.format(formatString, "TOTAL", 100.0D, total, ""));
  86 
  87             return buf.toString();
  88         }
  89     }
  90 
  91     /**
  92      * Sorts counters in descending order of their {@linkplain #value() values}.
  93      */
  94     @Override
  95     public int compareTo(SnippetCounter o) {
  96         if (value > o.value) {
  97             return -1;
  98         } else if (o.value < value) {
  99             return 1;
 100         }
 101         return 0;
 102     }
 103 
 104     private final Group group;
 105     private final String name;
 106     private final String description;
 107     private long value;
 108 
 109     /**
 110      * Creates a counter.
 111      *
 112      * @param group the group to which the counter belongs. If this is null, the newly created
 113      *            counter is disabled and {@linkplain #inc() incrementing} is a no-op.
 114      * @param name the name of the counter
 115      * @param description a brief comment describing the metric represented by the counter
 116      */
 117     public SnippetCounter(Group group, String name, String description) {
 118         this.group = group;
 119         this.name = name;
 120         this.description = description;
 121         if (group != null) {




  76             }
  77 
  78             StringBuilder buf = new StringBuilder(String.format("Counters: %s%n", name));
  79 
  80             String formatString = "  %" + maxNameLen + "s: %6.2f%%%," + (String.format("%,d", total).length() + 2) + "d  // %s%n";
  81             for (SnippetCounter c : counters) {
  82                 double percent = total == 0D ? 0D : ((double) (c.value * 100)) / total;
  83                 buf.append(String.format(formatString, c.name, percent, c.value, c.description));
  84             }
  85             buf.append(String.format(formatString, "TOTAL", 100.0D, total, ""));
  86 
  87             return buf.toString();
  88         }
  89     }
  90 
  91     /**
  92      * Sorts counters in descending order of their {@linkplain #value() values}.
  93      */
  94     @Override
  95     public int compareTo(SnippetCounter o) {
  96         return Long.signum(o.value - value);





  97     }
  98 
  99     private final Group group;
 100     private final String name;
 101     private final String description;
 102     private long value;
 103 
 104     /**
 105      * Creates a counter.
 106      *
 107      * @param group the group to which the counter belongs. If this is null, the newly created
 108      *            counter is disabled and {@linkplain #inc() incrementing} is a no-op.
 109      * @param name the name of the counter
 110      * @param description a brief comment describing the metric represented by the counter
 111      */
 112     public SnippetCounter(Group group, String name, String description) {
 113         this.group = group;
 114         this.name = name;
 115         this.description = description;
 116         if (group != null) {


< prev index next >