ProfiledReloadInstance.java
net.minecraft.server.packs.resources.ProfiledReloadInstance
信息
- 全限定名:net.minecraft.server.packs.resources.ProfiledReloadInstance
- 类型:public class
- 包:net.minecraft.server.packs.resources
- 源码路径:src/main/java/net/minecraft/server/packs/resources/ProfiledReloadInstance.java
- 起始行号:L16
- 继承:SimpleReloadInstance<ProfiledReloadInstance.State>
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L17 - 说明:
TODO
- 类型:
-
total- 类型:
Stopwatch - 修饰符:
private final - 源码定位:
L18 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.server.packs.resources.ProfiledReloadInstance.State- 类型:
record - 修饰符:
public - 源码定位:
L114 - 说明:
TODO
- 类型:
构造器
private ProfiledReloadInstance(List<PreparableReloadListener> listeners) @ L54
- 构造器名:ProfiledReloadInstance
- 源码定位:L54
- 修饰符:private
参数:
- listeners: List
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static ReloadInstance of(ResourceManager resourceManager, List<PreparableReloadListener> listeners, Executor taskExecutor, Executor mainThreadExecutor, CompletableFuture<Unit> initialTask) @ L20
- 方法名:of
- 源码定位:L20
- 返回类型:ReloadInstance
- 修饰符:public static
参数:
- resourceManager: ResourceManager
- listeners: List
- taskExecutor: Executor
- mainThreadExecutor: Executor
- initialTask: CompletableFuture
说明:
TODO
protected CompletableFuture<List<ProfiledReloadInstance.State>> prepareTasks(Executor taskExecutor, Executor mainThreadExecutor, ResourceManager resourceManager, List<PreparableReloadListener> listeners, SimpleReloadInstance.StateFactory<ProfiledReloadInstance.State> stateFactory, CompletableFuture<?> initialTask) @ L59
- 方法名:prepareTasks
- 源码定位:L59
- 返回类型:CompletableFuture<List<ProfiledReloadInstance.State>>
- 修饰符:protected
参数:
- taskExecutor: Executor
- mainThreadExecutor: Executor
- resourceManager: ResourceManager
- listeners: List
- stateFactory: SimpleReloadInstance.StateFactory<ProfiledReloadInstance.State>
- initialTask: CompletableFuture<?>
说明:
TODO
private static Executor profiledExecutor(Executor executor, AtomicLong accumulatedNanos, AtomicLong taskCount, String name) @ L72
- 方法名:profiledExecutor
- 源码定位:L72
- 返回类型:Executor
- 修饰符:private static
参数:
- executor: Executor
- accumulatedNanos: AtomicLong
- taskCount: AtomicLong
- name: String
说明:
TODO
private List<ProfiledReloadInstance.State> finish(List<ProfiledReloadInstance.State> result) @ L84
- 方法名:finish
- 源码定位:L84
- 返回类型:List<ProfiledReloadInstance.State>
- 修饰符:private
参数:
- result: List<ProfiledReloadInstance.State>
说明:
TODO
代码
public class ProfiledReloadInstance extends SimpleReloadInstance<ProfiledReloadInstance.State> {
private static final Logger LOGGER = LogUtils.getLogger();
private final Stopwatch total = Stopwatch.createUnstarted();
public static ReloadInstance of(
ResourceManager resourceManager,
List<PreparableReloadListener> listeners,
Executor taskExecutor,
Executor mainThreadExecutor,
CompletableFuture<Unit> initialTask
) {
ProfiledReloadInstance result = new ProfiledReloadInstance(listeners);
result.startTasks(
taskExecutor,
mainThreadExecutor,
resourceManager,
listeners,
(currentReload, previousStep, listener, parentTaskExecutor, parentReloadExecutor) -> {
AtomicLong preparationNanos = new AtomicLong();
AtomicLong preparationCount = new AtomicLong();
AtomicLong reloadNanos = new AtomicLong();
AtomicLong reloadCount = new AtomicLong();
CompletableFuture<Void> reload = listener.reload(
currentReload,
profiledExecutor(parentTaskExecutor, preparationNanos, preparationCount, listener.getName()),
previousStep,
profiledExecutor(parentReloadExecutor, reloadNanos, reloadCount, listener.getName())
);
return reload.thenApplyAsync(v -> {
LOGGER.debug("Finished reloading {}", listener.getName());
return new ProfiledReloadInstance.State(listener.getName(), preparationNanos, preparationCount, reloadNanos, reloadCount);
}, mainThreadExecutor);
},
initialTask
);
return result;
}
private ProfiledReloadInstance(List<PreparableReloadListener> listeners) {
super(listeners);
this.total.start();
}
@Override
protected CompletableFuture<List<ProfiledReloadInstance.State>> prepareTasks(
Executor taskExecutor,
Executor mainThreadExecutor,
ResourceManager resourceManager,
List<PreparableReloadListener> listeners,
SimpleReloadInstance.StateFactory<ProfiledReloadInstance.State> stateFactory,
CompletableFuture<?> initialTask
) {
return super.prepareTasks(taskExecutor, mainThreadExecutor, resourceManager, listeners, stateFactory, initialTask)
.thenApplyAsync(this::finish, mainThreadExecutor);
}
private static Executor profiledExecutor(Executor executor, AtomicLong accumulatedNanos, AtomicLong taskCount, String name) {
return r -> executor.execute(() -> {
ProfilerFiller profiler = Profiler.get();
profiler.push(name);
long nanos = Util.getNanos();
r.run();
accumulatedNanos.addAndGet(Util.getNanos() - nanos);
taskCount.incrementAndGet();
profiler.pop();
});
}
private List<ProfiledReloadInstance.State> finish(List<ProfiledReloadInstance.State> result) {
this.total.stop();
long blockingTime = 0L;
LOGGER.info("Resource reload finished after {} ms", this.total.elapsed(TimeUnit.MILLISECONDS));
for (ProfiledReloadInstance.State state : result) {
long prepTime = TimeUnit.NANOSECONDS.toMillis(state.preparationNanos.get());
long prepCount = state.preparationCount.get();
long reloadTime = TimeUnit.NANOSECONDS.toMillis(state.reloadNanos.get());
long reloadCount = state.reloadCount.get();
long totalTime = prepTime + reloadTime;
long totalCount = prepCount + reloadCount;
String name = state.name;
LOGGER.info(
"{} took approximately {} tasks/{} ms ({} tasks/{} ms preparing, {} tasks/{} ms applying)",
name,
totalCount,
totalTime,
prepCount,
prepTime,
reloadCount,
reloadTime
);
blockingTime += reloadTime;
}
LOGGER.info("Total blocking time: {} ms", blockingTime);
return result;
}
public record State(String name, AtomicLong preparationNanos, AtomicLong preparationCount, AtomicLong reloadNanos, AtomicLong reloadCount) {
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/继承
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.getNanos()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Profiler.get()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Stopwatch.createUnstarted()
- 引用位置: