Skip to content

Commit

Permalink
[api] Adds suffix to percentile metric name
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu committed Feb 29, 2024
1 parent ab00bed commit 79e2ab8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions api/src/main/java/ai/djl/metric/Metric.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
*
Expand Down
3 changes: 2 additions & 1 deletion api/src/main/java/ai/djl/metric/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ public Metric percentile(String metricName, int percentile) {
List<Metric> 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);
}

/**
Expand Down
1 change: 1 addition & 0 deletions api/src/main/java/ai/djl/metric/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Unit> MAP = new ConcurrentHashMap<>();
Expand Down

0 comments on commit 79e2ab8

Please sign in to comment.