Skip to content

Commit 149c0c0

Browse files
authored
SubstrateVM awareness (#802)
* SubstrateVM awareness Signed-off-by: Arthur Sengileyev <[email protected]> * SubstrateVM awareness (via system properties check) Signed-off-by: Arthur Sengileyev <[email protected]>
1 parent cb0c862 commit 149c0c0

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.prometheus.client.hotspot;
2+
3+
/**
4+
* Contains utilities to check if we are running inside or building for native image. Default behavior is to check
5+
* if specific for graalvm runtime property is present. For additional optimizations it is possible to do add
6+
* "--initialize-at-build-time=io.prometheus.client.hotspot.NativeImageChecker" to graalvm native image build command and
7+
* the native image will be identified during build time.
8+
*/
9+
public final class NativeImageChecker {
10+
static final boolean isGraalVmNativeImage = System.getProperty("org.graalvm.nativeimage.imagecode") != null;
11+
12+
private NativeImageChecker() {}
13+
}

simpleclient_hotspot/src/main/java/io/prometheus/client/hotspot/ThreadExports.java

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,36 +90,38 @@ void addThreadMetrics(List<MetricFamilySamples> sampleFamilies, Predicate<String
9090
threadBean.getTotalStartedThreadCount()));
9191
}
9292

93-
if (nameFilter.test(JVM_THREADS_DEADLOCKED)) {
94-
sampleFamilies.add(
95-
new GaugeMetricFamily(
96-
JVM_THREADS_DEADLOCKED,
97-
"Cycles of JVM-threads that are in deadlock waiting to acquire object monitors or ownable synchronizers",
98-
nullSafeArrayLength(threadBean.findDeadlockedThreads())));
99-
}
93+
if (!NativeImageChecker.isGraalVmNativeImage) {
94+
if (nameFilter.test(JVM_THREADS_DEADLOCKED)) {
95+
sampleFamilies.add(
96+
new GaugeMetricFamily(
97+
JVM_THREADS_DEADLOCKED,
98+
"Cycles of JVM-threads that are in deadlock waiting to acquire object monitors or ownable synchronizers",
99+
nullSafeArrayLength(threadBean.findDeadlockedThreads())));
100+
}
100101

101-
if (nameFilter.test(JVM_THREADS_DEADLOCKED_MONITOR)) {
102-
sampleFamilies.add(
103-
new GaugeMetricFamily(
104-
JVM_THREADS_DEADLOCKED_MONITOR,
105-
"Cycles of JVM-threads that are in deadlock waiting to acquire object monitors",
106-
nullSafeArrayLength(threadBean.findMonitorDeadlockedThreads())));
107-
}
102+
if (nameFilter.test(JVM_THREADS_DEADLOCKED_MONITOR)) {
103+
sampleFamilies.add(
104+
new GaugeMetricFamily(
105+
JVM_THREADS_DEADLOCKED_MONITOR,
106+
"Cycles of JVM-threads that are in deadlock waiting to acquire object monitors",
107+
nullSafeArrayLength(threadBean.findMonitorDeadlockedThreads())));
108+
}
108109

109-
if (nameFilter.test(JVM_THREADS_STATE)) {
110-
GaugeMetricFamily threadStateFamily = new GaugeMetricFamily(
111-
JVM_THREADS_STATE,
112-
"Current count of threads by state",
113-
Collections.singletonList("state"));
114-
115-
Map<String, Integer> threadStateCounts = getThreadStateCountMap();
116-
for (Map.Entry<String, Integer> entry : threadStateCounts.entrySet()) {
117-
threadStateFamily.addMetric(
118-
Collections.singletonList(entry.getKey()),
119-
entry.getValue()
120-
);
110+
if (nameFilter.test(JVM_THREADS_STATE)) {
111+
GaugeMetricFamily threadStateFamily = new GaugeMetricFamily(
112+
JVM_THREADS_STATE,
113+
"Current count of threads by state",
114+
Collections.singletonList("state"));
115+
116+
Map<String, Integer> threadStateCounts = getThreadStateCountMap();
117+
for (Map.Entry<String, Integer> entry : threadStateCounts.entrySet()) {
118+
threadStateFamily.addMetric(
119+
Collections.singletonList(entry.getKey()),
120+
entry.getValue()
121+
);
122+
}
123+
sampleFamilies.add(threadStateFamily);
121124
}
122-
sampleFamilies.add(threadStateFamily);
123125
}
124126
}
125127

0 commit comments

Comments
 (0)