Coverage Report

Created: 2026-03-15 08:11

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