Log jemalloc presence and version at startup (#4738)

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
This commit is contained in:
Fabio Di Fabio
2023-04-11 15:49:59 +02:00
committed by GitHub
parent 4737f14534
commit a9b906cba5
7 changed files with 103 additions and 19 deletions

View File

@@ -32,6 +32,7 @@ dependencies {
api 'org.slf4j:slf4j-api'
implementation 'com.google.guava:guava'
implementation 'net.java.dev.jna:jna'
implementation 'org.apache.commons:commons-lang3'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.apache.logging.log4j:log4j-slf4j2-impl'

View File

@@ -23,6 +23,11 @@ import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
/**
* Detects OS and VMs.
*
@@ -36,6 +41,7 @@ public class PlatformDetector {
private static String _vm;
private static String _arch;
private static String _glibc;
private static String _jemalloc;
/**
* Gets OS type.
@@ -98,6 +104,14 @@ public class PlatformDetector {
return _glibc;
}
public static String getJemalloc() {
if (_jemalloc == null) {
detectJemalloc();
}
return _jemalloc;
}
private static final String UNKNOWN = "unknown";
private static void detect() {
@@ -306,4 +320,23 @@ public class PlatformDetector {
return matcher.find() ? matcher.group() : null;
}
private static void detectJemalloc() {
interface JemallocLib extends Library {
int mallctl(
String property,
PointerByReference value,
IntByReference len,
String newValue,
int newLen);
}
final JemallocLib jemallocLib = Native.load("jemalloc", JemallocLib.class);
PointerByReference pVersion = new PointerByReference();
IntByReference pSize = new IntByReference(Native.POINTER_SIZE);
jemallocLib.mallctl("version", pVersion, pSize, null, 0);
_jemalloc = pVersion.getValue().getString(0);
}
}