-
Notifications
You must be signed in to change notification settings - Fork 117
feat: Add histogram metric type #386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
a8d83d0
d560f64
fd5c44b
edb0533
667858e
60f1e63
349daa6
c3d478a
484c2be
d4372af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ struct TRITONSERVER_Server; | |
| struct TRITONSERVER_ServerOptions; | ||
| struct TRITONSERVER_Metric; | ||
| struct TRITONSERVER_MetricFamily; | ||
| struct TRITONSERVER_MetricArgs; | ||
|
|
||
| /// | ||
| /// TRITONSERVER API Version | ||
|
|
@@ -91,7 +92,7 @@ struct TRITONSERVER_MetricFamily; | |
| /// } | ||
| /// | ||
| #define TRITONSERVER_API_VERSION_MAJOR 1 | ||
| #define TRITONSERVER_API_VERSION_MINOR 33 | ||
| #define TRITONSERVER_API_VERSION_MINOR 34 | ||
|
|
||
| /// Get the TRITONBACKEND API version supported by the Triton shared | ||
| /// library. This value can be compared against the | ||
|
|
@@ -2615,7 +2616,8 @@ TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_ServerInferAsync( | |
| /// | ||
| typedef enum TRITONSERVER_metrickind_enum { | ||
| TRITONSERVER_METRIC_KIND_COUNTER, | ||
| TRITONSERVER_METRIC_KIND_GAUGE | ||
| TRITONSERVER_METRIC_KIND_GAUGE, | ||
| TRITONSERVER_METRIC_KIND_HISTOGRAM | ||
| } TRITONSERVER_MetricKind; | ||
|
|
||
| /// Create a new metric family object. The caller takes ownership of the | ||
|
|
@@ -2644,6 +2646,42 @@ TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricFamilyNew( | |
| TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* | ||
| TRITONSERVER_MetricFamilyDelete(struct TRITONSERVER_MetricFamily* family); | ||
|
|
||
| /// Get the TRITONSERVER_MetricKind of the metric family. | ||
| /// | ||
| /// \param metric The metric family object to query. | ||
| /// \param kind Returns the TRITONSERVER_MetricKind of metric. | ||
| /// \return a TRITONSERVER_Error indicating success or failure. | ||
| TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* | ||
| TRITONSERVER_GetMetricFamilyKind( | ||
| struct TRITONSERVER_MetricFamily* family, TRITONSERVER_MetricKind* kind); | ||
|
|
||
| /// Create a new metric args object. The caller takes ownership of the | ||
| /// TRITONSERVER_MetricArgs object and must call TRITONSERVER_MetricArgsDelete | ||
| /// to release the object. | ||
| /// | ||
| /// \param args Returns the new metric args object. | ||
| /// \return a TRITONSERVER_Error indicating success or failure. | ||
| TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricArgsNew( | ||
| struct TRITONSERVER_MetricArgs** args); | ||
|
|
||
| /// Set metric args with prometheus histogram metric parameter. | ||
yinggeh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// \param args The metric args object to set. | ||
| /// \param buckets The array of bucket boundaries. | ||
| /// \param buckets_count The number of bucket boundaries. | ||
| /// \return a TRITONSERVER_Error indicating success or failure. | ||
| TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* | ||
| TRITONSERVER_MetricArgsSetHistogram( | ||
| struct TRITONSERVER_MetricArgs* args, const double* buckets, | ||
| const uint64_t buckets_count); | ||
|
|
||
| /// Delete a metric args object. | ||
| /// | ||
| /// \param args The metric args object. | ||
| /// \return a TRITONSERVER_Error indicating success or failure. | ||
| TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricArgsDelete( | ||
| struct TRITONSERVER_MetricArgs* args); | ||
|
|
||
| /// Create a new metric object. The caller takes ownership of the | ||
| /// TRITONSERVER_Metric object and must call | ||
| /// TRITONSERVER_MetricDelete to release the object. The caller is also | ||
|
|
@@ -2655,12 +2693,35 @@ TRITONSERVER_MetricFamilyDelete(struct TRITONSERVER_MetricFamily* family); | |
| /// \param family The metric family to add this new metric to. | ||
| /// \param labels The array of labels to associate with this new metric. | ||
| /// \param label_count The number of labels. | ||
| /// bucket boundaries. For histogram only. | ||
yinggeh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// \return a TRITONSERVER_Error indicating success or failure. | ||
| TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricNew( | ||
| struct TRITONSERVER_Metric** metric, | ||
| struct TRITONSERVER_MetricFamily* family, | ||
| const struct TRITONSERVER_Parameter** labels, const uint64_t label_count); | ||
|
|
||
| /// Create a new metric object. The caller takes ownership of the | ||
| /// TRITONSERVER_Metric object and must call | ||
| /// TRITONSERVER_MetricDelete to release the object. The caller is also | ||
| /// responsible for ownership of the labels passed in. | ||
| /// Each label can be deleted immediately after creating the metric with | ||
| /// TRITONSERVER_ParameterDelete if not re-using the labels. | ||
| /// Metric args can be deleted immediately after creating the metric with | ||
| /// TRITONSERVER_MetricArgsDelete if not re-using the metric args. | ||
| /// | ||
| /// \param metric Returns the new metric object. | ||
| /// \param family The metric family to add this new metric to. | ||
| /// \param labels The array of labels to associate with this new metric. | ||
| /// \param label_count The number of labels. | ||
| /// \param args Metric args that store additional arguments to construct | ||
| /// particular metric types, e.g. histogram. | ||
| /// \return a TRITONSERVER_Error indicating success or failure. | ||
| TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricNewWithArgs( | ||
| struct TRITONSERVER_Metric** metric, | ||
| struct TRITONSERVER_MetricFamily* family, | ||
| const struct TRITONSERVER_Parameter** labels, const uint64_t label_count, | ||
| const struct TRITONSERVER_MetricArgs* args); | ||
|
|
||
| /// Delete a metric object. | ||
| /// All TRITONSERVER_Metric* objects should be deleted BEFORE their | ||
| /// corresponding TRITONSERVER_MetricFamily* objects have been deleted. | ||
|
|
@@ -2672,9 +2733,10 @@ TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricDelete( | |
| struct TRITONSERVER_Metric* metric); | ||
|
|
||
| /// Get the current value of a metric object. | ||
| /// Supports metrics of kind TRITONSERVER_METRIC_KIND_COUNTER | ||
| /// and TRITONSERVER_METRIC_KIND_GAUGE, and returns | ||
| /// TRITONSERVER_ERROR_UNSUPPORTED for unsupported TRITONSERVER_MetricKind. | ||
| /// Supports metrics of kind TRITONSERVER_METRIC_KIND_COUNTER, | ||
| /// TRITONSERVER_METRIC_KIND_GAUGE, TRITONSERVER_METRIC_KIND_HISTOGRAM, and | ||
| /// returns TRITONSERVER_ERROR_UNSUPPORTED for unsupported | ||
| /// TRITONSERVER_MetricKind. | ||
| /// | ||
| /// \param metric The metric object to query. | ||
| /// \param value Returns the current value of the metric object. | ||
|
|
@@ -2695,8 +2757,9 @@ TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricValue( | |
| TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricIncrement( | ||
| struct TRITONSERVER_Metric* metric, double value); | ||
|
|
||
| /// Set the current value of metric to value. | ||
| /// Supports metrics of kind TRITONSERVER_METRIC_KIND_GAUGE and returns | ||
| /// Set the current value of metric to value or observe the value to metric. | ||
| /// Supports metrics of kind TRITONSERVER_METRIC_KIND_GAUGE and | ||
| /// TRITONSERVER_METRIC_KIND_HISTOGRAM. Returns | ||
|
||
| /// TRITONSERVER_ERROR_UNSUPPORTED for unsupported TRITONSERVER_MetricKind. | ||
| /// | ||
| /// \param metric The metric object to update. | ||
|
|
@@ -2705,7 +2768,7 @@ TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricIncrement( | |
| TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricSet( | ||
| struct TRITONSERVER_Metric* metric, double value); | ||
|
|
||
| /// Get the TRITONSERVER_MetricKind of metric and its corresponding family. | ||
| /// Get the TRITONSERVER_MetricKind of metric of its corresponding family. | ||
| /// | ||
| /// \param metric The metric object to query. | ||
| /// \param kind Returns the TRITONSERVER_MetricKind of metric. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||
| // Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||||||||
| // Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights | ||||||||
| // reserved. | ||||||||
| // | ||||||||
| // Redistribution and use in source and binary forms, with or without | ||||||||
| // modification, are permitted provided that the following conditions | ||||||||
|
|
@@ -27,6 +28,7 @@ | |||||||
|
|
||||||||
| #ifdef TRITON_ENABLE_METRICS | ||||||||
|
|
||||||||
| #include <cstring> | ||||||||
| #include <mutex> | ||||||||
| #include <set> | ||||||||
| #include <unordered_map> | ||||||||
|
|
@@ -37,6 +39,30 @@ | |||||||
|
|
||||||||
| namespace triton { namespace core { | ||||||||
|
|
||||||||
| // | ||||||||
| // TritonServerMetricArgs | ||||||||
| // | ||||||||
| // Implementation for TRITONSERVER_MetricArgs. | ||||||||
| // | ||||||||
| class TritonServerMetricArgs { | ||||||||
| public: | ||||||||
| TritonServerMetricArgs() = default; | ||||||||
|
|
||||||||
| 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_.resize(bucket_count); | |
| std::memcpy(buckets_.data(), buckets, sizeof(double) * bucket_count); | |
| buckets_ = std::vector<double>(buckets, buckets + bucket_count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
Uh oh!
There was an error while loading. Please reload this page.