Class IOStatisticsLogging

java.lang.Object
org.apache.hadoop.fs.statistics.IOStatisticsLogging

@Public @Unstable public final class IOStatisticsLogging extends Object
Utility operations convert IO Statistics sources/instances to strings, especially for robustly logging.
  • Method Details

    • ioStatisticsSourceToString

      public static String ioStatisticsSourceToString(@Nullable Object source)
      Extract the statistics from a source object -or "" if it is not an instance of IOStatistics, IOStatisticsSource or the retrieved statistics are null.

      Exceptions are caught and downgraded to debug logging.

      Parameters:
      source - source of statistics.
      Returns:
      a string for logging.
    • ioStatisticsToString

      public static String ioStatisticsToString(@Nullable IOStatistics statistics)
      Convert IOStatistics to a string form.
      Parameters:
      statistics - A statistics instance.
      Returns:
      string value or the empty string if null
    • ioStatisticsToPrettyString

      public static String ioStatisticsToPrettyString(@Nullable IOStatistics statistics)
      Convert IOStatistics to a string form, with all the metrics sorted and empty value stripped. This is more expensive than the simple conversion, so should only be used for logging/output where it's known/highly likely that the caller wants to see the values. Not for debug logging.
      Parameters:
      statistics - A statistics instance.
      Returns:
      string value or the empty string if null
    • demandStringifyIOStatisticsSource

      public static Object demandStringifyIOStatisticsSource(@Nullable org.apache.hadoop.fs.statistics.IOStatisticsSource source)
      On demand stringifier of an IOStatisticsSource instance.

      Whenever this object's toString() method is called, it evaluates the statistics.

      This is designed to affordable to use in log statements.

      Parameters:
      source - source of statistics -may be null.
      Returns:
      an object whose toString() operation returns the current values.
    • demandStringifyIOStatistics

      public static Object demandStringifyIOStatistics(@Nullable IOStatistics statistics)
      On demand stringifier of an IOStatistics instance.

      Whenever this object's toString() method is called, it evaluates the statistics.

      This is for use in log statements where for the cost of creation of this entry is low; it is affordable to use in log statements.

      Parameters:
      statistics - statistics to stringify -may be null.
      Returns:
      an object whose toString() operation returns the current values.
    • logIOStatisticsAtDebug

      public static void logIOStatisticsAtDebug(org.slf4j.Logger log, String message, Object source)
      Extract any statistics from the source and log at debug, if the log is set to log at debug. No-op if logging is not at debug or the source is null/of the wrong type/doesn't provide statistics.
      Parameters:
      log - log to log to
      message - message for log -this must contain "{}" for the statistics report to actually get logged.
      source - source object
    • logIOStatisticsAtDebug

      public static void logIOStatisticsAtDebug(String message, Object source)
      Extract any statistics from the source and log to this class's log at debug, if the log is set to log at debug. No-op if logging is not at debug or the source is null/of the wrong type/doesn't provide statistics.
      Parameters:
      message - message for log -this must contain "{}" for the statistics report to actually get logged.
      source - source object
    • logIOStatisticsAtLevel

      public static void logIOStatisticsAtLevel(org.slf4j.Logger log, String level, Object source)
      A method to log IOStatistics from a source at different levels.
      Parameters:
      log - Logger for logging.
      level - LOG level.
      source - Source to LOG.