be/src/runtime/runtime_profile_counter_tree_node.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | #include <gen_cpp/RuntimeProfile_types.h> |
20 | | |
21 | | #include <string> |
22 | | |
23 | | #include "runtime/runtime_profile.h" |
24 | | |
25 | | namespace doris { |
26 | | |
27 | | class RuntimeProfileCounterTreeNode { |
28 | | public: |
29 | | using CounterMap = std::map<std::string, RuntimeProfile::Counter*>; |
30 | | using ChildCounterMap = std::map<std::string, std::set<std::string>>; |
31 | | |
32 | 46.1k | RuntimeProfileCounterTreeNode() = default; |
33 | 342k | ~RuntimeProfileCounterTreeNode() { |
34 | | // counter is not owned by this class |
35 | 342k | counter = nullptr; |
36 | 342k | }; |
37 | | |
38 | | // Create a tree node from a counter map and a child counter map. |
39 | | static RuntimeProfileCounterTreeNode from_map(const CounterMap& counterMap, |
40 | | const ChildCounterMap& childCounterMap, |
41 | | const std::string& rootName); |
42 | | |
43 | | // Prune the tree by: |
44 | | // 1. Remove all leaf nodes whose level is greater than the given level. |
45 | | // 2. Remove all nodes whose children are all pruned. |
46 | | static RuntimeProfileCounterTreeNode prune_the_tree(RuntimeProfileCounterTreeNode node, |
47 | | int64_t level); |
48 | | |
49 | | // Convert the counter tree to a list of TCounter objects and a map of tree topology. |
50 | | void to_thrift(std::vector<TCounter>& tcounter, |
51 | | std::map<std::string, std::set<std::string>>& child_counter_map) const; |
52 | | |
53 | | void to_proto( |
54 | | google::protobuf::RepeatedPtrField<PProfileCounter>* proto_counters, |
55 | | google::protobuf::Map<std::string, PProfileChildCounterSet>* child_counter_map) const; |
56 | | |
57 | | // Conver this node to a TCounter object. |
58 | | TCounter to_thrift() const; |
59 | | |
60 | | PProfileCounter to_proto() const; |
61 | | |
62 | | private: |
63 | | std::string name; |
64 | | // counter is not owned by this class |
65 | | RuntimeProfile::Counter* counter = nullptr; |
66 | | |
67 | | std::vector<RuntimeProfileCounterTreeNode> children; |
68 | | }; |
69 | | |
70 | | } // namespace doris |