From 484c2be1ce6c4be01eeb25b8040b69a38c28b58c Mon Sep 17 00:00:00 2001 From: Yingge He Date: Fri, 16 Aug 2024 12:31:35 -0700 Subject: [PATCH] Minor update --- src/metric_family.h | 3 +-- src/test/metrics_api_test.cc | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/metric_family.h b/src/metric_family.h index 3953d6f53..2ea13eeda 100644 --- a/src/metric_family.h +++ b/src/metric_family.h @@ -51,8 +51,7 @@ class TritonServerMetricArgs { void* SetHistogramArgs(const double* buckets, uint64_t bucket_count) { kind_ = TRITONSERVER_METRIC_KIND_HISTOGRAM; - buckets_.resize(bucket_count); - std::memcpy(buckets_.data(), buckets, sizeof(double) * bucket_count); + buckets_ = std::vector(buckets, buckets + bucket_count); return nullptr; } TRITONSERVER_MetricKind kind() const { return kind_; } diff --git a/src/test/metrics_api_test.cc b/src/test/metrics_api_test.cc index 41e4ac274..e1261616f 100644 --- a/src/test/metrics_api_test.cc +++ b/src/test/metrics_api_test.cc @@ -233,6 +233,34 @@ MetricAPIHelper(TRITONSERVER_Metric* metric, TRITONSERVER_MetricKind kind) TRITONSERVER_ErrorDelete(err); } +// Calculate the cumulative_counts vector based on data and buckets. +std::vector +GetCumulativeCounts( + const std::vector& data, const std::vector& buckets) +{ + std::vector cumulative_counts(buckets.size() + 1, 0); + for (double datum : data) { + int i = 0; + for (; i < buckets.size(); ++i) { + if (datum <= buckets[i]) { + cumulative_counts[i]++; + break; + } + } + if (i == buckets.size()) { + cumulative_counts[i]++; + } + } + + double cumulative_sum = 0.0; + for (int i = 0; i < cumulative_counts.size(); ++i) { + std::cout << cumulative_counts[i] << std::endl; + cumulative_sum += cumulative_counts[i]; + cumulative_counts[i] = cumulative_sum; + } + return cumulative_counts; +} + void HistogramAPIHelper( TRITONSERVER_Server* server, TRITONSERVER_Metric* metric, @@ -247,8 +275,8 @@ HistogramAPIHelper( TRITONSERVER_MetricObserve(metric, datum), "observe metric value"); sum += datum; } - std::vector cumulative_counts = {1, 1, 2, 2, 3, 3}; - ASSERT_EQ(buckets.size() + 1, cumulative_counts.size()); + std::vector cumulative_counts = + GetCumulativeCounts(data, buckets); // Collect formatted output std::string metrics_str;