/root/doris/be/src/util/jvm_metrics.h
Line | Count | Source (jump to first uncovered line) |
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 "jni.h" |
21 | | #include "util/jni-util.h" |
22 | | #include "util/metrics.h" |
23 | | |
24 | | namespace doris { |
25 | | |
26 | | class JvmMetrics; |
27 | | |
28 | | class JvmStats { |
29 | | private: |
30 | | jclass _managementFactoryClass = nullptr; |
31 | | jmethodID _getMemoryMXBeanMethod = nullptr; |
32 | | jclass _memoryUsageClass = nullptr; |
33 | | jclass _memoryMXBeanClass = nullptr; |
34 | | jmethodID _getHeapMemoryUsageMethod = nullptr; |
35 | | jmethodID _getNonHeapMemoryUsageMethod = nullptr; |
36 | | jmethodID _getMemoryUsageUsedMethod = nullptr; |
37 | | jmethodID _getMemoryUsageCommittedMethod = nullptr; |
38 | | jmethodID _getMemoryUsageMaxMethod = nullptr; |
39 | | |
40 | | jmethodID _getMemoryPoolMXBeansMethod = nullptr; |
41 | | |
42 | | jclass _listClass = nullptr; |
43 | | jmethodID _getListSizeMethod = nullptr; |
44 | | jmethodID _getListUseIndexMethod = nullptr; |
45 | | |
46 | | jclass _memoryPoolMXBeanClass = nullptr; |
47 | | jmethodID _getMemoryPoolMXBeanUsageMethod = nullptr; |
48 | | |
49 | | jmethodID _getMemoryPollMXBeanPeakMethod = nullptr; |
50 | | jmethodID _getMemoryPollMXBeanNameMethod = nullptr; |
51 | | |
52 | | enum memoryPoolNameEnum { YOUNG, SURVIVOR, OLD }; |
53 | | const std::map<std::string, memoryPoolNameEnum> _memoryPoolName = { |
54 | | {"Eden Space", YOUNG}, |
55 | | {"PS Eden Space", YOUNG}, |
56 | | {"Par Eden Space", YOUNG}, |
57 | | {"G1 Eden Space", YOUNG}, |
58 | | |
59 | | {"Survivor Space", SURVIVOR}, |
60 | | {"PS Survivor Space", SURVIVOR}, |
61 | | {"Par Survivor Space", SURVIVOR}, |
62 | | {"G1 Survivor Space", SURVIVOR}, |
63 | | |
64 | | {"Tenured Gen", OLD}, |
65 | | {"PS Old Gen", OLD}, |
66 | | {"CMS Old Gen", OLD}, |
67 | | {"G1 Old Gen", OLD}, |
68 | | |
69 | | }; |
70 | | |
71 | | jmethodID _getThreadMXBeanMethod = nullptr; |
72 | | jclass _threadMXBeanClass = nullptr; |
73 | | jmethodID _getAllThreadIdsMethod = nullptr; |
74 | | jmethodID _getThreadInfoMethod = nullptr; |
75 | | jclass _threadInfoClass = nullptr; |
76 | | |
77 | | jmethodID _getPeakThreadCountMethod = nullptr; |
78 | | |
79 | | jmethodID _getThreadStateMethod = nullptr; |
80 | | jclass _threadStateClass = nullptr; |
81 | | |
82 | | jobject _newThreadStateObj = nullptr; |
83 | | jobject _runnableThreadStateObj = nullptr; |
84 | | jobject _blockedThreadStateObj = nullptr; |
85 | | jobject _waitingThreadStateObj = nullptr; |
86 | | jobject _timedWaitingThreadStateObj = nullptr; |
87 | | jobject _terminatedThreadStateObj = nullptr; |
88 | | |
89 | | jclass _garbageCollectorMXBeanClass = nullptr; |
90 | | jmethodID _getGCNameMethod = nullptr; |
91 | | jmethodID _getGarbageCollectorMXBeansMethod = nullptr; |
92 | | jmethodID _getGCCollectionCountMethod = nullptr; |
93 | | jmethodID _getGCCollectionTimeMethod = nullptr; |
94 | | |
95 | | bool _init_complete = false; |
96 | | |
97 | | public: |
98 | | Status init(JNIEnv* env); |
99 | 0 | bool init_complete() const { return _init_complete; } |
100 | 0 | void set_complete(bool val) { _init_complete = val; } |
101 | | Status refresh(JvmMetrics* jvm_metrics) const; |
102 | | ~JvmStats(); |
103 | | }; |
104 | | |
105 | | class JvmMetrics { |
106 | | public: |
107 | | JvmMetrics(MetricRegistry* registry, JNIEnv* env); |
108 | 0 | ~JvmMetrics() = default; |
109 | | void update(); |
110 | | |
111 | | IntGauge* jvm_heap_size_bytes_max = nullptr; |
112 | | IntGauge* jvm_heap_size_bytes_committed = nullptr; |
113 | | IntGauge* jvm_heap_size_bytes_used = nullptr; |
114 | | |
115 | | IntGauge* jvm_non_heap_size_bytes_used = nullptr; |
116 | | IntGauge* jvm_non_heap_size_bytes_committed = nullptr; |
117 | | |
118 | | IntGauge* jvm_young_size_bytes_used = nullptr; |
119 | | IntGauge* jvm_young_size_bytes_peak_used = nullptr; |
120 | | IntGauge* jvm_young_size_bytes_max = nullptr; |
121 | | |
122 | | IntGauge* jvm_old_size_bytes_used = nullptr; |
123 | | IntGauge* jvm_old_size_bytes_peak_used = nullptr; |
124 | | IntGauge* jvm_old_size_bytes_max = nullptr; |
125 | | |
126 | | IntGauge* jvm_thread_count = nullptr; |
127 | | IntGauge* jvm_thread_peak_count = nullptr; |
128 | | IntGauge* jvm_thread_new_count = nullptr; |
129 | | IntGauge* jvm_thread_runnable_count = nullptr; |
130 | | IntGauge* jvm_thread_blocked_count = nullptr; |
131 | | IntGauge* jvm_thread_waiting_count = nullptr; |
132 | | IntGauge* jvm_thread_timed_waiting_count = nullptr; |
133 | | IntGauge* jvm_thread_terminated_count = nullptr; |
134 | | |
135 | | IntGauge* jvm_gc_g1_young_generation_count = nullptr; |
136 | | IntGauge* jvm_gc_g1_young_generation_time_ms = nullptr; |
137 | | IntGauge* jvm_gc_g1_old_generation_count = nullptr; |
138 | | IntGauge* jvm_gc_g1_old_generation_time_ms = nullptr; |
139 | | |
140 | | private: |
141 | | JvmStats _jvm_stats; |
142 | | std::shared_ptr<MetricEntity> _server_entity; |
143 | | static const char* _s_hook_name; |
144 | | MetricRegistry* _registry = nullptr; |
145 | | }; |
146 | | |
147 | | } // namespace doris |