Skip to content

Commit 484c2be

Browse files
committed
Minor update
1 parent c3d478a commit 484c2be

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/metric_family.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ class TritonServerMetricArgs {
5151
void* SetHistogramArgs(const double* buckets, uint64_t bucket_count)
5252
{
5353
kind_ = TRITONSERVER_METRIC_KIND_HISTOGRAM;
54-
buckets_.resize(bucket_count);
55-
std::memcpy(buckets_.data(), buckets, sizeof(double) * bucket_count);
54+
buckets_ = std::vector<double>(buckets, buckets + bucket_count);
5655
return nullptr;
5756
}
5857
TRITONSERVER_MetricKind kind() const { return kind_; }

src/test/metrics_api_test.cc

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,34 @@ MetricAPIHelper(TRITONSERVER_Metric* metric, TRITONSERVER_MetricKind kind)
233233
TRITONSERVER_ErrorDelete(err);
234234
}
235235

236+
// Calculate the cumulative_counts vector based on data and buckets.
237+
std::vector<std::uint64_t>
238+
GetCumulativeCounts(
239+
const std::vector<double>& data, const std::vector<double>& buckets)
240+
{
241+
std::vector<std::uint64_t> cumulative_counts(buckets.size() + 1, 0);
242+
for (double datum : data) {
243+
int i = 0;
244+
for (; i < buckets.size(); ++i) {
245+
if (datum <= buckets[i]) {
246+
cumulative_counts[i]++;
247+
break;
248+
}
249+
}
250+
if (i == buckets.size()) {
251+
cumulative_counts[i]++;
252+
}
253+
}
254+
255+
double cumulative_sum = 0.0;
256+
for (int i = 0; i < cumulative_counts.size(); ++i) {
257+
std::cout << cumulative_counts[i] << std::endl;
258+
cumulative_sum += cumulative_counts[i];
259+
cumulative_counts[i] = cumulative_sum;
260+
}
261+
return cumulative_counts;
262+
}
263+
236264
void
237265
HistogramAPIHelper(
238266
TRITONSERVER_Server* server, TRITONSERVER_Metric* metric,
@@ -247,8 +275,8 @@ HistogramAPIHelper(
247275
TRITONSERVER_MetricObserve(metric, datum), "observe metric value");
248276
sum += datum;
249277
}
250-
std::vector<std::uint64_t> cumulative_counts = {1, 1, 2, 2, 3, 3};
251-
ASSERT_EQ(buckets.size() + 1, cumulative_counts.size());
278+
std::vector<std::uint64_t> cumulative_counts =
279+
GetCumulativeCounts(data, buckets);
252280

253281
// Collect formatted output
254282
std::string metrics_str;

0 commit comments

Comments
 (0)