zhiqiang-hhhh commented on code in PR #49688: URL: https://github.com/apache/doris/pull/49688#discussion_r2051878437
########## be/src/util/runtime_profile.cpp: ########## @@ -473,6 +473,24 @@ void RuntimeProfile::add_description(const std::string& name, const std::string& child_counters->insert(name); } +RuntimeProfile::ConditionCounter* RuntimeProfile::add_conditition_counter( + const std::string& name, TUnit::type type, const ConditionCounterFunction& counter_fn, + const std::string& parent_counter_name) { + std::lock_guard<std::mutex> l(_counter_map_lock); + + if (_counter_map.find(name) != _counter_map.end()) { + DCHECK(dynamic_cast<ConditionCounter*>(_counter_map[name])); Review Comment: 把dcheck去掉,保存dynamic_cast的结果,检查是否为空指针,如果为空,那么就抛异常 ########## be/src/util/runtime_profile.cpp: ########## @@ -473,6 +473,24 @@ void RuntimeProfile::add_description(const std::string& name, const std::string& child_counters->insert(name); } +RuntimeProfile::ConditionCounter* RuntimeProfile::add_conditition_counter( + const std::string& name, TUnit::type type, const ConditionCounterFunction& counter_fn, + const std::string& parent_counter_name) { Review Comment: 没有counter_level参数 ########## be/src/util/runtime_profile.h: ########## @@ -278,6 +278,47 @@ class RuntimeProfile { DerivedCounterFunction _counter_fn; }; + using ConditionCounterFunction = std::function<bool(int64_t, int64_t)>; + + // ConditionCounter is a specialized counter that only updates its value when a specific condition is met. + // It uses a condition function (condition_func) to determine when the counter's value should be updated. + // This type of counter is particularly useful for tracking maximum values, minimum values, or other metrics + // that should only be updated when they meet certain criteria. + // For example, it can be used to record the maximum value of a specific metric during query execution, + // or to update the counter only when a new value exceeds some threshold. + class ConditionCounter : public Counter { + public: + ConditionCounter(TUnit::type type, const ConditionCounterFunction& condition_func, + int64_t condition = 0, int64_t value = 0, int64_t level = 2) + : Counter(type, value, level), + _condition(condition), + _value(value), + _condition_func(condition_func) {} + + virtual Counter* clone() const override { Review Comment: virtual 去掉,需要加锁 ########## be/src/util/runtime_profile.h: ########## @@ -278,6 +278,47 @@ class RuntimeProfile { DerivedCounterFunction _counter_fn; }; + using ConditionCounterFunction = std::function<bool(int64_t, int64_t)>; + + // ConditionCounter is a specialized counter that only updates its value when a specific condition is met. + // It uses a condition function (condition_func) to determine when the counter's value should be updated. + // This type of counter is particularly useful for tracking maximum values, minimum values, or other metrics + // that should only be updated when they meet certain criteria. + // For example, it can be used to record the maximum value of a specific metric during query execution, + // or to update the counter only when a new value exceeds some threshold. + class ConditionCounter : public Counter { + public: + ConditionCounter(TUnit::type type, const ConditionCounterFunction& condition_func, + int64_t condition = 0, int64_t value = 0, int64_t level = 2) + : Counter(type, value, level), + _condition(condition), + _value(value), + _condition_func(condition_func) {} + + virtual Counter* clone() const override { + return new ConditionCounter(type(), _condition_func, _condition, value(), level()); + } + + virtual int64_t value() const override { Review Comment: virtual 去掉 -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org