public class Metrics
extends java.lang.Object
Metric
objects organized by metric name.
Metric
is a utility class that is used in the Trainer
and
Predictor
to capture performance and other metrics during runtime.
It is built as a collection of individual Metric
classes. As a container for
individual metrics classes, Metrics
stores them as time series data so that
metric-vs-timeline analysis can be performed. It also provides convenient statistical methods for
getting aggregated information, such as mean and percentile. The metrics is used to store key
performance indicators (KPIs) during inference and training runs. These KPIs include various
latencies, CPU and GPU memory consumption, losses, etc.
For more details about using the metrics, see the metrics tutorial.
Constructor and Description |
---|
Metrics()
Constructs an empty
Metrics instance. |
Modifier and Type | Method and Description |
---|---|
void |
addMetric(Metric metric)
Adds a
Metric to the collection. |
void |
addMetric(java.lang.String name,
java.lang.Number value)
Adds a
Metric given the metric's name and value . |
void |
addMetric(java.lang.String name,
java.lang.Number value,
java.lang.String unit)
Adds a
Metric given the metric's name , value , and unit . |
java.util.List<Metric> |
getMetric(java.lang.String name)
Returns all
Metric s with the specified metric name. |
boolean |
hasMetric(java.lang.String name)
Returns
true if the metrics object has a metric with the given name. |
Metric |
latestMetric(java.lang.String name)
Returns the latest
Metric with the specified metric name. |
double |
mean(java.lang.String metricName)
Returns the average value of the specified metric.
|
Metric |
percentile(java.lang.String metricName,
int percentile)
Returns a percentile
Metric object for the specified metric name. |
public void addMetric(Metric metric)
Metric
to the collection.metric
- the Metric
to be addedpublic void addMetric(java.lang.String name, java.lang.Number value)
Metric
given the metric's name
and value
.name
- the metric namevalue
- the metric valuepublic void addMetric(java.lang.String name, java.lang.Number value, java.lang.String unit)
Metric
given the metric's name
, value
, and unit
.name
- the metric namevalue
- the metric valueunit
- the metric unitpublic boolean hasMetric(java.lang.String name)
true
if the metrics object has a metric with the given name.name
- the name to check fortrue
if the metrics object has a metric with the given namepublic java.util.List<Metric> getMetric(java.lang.String name)
Metric
s with the specified metric name.name
- the name of the metricMetric
with the specified metric namepublic Metric latestMetric(java.lang.String name)
Metric
with the specified metric name.name
- the name of the metricMetric
with the specified metric namejava.lang.IllegalArgumentException
- if the given name is not foundpublic Metric percentile(java.lang.String metricName, int percentile)
Metric
object for the specified metric name.metricName
- the name of the metricpercentile
- the percentileMetric
object at specified percentile
public double mean(java.lang.String metricName)
metricName
- the name of the metric