From 49c255e350f01cfc6ff2774ec60623078a9775dc Mon Sep 17 00:00:00 2001 From: Frank Liu Date: Thu, 29 Feb 2024 11:46:12 -0800 Subject: [PATCH] [api] Adds suffix to percentile metric name --- api/src/main/java/ai/djl/metric/Metric.java | 10 ++++++++++ api/src/main/java/ai/djl/metric/Metrics.java | 3 ++- api/src/main/java/ai/djl/metric/Unit.java | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/ai/djl/metric/Metric.java b/api/src/main/java/ai/djl/metric/Metric.java index b3c172ce8b35..4743421a1f6c 100644 --- a/api/src/main/java/ai/djl/metric/Metric.java +++ b/api/src/main/java/ai/djl/metric/Metric.java @@ -105,6 +105,16 @@ private Metric( this.dimensions = dimensions; } + /** + * Returns a copy of the metric with a new name. + * + * @param name the new metric name + * @return a copy of the metric + */ + public Metric copyOf(String name) { + return new Metric(name, value, unit, timestamp, dimensions); + } + /** * Returns the name of the {@code Metric}. * diff --git a/api/src/main/java/ai/djl/metric/Metrics.java b/api/src/main/java/ai/djl/metric/Metrics.java index bdbd0d3e7325..ae3c7bef7b47 100644 --- a/api/src/main/java/ai/djl/metric/Metrics.java +++ b/api/src/main/java/ai/djl/metric/Metrics.java @@ -172,7 +172,8 @@ public Metric percentile(String metricName, int percentile) { List list = new ArrayList<>(metric); list.sort(Comparator.comparingDouble(Metric::getValue)); int index = metric.size() * percentile / 100; - return list.get(index); + Metric m = list.get(index); + return m.copyOf(m.getMetricName() + ".p" + percentile); } /** diff --git a/api/src/main/java/ai/djl/metric/Unit.java b/api/src/main/java/ai/djl/metric/Unit.java index 81d45e631854..3703d2a312e5 100644 --- a/api/src/main/java/ai/djl/metric/Unit.java +++ b/api/src/main/java/ai/djl/metric/Unit.java @@ -41,6 +41,7 @@ public enum Unit { GIGABITS_PER_SECOND("Gigabits/Second"), TERABITS_PER_SECOND("Terabits/Second"), COUNT_PER_SECOND("Count/Second"), + COUNT_PER_ITEM("Count/Item"), NONE("None"); private static final ConcurrentHashMap MAP = new ConcurrentHashMap<>();