Coverage Report

Created: 2026-03-16 05:02

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