Class WrappedStatistics

java.lang.Object
org.apache.hadoop.io.wrappedio.WrappedStatistics

@Public @Unstable public final class WrappedStatistics extends Object
Reflection-friendly access to IOStatistics APIs. All Serializable arguments/return values are actually IOStatisticsSource instances; passing in the wrong value will raise IllegalArgumentExceptions.
  • Method Details

    • isIOStatisticsSource

      public static boolean isIOStatisticsSource(Object object)
      Probe for an object being an instance of IOStatisticsSource.
      Parameters:
      object - object to probe
      Returns:
      true if the object is the right type.
    • isIOStatistics

      public static boolean isIOStatistics(Object object)
      Probe for an object being an instance of IOStatistics.
      Parameters:
      object - object to probe
      Returns:
      true if the object is the right type.
    • isIOStatisticsSnapshot

      public static boolean isIOStatisticsSnapshot(Serializable object)
      Probe for an object being an instance of IOStatisticsSnapshot.
      Parameters:
      object - object to probe
      Returns:
      true if the object is the right type.
    • iostatisticsSnapshot_aggregate

      public static boolean iostatisticsSnapshot_aggregate(Serializable snapshot, @Nullable Object statistics)
      Aggregate an existing IOStatisticsSnapshot with the supplied statistics.
      Parameters:
      snapshot - snapshot to update
      statistics - IOStatistics to add
      Returns:
      true if the snapshot was updated.
      Throws:
      IllegalArgumentException - if the statistics argument is not null but not an instance of IOStatistics, or if snapshot is invalid.
    • iostatisticsSnapshot_create

      public static Serializable iostatisticsSnapshot_create()
      Create a new IOStatisticsSnapshot instance.
      Returns:
      an empty IOStatisticsSnapshot.
    • iostatisticsSnapshot_create

      public static Serializable iostatisticsSnapshot_create(@Nullable Object source)
      Create a new IOStatisticsSnapshot instance.
      Parameters:
      source - optional source statistics
      Returns:
      an IOStatisticsSnapshot.
      Throws:
      ClassCastException - if the source is not null and not an IOStatistics instance
    • iostatisticsSnapshot_load

      public static Serializable iostatisticsSnapshot_load(FileSystem fs, Path path)
      Load IOStatisticsSnapshot from a Hadoop filesystem.
      Parameters:
      fs - filesystem
      path - path
      Returns:
      the loaded snapshot
      Throws:
      UncheckedIOException - Any IO exception.
    • iostatisticsSnapshot_retrieve

      public static Serializable iostatisticsSnapshot_retrieve(@Nullable Object source)
      Extract the IOStatistics from an object in a serializable form.
      Parameters:
      source - source object, may be null/not a statistics source/instance
      Returns:
      IOStatisticsSnapshot or null if the object is null/doesn't have statistics
    • iostatisticsSnapshot_save

      public static void iostatisticsSnapshot_save(@Nullable Serializable snapshot, FileSystem fs, Path path, boolean overwrite)
      Save IOStatisticsSnapshot to a Hadoop filesystem as a JSON file.
      Parameters:
      snapshot - statistics
      fs - filesystem
      path - path
      overwrite - should any existing file be overwritten?
      Throws:
      UncheckedIOException - Any IO exception.
    • iostatisticsSnapshot_toJsonString

      public static String iostatisticsSnapshot_toJsonString(@Nullable Serializable snapshot)
      Save IOStatisticsSnapshot to a JSON string.
      Parameters:
      snapshot - statistics; may be null or of an incompatible type
      Returns:
      JSON string value
      Throws:
      UncheckedIOException - Any IO/jackson exception.
      IllegalArgumentException - if the supplied class is not a snapshot
    • iostatisticsSnapshot_fromJsonString

      public static Serializable iostatisticsSnapshot_fromJsonString(String json)
      Load IOStatisticsSnapshot from a JSON string.
      Parameters:
      json - JSON string value.
      Returns:
      deserialized snapshot.
      Throws:
      UncheckedIOException - Any IO/jackson exception.
    • iostatistics_counters

      public static Map<String,Long> iostatistics_counters(Serializable source)
      Get the counters of an IOStatisticsSnapshot.
      Parameters:
      source - source of statistics.
      Returns:
      the map of counters.
    • iostatistics_gauges

      public static Map<String,Long> iostatistics_gauges(Serializable source)
      Get the gauges of an IOStatisticsSnapshot.
      Parameters:
      source - source of statistics.
      Returns:
      the map of gauges.
    • iostatistics_minimums

      public static Map<String,Long> iostatistics_minimums(Serializable source)
      Get the minimums of an IOStatisticsSnapshot.
      Parameters:
      source - source of statistics.
      Returns:
      the map of minimums.
    • iostatistics_maximums

      public static Map<String,Long> iostatistics_maximums(Serializable source)
      Get the maximums of an IOStatisticsSnapshot.
      Parameters:
      source - source of statistics.
      Returns:
      the map of maximums.
    • iostatistics_means

      public static Map<String,Map.Entry<Long,Long>> iostatistics_means(Serializable source)
      Get the means of an IOStatisticsSnapshot. Each value in the map is the (sample, sum) tuple of the values; the mean is then calculated by dividing sum/sample wherever sample count is non-zero.
      Parameters:
      source - source of statistics.
      Returns:
      a map of mean key to (sample, sum) tuples.
    • iostatisticsContext_getCurrent

      public static Object iostatisticsContext_getCurrent()
      Get the context's IOStatisticsContext which implements IOStatisticsSource. This is either a thread-local value or a global empty context.
      Returns:
      instance of IOStatisticsContext.
    • iostatisticsContext_setThreadIOStatisticsContext

      public static void iostatisticsContext_setThreadIOStatisticsContext(@Nullable Object statisticsContext)
      Set the IOStatisticsContext for the current thread.
      Parameters:
      statisticsContext - IOStatistics context instance for the current thread. If null, the context is reset.
    • iostatisticsContext_enabled

      public static boolean iostatisticsContext_enabled()
      Static probe to check if the thread-level IO statistics enabled.
      Returns:
      true if the thread-level IO statistics are enabled.
    • iostatisticsContext_reset

      public static void iostatisticsContext_reset()
      Reset the context's IOStatistics. IOStatisticsContext.reset()
    • iostatisticsContext_snapshot

      public static Serializable iostatisticsContext_snapshot()
      Take a snapshot of the context IOStatistics. IOStatisticsContext.snapshot()
      Returns:
      an instance of IOStatisticsSnapshot.
    • iostatisticsContext_aggregate

      public static boolean iostatisticsContext_aggregate(Object source)
      Aggregate into the IOStatistics context the statistics passed in via IOStatistics/source parameter.

      Returns false if the source is null or does not contain any statistics.

      Parameters:
      source - implementation of IOStatisticsSource or IOStatistics
      Returns:
      true if the the source object was aggregated.
    • iostatistics_toPrettyString

      public static String iostatistics_toPrettyString(@Nullable Object statistics)
      Convert IOStatistics to a string form, with all the metrics sorted and empty value stripped.
      Parameters:
      statistics - A statistics instance; may be null
      Returns:
      string value or the empty string if null
    • applyToIOStatisticsSnapshot

      public static <T> T applyToIOStatisticsSnapshot(Serializable source, org.apache.hadoop.util.functional.FunctionRaisingIOE<IOStatisticsSnapshot,T> fun)
      Apply a function to an object which may be an IOStatisticsSnapshot.
      Type Parameters:
      T - return type
      Parameters:
      source - statistics snapshot
      fun - function to invoke if source is valid.
      Returns:
      the applied value
      Throws:
      UncheckedIOException - Any IO exception.
      IllegalArgumentException - if the supplied class is not a snapshot