This is an automated email from the ASF dual-hosted git repository. panxiaolei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 3c078ad3736 [feature](profile) add non-zero counter in profile(#33342) 3c078ad3736 is described below commit 3c078ad3736bdfb743438cb78ec28269c299f0b2 Author: Mryange <59914473+mrya...@users.noreply.github.com> AuthorDate: Fri Apr 12 14:39:05 2024 +0800 [feature](profile) add non-zero counter in profile(#33342) add non-zero counter in profile --- be/src/pipeline/exec/exchange_sink_operator.cpp | 6 ++-- be/src/pipeline/exec/exchange_source_operator.cpp | 4 +-- be/src/util/runtime_profile.cpp | 29 +++++++++++++------ be/src/util/runtime_profile.h | 34 +++++++++++++++++++++++ 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/be/src/pipeline/exec/exchange_sink_operator.cpp b/be/src/pipeline/exec/exchange_sink_operator.cpp index 8323e20cfd1..ca50f7bd053 100644 --- a/be/src/pipeline/exec/exchange_sink_operator.cpp +++ b/be/src/pipeline/exec/exchange_sink_operator.cpp @@ -197,9 +197,9 @@ Status ExchangeSinkLocalState::init(RuntimeState* state, LocalSinkStateInfo& inf if (channel->is_local()) { _local_channels_dependency[dep_id] = channel->get_local_channel_dependency(); DCHECK(_local_channels_dependency[dep_id] != nullptr); - _wait_channel_timer[dep_id] = ADD_CHILD_TIMER_WITH_LEVEL( - _profile, fmt::format("WaitForLocalExchangeBuffer{}", dep_id), timer_name, - 1); + _wait_channel_timer[dep_id] = _profile->add_nonzero_counter( + fmt::format("WaitForLocalExchangeBuffer{}", dep_id), TUnit ::TIME_NS, + timer_name, 1); dep_id++; } } diff --git a/be/src/pipeline/exec/exchange_source_operator.cpp b/be/src/pipeline/exec/exchange_source_operator.cpp index 664e576e1ce..fd44b23995d 100644 --- a/be/src/pipeline/exec/exchange_source_operator.cpp +++ b/be/src/pipeline/exec/exchange_source_operator.cpp @@ -85,8 +85,8 @@ Status ExchangeLocalState::init(RuntimeState* state, LocalStateInfo& info) { static const std::string timer_name = "WaitForDependencyTime"; _wait_for_dependency_timer = ADD_TIMER_WITH_LEVEL(_runtime_profile, timer_name, 1); for (size_t i = 0; i < queues.size(); i++) { - metrics[i] = ADD_CHILD_TIMER_WITH_LEVEL(_runtime_profile, fmt::format("WaitForData{}", i), - timer_name, 1); + metrics[i] = _runtime_profile->add_nonzero_counter(fmt::format("WaitForData{}", i), + TUnit ::TIME_NS, timer_name, 1); } RETURN_IF_ERROR(_parent->cast<ExchangeSourceOperatorX>()._vsort_exec_exprs.clone( state, vsort_exec_exprs)); diff --git a/be/src/util/runtime_profile.cpp b/be/src/util/runtime_profile.cpp index 647c6e966c5..782009d4438 100644 --- a/be/src/util/runtime_profile.cpp +++ b/be/src/util/runtime_profile.cpp @@ -429,6 +429,25 @@ RuntimeProfile::Counter* RuntimeProfile::add_counter(const std::string& name, TU return counter; } +RuntimeProfile::NonZeroCounter* RuntimeProfile::add_nonzero_counter( + const std::string& name, TUnit::type type, const std::string& parent_counter_name, + int64_t level) { + std::lock_guard<std::mutex> l(_counter_map_lock); + if (_counter_map.find(name) != _counter_map.end()) { + DCHECK(dynamic_cast<NonZeroCounter*>(_counter_map[name])); + return static_cast<NonZeroCounter*>(_counter_map[name]); + } + + DCHECK(parent_counter_name == ROOT_COUNTER || + _counter_map.find(parent_counter_name) != _counter_map.end()); + NonZeroCounter* counter = _pool->add(new NonZeroCounter(type, level, parent_counter_name)); + _counter_map[name] = counter; + std::set<std::string>* child_counters = + find_or_insert(&_child_counter_map, parent_counter_name, std::set<std::string>()); + child_counters->insert(name); + return counter; +} + RuntimeProfile::DerivedCounter* RuntimeProfile::add_derived_counter( const std::string& name, TUnit::type type, const DerivedCounterFunction& counter_fn, const std::string& parent_counter_name) { @@ -576,14 +595,8 @@ void RuntimeProfile::to_thrift(std::vector<TRuntimeProfileNode>* nodes) { node.child_counters_map = _child_counter_map; } - for (std::map<std::string, Counter*>::const_iterator iter = counter_map.begin(); - iter != counter_map.end(); ++iter) { - TCounter counter; - counter.name = iter->first; - counter.value = iter->second->value(); - counter.type = iter->second->type(); - counter.__set_level(iter->second->level()); - node.counters.push_back(counter); + for (auto&& [name, counter] : counter_map) { + counter->to_thrift(name, node.counters, node.child_counters_map); } { diff --git a/be/src/util/runtime_profile.h b/be/src/util/runtime_profile.h index 4cc2c2617ec..c1756f6c63e 100644 --- a/be/src/util/runtime_profile.h +++ b/be/src/util/runtime_profile.h @@ -116,6 +116,16 @@ public: return binary_cast<int64_t, double>(_value.load(std::memory_order_relaxed)); } + virtual void to_thrift(const std::string& name, std::vector<TCounter>& tcounters, + std::map<std::string, std::set<std::string>>& child_counters_map) { + TCounter counter; + counter.name = name; + counter.value = this->value(); + counter.type = this->type(); + counter.__set_level(this->level()); + tcounters.push_back(counter); + } + TUnit::type type() const { return _type; } virtual int64_t level() { return _level; } @@ -201,6 +211,26 @@ public: DerivedCounterFunction _counter_fn; }; + // NonZeroCounter will not be converted to Thrift if the value is 0. + class NonZeroCounter : public Counter { + public: + NonZeroCounter(TUnit::type type, int64_t level, const std::string& parent_name) + : Counter(type, 0, level), _parent_name(parent_name) {} + + void to_thrift(const std::string& name, std::vector<TCounter>& tcounters, + std::map<std::string, std::set<std::string>>& child_counters_map) override { + if (this->_value > 0) { + Counter::to_thrift(name, tcounters, child_counters_map); + } else { + // remove it + child_counters_map[_parent_name].erase(name); + } + } + + private: + const std::string _parent_name; + }; + // An EventSequence captures a sequence of events (each added by // calling MarkEvent). Each event has a text label, and a time // (measured relative to the moment start() was called as t=0). It is @@ -299,6 +329,10 @@ public: return add_counter(name, type, "", level); } + NonZeroCounter* add_nonzero_counter(const std::string& name, TUnit::type type, + const std::string& parent_counter_name = "", + int64_t level = 2); + // Add a derived counter with 'name'/'type'. The counter is owned by the // RuntimeProfile object. // If parent_counter_name is a non-empty string, the counter is added as a child of --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org