Coverage Report

Created: 2026-08-06 18:45

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