84 lines
5.1 KiB
Diff
84 lines
5.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|||
|
|
From: NanaChiyo0721 <nanachiyo0721@163.com>
|
||
|
|
Date: Sun, 16 Aug 2026 01:31:31 +0800
|
||
|
|
Subject: [PATCH] Per region async profiler
|
||
|
|
|
||
|
|
|
||
|
|
diff --git a/io/papermc/paper/threadedregions/TickRegionScheduler.java b/io/papermc/paper/threadedregions/TickRegionScheduler.java
|
||
|
|
index 724332d074bd7d3dfdcb60e83cf1fd6ce706000e..eb65077d18d86fce3ae1131445ebdcb736f5dc93 100644
|
||
|
|
--- a/io/papermc/paper/threadedregions/TickRegionScheduler.java
|
||
|
|
+++ b/io/papermc/paper/threadedregions/TickRegionScheduler.java
|
||
|
|
@@ -220,6 +220,7 @@ public final class TickRegionScheduler {
|
||
|
|
*/
|
||
|
|
public void scheduleRegion(final RegionScheduleHandle region) {
|
||
|
|
region.scheduler = this;
|
||
|
|
+ region.scheduleProfiler = TickRegions.getScheduleProfilerManager().register(region.id); // Shiroha - per region async profiler
|
||
|
|
this.scheduler.schedule(region);
|
||
|
|
}
|
||
|
|
|
||
|
|
@@ -230,6 +231,7 @@ public final class TickRegionScheduler {
|
||
|
|
public void descheduleRegion(final RegionScheduleHandle region) {
|
||
|
|
// To avoid acquiring any of the locks the scheduler may be using, we
|
||
|
|
// simply cancel the next action.
|
||
|
|
+ TickRegions.getScheduleProfilerManager().deRegister(region.id); region.scheduleProfiler = null; // Shiroha - per region async profiler
|
||
|
|
region.markNonSchedulable();
|
||
|
|
}
|
||
|
|
|
||
|
|
@@ -296,6 +298,7 @@ public final class TickRegionScheduler {
|
||
|
|
}
|
||
|
|
|
||
|
|
public static abstract class RegionScheduleHandle extends SchedulableTick {
|
||
|
|
+ public io.nanachiyo0721.shiroha.utils.profiling.RegionScheduleProfiler scheduleProfiler = null; // Shiroha - per region async profiler
|
||
|
|
|
||
|
|
protected long currentTick;
|
||
|
|
protected long lastTickStart;
|
||
|
|
@@ -391,6 +394,7 @@ public final class TickRegionScheduler {
|
||
|
|
|
||
|
|
final FoliaWatchdogThread.RunningTick runningTick = new FoliaWatchdogThread.RunningTick(tickStart, this, Thread.currentThread()); // Folia - watchdog
|
||
|
|
WATCHDOG_THREAD.addTick(runningTick); // Folia - watchdog
|
||
|
|
+ if (this.scheduleProfiler != null) this.scheduleProfiler.taskBegin(); // Shiroha - per region async profiler
|
||
|
|
try {
|
||
|
|
this.runRegionTasks(() -> {
|
||
|
|
return !RegionScheduleHandle.this.cancelled.get() && canContinue.getAsBoolean();
|
||
|
|
@@ -400,6 +404,7 @@ public final class TickRegionScheduler {
|
||
|
|
// don't release region for another tick
|
||
|
|
return false;
|
||
|
|
} finally {
|
||
|
|
+ if (this.scheduleProfiler != null) this.scheduleProfiler.taskEnd(); // Shiroha - per region async profiler
|
||
|
|
WATCHDOG_THREAD.removeTick(runningTick); // Folia - watchdog
|
||
|
|
final long tickEnd = System.nanoTime();
|
||
|
|
final long cpuEnd = MEASURE_CPU_TIME ? THREAD_MX_BEAN.getCurrentThreadCpuTime() : 0L;
|
||
|
|
@@ -476,6 +481,7 @@ public final class TickRegionScheduler {
|
||
|
|
|
||
|
|
final FoliaWatchdogThread.RunningTick runningTick = new FoliaWatchdogThread.RunningTick(tickStart, this, Thread.currentThread()); // Folia - region threading
|
||
|
|
WATCHDOG_THREAD.addTick(runningTick); // Folia - region threading
|
||
|
|
+ if (this.scheduleProfiler != null) this.scheduleProfiler.tickBegin(); // Shiroha - per region async profiler
|
||
|
|
try {
|
||
|
|
// next start isn't updated until the end of this tick
|
||
|
|
this.tickRegion(tickCount, tickStart, scheduledEnd);
|
||
|
|
@@ -489,6 +495,7 @@ public final class TickRegionScheduler {
|
||
|
|
// regionFailed will schedule a shutdown, so we should avoid letting this region tick further
|
||
|
|
return false;
|
||
|
|
} finally {
|
||
|
|
+ if (this.scheduleProfiler != null) this.scheduleProfiler.tickEnd(); // Shiroha - per region async profiler
|
||
|
|
WATCHDOG_THREAD.removeTick(runningTick); // Folia - region threading
|
||
|
|
final long tickEnd = System.nanoTime();
|
||
|
|
final long cpuEnd = MEASURE_CPU_TIME ? THREAD_MX_BEAN.getCurrentThreadCpuTime() : 0L;
|
||
|
|
diff --git a/io/papermc/paper/threadedregions/TickRegions.java b/io/papermc/paper/threadedregions/TickRegions.java
|
||
|
|
index ab94ea7f18799d9dd3cf164a1332db69f40a9278..863f78680150d87c5b82132e471baac527452b6b 100644
|
||
|
|
--- a/io/papermc/paper/threadedregions/TickRegions.java
|
||
|
|
+++ b/io/papermc/paper/threadedregions/TickRegions.java
|
||
|
|
@@ -36,10 +36,12 @@ public final class TickRegions implements ThreadedRegionizer.RegionCallbacks<Tic
|
||
|
|
private static boolean initialised;
|
||
|
|
private static boolean started;
|
||
|
|
private static TickRegionScheduler scheduler;
|
||
|
|
+ private static final io.nanachiyo0721.shiroha.utils.profiling.RegionScheduleProfilerManager scheduleProfilerManager = new io.nanachiyo0721.shiroha.utils.profiling.RegionScheduleProfilerManager(); // Shiroha - per region async profiler
|
||
|
|
|
||
|
|
public static TickRegionScheduler getScheduler() {
|
||
|
|
return scheduler;
|
||
|
|
}
|
||
|
|
+ public static io.nanachiyo0721.shiroha.utils.profiling.RegionScheduleProfilerManager getScheduleProfilerManager() { return scheduleProfilerManager; } // Shiroha - per region async profiler
|
||
|
|
|
||
|
|
private static int getTickThreads(final GlobalConfiguration.ThreadedRegions config) {
|
||
|
|
int tickThreads;
|