Package org.apache.hadoop.io.wrappedio
Class WrappedStatistics
java.lang.Object
org.apache.hadoop.io.wrappedio.WrappedStatistics
Reflection-friendly access to IOStatistics APIs.
All
Serializable arguments/return values are actually
IOStatisticsSource instances; passing in the wrong value
will raise IllegalArgumentExceptions.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TapplyToIOStatisticsSnapshot(Serializable source, org.apache.hadoop.util.functional.FunctionRaisingIOE<IOStatisticsSnapshot, T> fun) Apply a function to an object which may be an IOStatisticsSnapshot.iostatistics_counters(Serializable source) Get the counters of an IOStatisticsSnapshot.iostatistics_gauges(Serializable source) Get the gauges of an IOStatisticsSnapshot.iostatistics_maximums(Serializable source) Get the maximums of an IOStatisticsSnapshot.iostatistics_means(Serializable source) Get the means of an IOStatisticsSnapshot.iostatistics_minimums(Serializable source) Get the minimums of an IOStatisticsSnapshot.static Stringiostatistics_toPrettyString(Object statistics) Convert IOStatistics to a string form, with all the metrics sorted and empty value stripped.static booleaniostatisticsContext_aggregate(Object source) Aggregate into the IOStatistics context the statistics passed in via IOStatistics/source parameter.static booleanStatic probe to check if the thread-level IO statistics enabled.static ObjectGet the context'sIOStatisticsContextwhich implementsIOStatisticsSource.static voidReset the context's IOStatistics.static voidiostatisticsContext_setThreadIOStatisticsContext(Object statisticsContext) Set the IOStatisticsContext for the current thread.static SerializableTake a snapshot of the context IOStatistics.static booleaniostatisticsSnapshot_aggregate(Serializable snapshot, Object statistics) Aggregate an existingIOStatisticsSnapshotwith the supplied statistics.static SerializableCreate a newIOStatisticsSnapshotinstance.static SerializableiostatisticsSnapshot_create(Object source) Create a newIOStatisticsSnapshotinstance.static SerializableLoad IOStatisticsSnapshot from a JSON string.static SerializableiostatisticsSnapshot_load(FileSystem fs, Path path) Load IOStatisticsSnapshot from a Hadoop filesystem.static SerializableiostatisticsSnapshot_retrieve(Object source) Extract the IOStatistics from an object in a serializable form.static voidiostatisticsSnapshot_save(Serializable snapshot, FileSystem fs, Path path, boolean overwrite) Save IOStatisticsSnapshot to a Hadoop filesystem as a JSON file.static StringSave IOStatisticsSnapshot to a JSON string.static booleanisIOStatistics(Object object) Probe for an object being an instance ofIOStatistics.static booleanisIOStatisticsSnapshot(Serializable object) Probe for an object being an instance ofIOStatisticsSnapshot.static booleanisIOStatisticsSource(Object object) Probe for an object being an instance ofIOStatisticsSource.
-
Method Details
-
isIOStatisticsSource
Probe for an object being an instance ofIOStatisticsSource.- Parameters:
object- object to probe- Returns:
- true if the object is the right type.
-
isIOStatistics
Probe for an object being an instance ofIOStatistics.- Parameters:
object- object to probe- Returns:
- true if the object is the right type.
-
isIOStatisticsSnapshot
Probe for an object being an instance ofIOStatisticsSnapshot.- 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 existingIOStatisticsSnapshotwith the supplied statistics.- Parameters:
snapshot- snapshot to updatestatistics- IOStatistics to add- Returns:
- true if the snapshot was updated.
- Throws:
IllegalArgumentException- if thestatisticsargument is not null but not an instance of IOStatistics, or ifsnapshotis invalid.
-
iostatisticsSnapshot_create
Create a newIOStatisticsSnapshotinstance.- Returns:
- an empty IOStatisticsSnapshot.
-
iostatisticsSnapshot_create
Create a newIOStatisticsSnapshotinstance.- Parameters:
source- optional source statistics- Returns:
- an IOStatisticsSnapshot.
- Throws:
ClassCastException- if thesourceis not null and not an IOStatistics instance
-
iostatisticsSnapshot_load
Load IOStatisticsSnapshot from a Hadoop filesystem.- Parameters:
fs- filesystempath- path- Returns:
- the loaded snapshot
- Throws:
UncheckedIOException- Any IO exception.
-
iostatisticsSnapshot_retrieve
Extract the IOStatistics from an object in a serializable form.- Parameters:
source- source object, may be null/not a statistics source/instance- Returns:
IOStatisticsSnapshotor 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- statisticsfs- filesystempath- pathoverwrite- should any existing file be overwritten?- Throws:
UncheckedIOException- Any IO exception.
-
iostatisticsSnapshot_toJsonString
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
Load IOStatisticsSnapshot from a JSON string.- Parameters:
json- JSON string value.- Returns:
- deserialized snapshot.
- Throws:
UncheckedIOException- Any IO/jackson exception.
-
iostatistics_counters
Get the counters of an IOStatisticsSnapshot.- Parameters:
source- source of statistics.- Returns:
- the map of counters.
-
iostatistics_gauges
Get the gauges of an IOStatisticsSnapshot.- Parameters:
source- source of statistics.- Returns:
- the map of gauges.
-
iostatistics_minimums
Get the minimums of an IOStatisticsSnapshot.- Parameters:
source- source of statistics.- Returns:
- the map of minimums.
-
iostatistics_maximums
Get the maximums of an IOStatisticsSnapshot.- Parameters:
source- source of statistics.- Returns:
- the map of maximums.
-
iostatistics_means
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
Get the context'sIOStatisticsContextwhich implementsIOStatisticsSource. 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
Take a snapshot of the context IOStatistics.IOStatisticsContext.snapshot()- Returns:
- an instance of
IOStatisticsSnapshot.
-
iostatisticsContext_aggregate
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 ofIOStatisticsSourceorIOStatistics- Returns:
- true if the the source object was aggregated.
-
iostatistics_toPrettyString
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 snapshotfun- function to invoke ifsourceis valid.- Returns:
- the applied value
- Throws:
UncheckedIOException- Any IO exception.IllegalArgumentException- if the supplied class is not a snapshot
-