be/src/runtime/workload_management/cpu_context.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 | | |
20 | | #include "common/factory_creator.h" |
21 | | #include "runtime/runtime_profile.h" |
22 | | #include "runtime/workload_group/workload_group.h" |
23 | | |
24 | | namespace doris { |
25 | | |
26 | | class ResourceContext; |
27 | | |
28 | | class CPUContext : public std::enable_shared_from_this<CPUContext> { |
29 | | ENABLE_FACTORY_CREATOR(CPUContext); |
30 | | |
31 | | public: |
32 | | /* |
33 | | * 1. operate them thread-safe. |
34 | | * 2. all tasks are unified. |
35 | | * 3. should not be operated frequently, use local variables to update Counter. |
36 | | */ |
37 | | struct Stats { |
38 | | RuntimeProfile::Counter* cpu_cost_ms_counter_; |
39 | | |
40 | 0 | RuntimeProfile* profile() { return profile_.get(); } |
41 | 122k | void init_profile() { |
42 | 122k | profile_ = std::make_unique<RuntimeProfile>("MemoryContext"); |
43 | 122k | cpu_cost_ms_counter_ = ADD_COUNTER(profile_, "RevokeWaitTimeMs", TUnit::TIME_MS); |
44 | 122k | } |
45 | 0 | std::string debug_string() { return profile_->pretty_print(); } |
46 | | |
47 | | private: |
48 | | std::unique_ptr<RuntimeProfile> profile_; |
49 | | }; |
50 | | |
51 | 122k | CPUContext() { stats_.init_profile(); } |
52 | 122k | virtual ~CPUContext() = default; |
53 | | |
54 | 0 | RuntimeProfile* stats_profile() { return stats_.profile(); } |
55 | | |
56 | 0 | int64_t cpu_cost_ms() const { return stats_.cpu_cost_ms_counter_->value(); } |
57 | | |
58 | | void update_cpu_cost_ms(int64_t delta) const; |
59 | | |
60 | | // Bind current thread to cgroup, only some load thread should do this. |
61 | 0 | void bind_workload_group() { |
62 | 0 | // TODO: Call workload group method to bind current thread to cgroup |
63 | 0 | } |
64 | | |
65 | | protected: |
66 | | friend class ResourceContext; |
67 | | |
68 | 122k | void set_resource_ctx(ResourceContext* resource_ctx) { resource_ctx_ = resource_ctx; } |
69 | | |
70 | | Stats stats_; |
71 | | ResourceContext* resource_ctx_ {nullptr}; |
72 | | }; |
73 | | |
74 | | } // namespace doris |