Run ThreadMXBean method in the enable method

This commit is contained in:
TheMode 2021-08-15 23:16:50 +02:00
parent b370f55ee0
commit ef5c15fb6a

View File

@ -36,9 +36,6 @@ public final class BenchmarkManager {
private static final List<String> THREADS = new ArrayList<>(); private static final List<String> THREADS = new ArrayList<>();
static { static {
THREAD_MX_BEAN.setThreadContentionMonitoringEnabled(true);
THREAD_MX_BEAN.setThreadCpuTimeEnabled(true);
THREADS.add(THREAD_NAME_BLOCK_BATCH); THREADS.add(THREAD_NAME_BLOCK_BATCH);
THREADS.add(THREAD_NAME_SCHEDULER); THREADS.add(THREAD_NAME_SCHEDULER);
THREADS.add(THREAD_NAME_TICK_SCHEDULER); THREADS.add(THREAD_NAME_TICK_SCHEDULER);
@ -59,23 +56,21 @@ public final class BenchmarkManager {
public void enable(@NotNull Duration duration) { public void enable(@NotNull Duration duration) {
Check.stateCondition(enabled, "A benchmark is already running, please disable it first."); Check.stateCondition(enabled, "A benchmark is already running, please disable it first.");
THREAD_MX_BEAN.setThreadContentionMonitoringEnabled(true);
THREAD_MX_BEAN.setThreadCpuTimeEnabled(true);
time = duration.toMillis(); this.time = duration.toMillis();
final Thread thread = new Thread(null, () -> { final Thread thread = new Thread(null, () -> {
while (!stop) { while (!stop) {
refreshData(); refreshData();
try { try {
Thread.sleep(time); Thread.sleep(time);
} catch (InterruptedException e) { } catch (InterruptedException e) {
MinecraftServer.getExceptionManager().handleException(e); MinecraftServer.getExceptionManager().handleException(e);
} }
} }
stop = false; stop = false;
}, MinecraftServer.THREAD_NAME_BENCHMARK); }, MinecraftServer.THREAD_NAME_BENCHMARK);
thread.setDaemon(true); thread.setDaemon(true);
thread.start(); thread.start();