Coverage Report

Created: 2026-04-14 17:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/runtime/memory/memory_profile.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/multi_version.h"
21
#include "runtime/runtime_profile.h"
22
23
namespace doris {
24
25
class MemoryProfile {
26
public:
27
    MemoryProfile();
28
29
    void refresh_memory_overview_profile();
30
    void refresh_tasks_memory_profile();
31
32
    void make_memory_profile(RuntimeProfile* profile) const;
33
34
4
    std::string print_memory_overview_profile() const {
35
4
        return _memory_overview_profile->pretty_print();
36
4
    }
37
38
4
    std::string print_global_memory_profile() const {
39
4
        return _global_memory_profile.get()->pretty_print();
40
4
    }
41
42
4
    std::string print_metadata_memory_profile() const {
43
4
        return _metadata_memory_profile.get()->pretty_print();
44
4
    }
45
46
4
    std::string print_cache_memory_profile() const {
47
4
        return _cache_memory_profile.get()->pretty_print();
48
4
    }
49
50
4
    std::string print_top_memory_tasks_profile() const {
51
4
        return _top_memory_tasks_profile.get()->pretty_print();
52
4
    }
53
54
0
    std::string print_tasks_memory_profile() const {
55
0
        return _tasks_memory_profile.get()->pretty_print();
56
0
    }
57
58
    static int64_t query_current_usage();
59
    static int64_t load_current_usage();
60
    static int64_t compaction_current_usage();
61
    static int64_t schema_change_current_usage();
62
    static int64_t other_current_usage();
63
64
    // process memory changes more than 256M, or the GC ends
65
0
    void enable_print_log_process_usage() { _enable_print_log_process_usage = true; }
66
    void print_log_process_usage();
67
    std::string process_memory_detail_str() const;
68
69
private:
70
    void init_memory_overview_counter();
71
72
    std::unique_ptr<RuntimeProfile> _memory_overview_profile;
73
    MultiVersion<RuntimeProfile> _global_memory_profile;
74
    MultiVersion<RuntimeProfile> _metadata_memory_profile;
75
    MultiVersion<RuntimeProfile> _cache_memory_profile;
76
    MultiVersion<RuntimeProfile> _top_memory_tasks_profile;
77
    MultiVersion<RuntimeProfile> _tasks_memory_profile;
78
79
    // process memory counter
80
    RuntimeProfile::HighWaterMarkCounter* _process_physical_memory_usage_counter;
81
    RuntimeProfile::HighWaterMarkCounter* _process_virtual_memory_usage_counter;
82
83
    // untracked/tracked memory counter
84
    RuntimeProfile::HighWaterMarkCounter* _untracked_memory_usage_counter;
85
    RuntimeProfile::HighWaterMarkCounter* _tracked_memory_usage_counter;
86
87
    // Jemalloc memory counter
88
    RuntimeProfile::HighWaterMarkCounter* _jemalloc_memory_usage_counter;
89
    RuntimeProfile::HighWaterMarkCounter* _jemalloc_cache_usage_counter;
90
    RuntimeProfile::HighWaterMarkCounter* _jemalloc_metadata_usage_counter;
91
92
    // JVM memory counter
93
    RuntimeProfile::HighWaterMarkCounter* _jvm_heap_memory_usage_counter;
94
    RuntimeProfile::HighWaterMarkCounter* _jvm_non_heap_memory_usage_counter;
95
96
    // global/metadata/cache memory counter
97
    RuntimeProfile::HighWaterMarkCounter* _global_usage_counter;
98
    RuntimeProfile::HighWaterMarkCounter* _metadata_usage_counter;
99
    RuntimeProfile::HighWaterMarkCounter* _cache_usage_counter;
100
101
    // tasks memory counter
102
    RuntimeProfile::HighWaterMarkCounter* _tasks_memory_usage_counter;
103
104
    // Memtable memory counter
105
    RuntimeProfile::HighWaterMarkCounter* _memtable_memory_usage_counter;
106
107
    // reserved memory is the sum of all task reserved memory, is duplicated with all task memory counter.
108
    RuntimeProfile::HighWaterMarkCounter* _reserved_memory_usage_counter;
109
    RuntimeProfile::HighWaterMarkCounter* _query_usage_counter;
110
    RuntimeProfile::HighWaterMarkCounter* _load_usage_counter;
111
    RuntimeProfile::HighWaterMarkCounter* _compaction_usage_counter;
112
    RuntimeProfile::HighWaterMarkCounter* _schema_change_usage_counter;
113
    RuntimeProfile::HighWaterMarkCounter* _other_usage_counter;
114
115
    std::atomic<bool> _enable_print_log_process_usage {true};
116
};
117
118
} // namespace doris