Skip to content

Commit

Permalink
Minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
yinggeh committed Aug 16, 2024
1 parent c3d478a commit 484c2be
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/metric_family.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(buckets, buckets + bucket_count);
return nullptr;
}
TRITONSERVER_MetricKind kind() const { return kind_; }
Expand Down
32 changes: 30 additions & 2 deletions src/test/metrics_api_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint64_t>
GetCumulativeCounts(
const std::vector<double>& data, const std::vector<double>& buckets)
{
std::vector<std::uint64_t> 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,
Expand All @@ -247,8 +275,8 @@ HistogramAPIHelper(
TRITONSERVER_MetricObserve(metric, datum), "observe metric value");
sum += datum;
}
std::vector<std::uint64_t> cumulative_counts = {1, 1, 2, 2, 3, 3};
ASSERT_EQ(buckets.size() + 1, cumulative_counts.size());
std::vector<std::uint64_t> cumulative_counts =
GetCumulativeCounts(data, buckets);

// Collect formatted output
std::string metrics_str;
Expand Down

0 comments on commit 484c2be

Please sign in to comment.