1 /*
   2  * Copyright (c) 2012, Oracle and/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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.debug;
  24 
  25 import java.util.Comparator;
  26 
  27 import org.graalvm.util.Pair;
  28 
  29 /**
  30  * A key for a metric.
  31  */
  32 public interface MetricKey {
  33 
  34     /**
  35      * Converts a given value for this key to a string, scaling it to a more useful unit of
  36      * measurement and appending a suffix indicating the unit where applicable. This representation
  37      * is intended for human consumption.
  38      */
  39     String toHumanReadableFormat(long value);
  40 
  41     /**
  42      * Converts a given value for this key to a CSV format intended for automated data processing.
  43      *
  44      * @param value
  45      * @return a pair where first is the {@code value} with any scaling conversion applied and
  46      *         second is the unit of measurement used for the first component (this will be the
  47      *         empty string for a simple counter)
  48      */
  49     Pair<String, String> toCSVFormat(long value);
  50 
  51     /**
  52      * Gets the name of this key.
  53      */
  54     String getName();
  55 
  56     /**
  57      * Comparator to sort keys by their names.
  58      */
  59     Comparator<MetricKey> NAME_COMPARATOR = new Comparator<MetricKey>() {
  60 
  61         @Override
  62         public int compare(MetricKey o1, MetricKey o2) {
  63             return o1.getName().compareTo(o2.getName());
  64         }
  65 
  66     };
  67 
  68     /**
  69      * Sets the documentation for this key.
  70      */
  71     MetricKey doc(String string);
  72 
  73     /**
  74      * Gets the name to use when listing keys. Note that this may be different from
  75      * {@link #getName()}.
  76      *
  77      * @return {@code null} if this key is derived from another key and so should not be listed
  78      */
  79     String getDocName();
  80 
  81     /**
  82      * Gets the documentation for this key.
  83      *
  84      * @return {@code null} if this key has no documentation
  85      */
  86     String getDoc();
  87 }