gavinchou commented on code in PR #55544:
URL: https://github.com/apache/doris/pull/55544#discussion_r2328990400


##########
cloud/src/common/bvars.h:
##########
@@ -179,6 +182,83 @@ class mBvarWrapper {
     bvar::MultiDimension<BvarType> counter_;
 };
 
+template <int N = 60>
+class BvarLatencyRecorderWithStatus {

Review Comment:
   add comment  what is N



##########
cloud/src/common/bvars.h:
##########
@@ -179,6 +182,83 @@ class mBvarWrapper {
     bvar::MultiDimension<BvarType> counter_;
 };
 
+template <int N = 60>
+class BvarLatencyRecorderWithStatus {

Review Comment:
   also add comment to show the usage of this recorder 
   better with an example



##########
cloud/src/common/bvars.h:
##########
@@ -179,6 +182,83 @@ class mBvarWrapper {
     bvar::MultiDimension<BvarType> counter_;
 };
 
+template <int N = 60>
+class BvarLatencyRecorderWithStatus {
+private:
+    bvar::LatencyRecorder recorder_;
+    bvar::PassiveStatus<int64_t> max_status_;
+    bvar::PassiveStatus<int64_t> avg_status_;
+
+    static int64_t get_max_latency(void* arg) {
+        auto* self = static_cast<BvarLatencyRecorderWithStatus*>(arg);
+        int64_t value = self->recorder_.max_latency();
+        return value >= 0 ? value : 0;
+    }
+
+    static int64_t get_avg_latency(void* arg) {
+        auto* self = static_cast<BvarLatencyRecorderWithStatus*>(arg);
+        int64_t value = self->recorder_.latency();
+        return value >= 0 ? value : 0;
+    }
+
+public:
+    BvarLatencyRecorderWithStatus(const std::string& prefix, const 
std::string& metric_name)
+            : recorder_(N),
+              max_status_(metric_name + "_max", get_max_latency, this),
+              avg_status_(metric_name + "_avg", get_avg_latency, this) {
+        recorder_.hide();
+    }
+
+    BvarLatencyRecorderWithStatus(const std::string& metric_name)
+            : recorder_(N),
+              max_status_(metric_name + "_max", get_max_latency, this),
+              avg_status_(metric_name + "_avg", get_avg_latency, this) {
+        recorder_.hide();
+    }
+
+    void put(int64_t value) { recorder_ << value; }
+
+    void operator<<(int64_t value) { recorder_ << value; }
+};
+
+class mBvarLatencyRecorderWithStatus {
+private:
+    std::string _metric_name;
+    // window size is config::bvar_dump_interval
+    // The bvar::MultiDimension<bvar::LatencyRecorder>'s window size can only 
be set by the global config
+    bvar::MultiDimension<bvar::LatencyRecorder> recorder_;
+    bvar::MultiDimension<bvar::Status<int64_t>> max_status_;
+    bvar::MultiDimension<bvar::Status<int64_t>> avg_status_;
+
+public:
+    mBvarLatencyRecorderWithStatus(const std::string& metric_name,
+                                   const std::initializer_list<std::string>& 
dim_names)
+            : _metric_name(metric_name),
+              recorder_(metric_name, std::list<std::string>(dim_names)),
+              max_status_(metric_name + "_max", 
std::list<std::string>(dim_names)),
+              avg_status_(metric_name + "_avg", 
std::list<std::string>(dim_names)) {

Review Comment:
   also expose _count



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to