Profiler.java

net.minecraft.util.profiling.Profiler

信息

  • 全限定名:net.minecraft.util.profiling.Profiler
  • 类型:public final class
  • 包:net.minecraft.util.profiling
  • 源码路径:src/main/java/net/minecraft/util/profiling/Profiler.java
  • 起始行号:L8
  • 职责:

    TODO

字段/常量

  • TRACY_FILLER

    • 类型: ThreadLocal<TracyZoneFiller>
    • 修饰符: private static final
    • 源码定位: L9
    • 说明:

      TODO

  • ACTIVE

    • 类型: ThreadLocal<ProfilerFiller>
    • 修饰符: private static final
    • 源码定位: L10
    • 说明:

      TODO

  • ACTIVE_COUNT

    • 类型: AtomicInteger
    • 修饰符: private static final
    • 源码定位: L11
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.util.profiling.Profiler.Scope
    • 类型: interface
    • 修饰符: public
    • 源码定位: L55
    • 说明:

      TODO

构造器

private Profiler() @ L13

  • 构造器名:Profiler
  • 源码定位:L13
  • 修饰符:private

参数:

说明:

TODO

方法

下面的方法块按源码顺序生成。

public static Profiler.Scope use(ProfilerFiller filler) @ L16

  • 方法名:use
  • 源码定位:L16
  • 返回类型:Profiler.Scope
  • 修饰符:public static

参数:

  • filler: ProfilerFiller

说明:

TODO

private static void startUsing(ProfilerFiller filler) @ L21

  • 方法名:startUsing
  • 源码定位:L21
  • 返回类型:void
  • 修饰符:private static

参数:

  • filler: ProfilerFiller

说明:

TODO

private static void stopUsing() @ L32

  • 方法名:stopUsing
  • 源码定位:L32
  • 返回类型:void
  • 修饰符:private static

参数:

说明:

TODO

private static ProfilerFiller decorateFiller(ProfilerFiller filler) @ L43

  • 方法名:decorateFiller
  • 源码定位:L43
  • 返回类型:ProfilerFiller
  • 修饰符:private static

参数:

  • filler: ProfilerFiller

说明:

TODO

public static ProfilerFiller get() @ L47

  • 方法名:get
  • 源码定位:L47
  • 返回类型:ProfilerFiller
  • 修饰符:public static

参数:

说明:

TODO

private static ProfilerFiller getDefaultFiller() @ L51

  • 方法名:getDefaultFiller
  • 源码定位:L51
  • 返回类型:ProfilerFiller
  • 修饰符:private static

参数:

说明:

TODO

代码

public final class Profiler {
    private static final ThreadLocal<TracyZoneFiller> TRACY_FILLER = ThreadLocal.withInitial(TracyZoneFiller::new);
    private static final ThreadLocal<@Nullable ProfilerFiller> ACTIVE = new ThreadLocal<>();
    private static final AtomicInteger ACTIVE_COUNT = new AtomicInteger();
 
    private Profiler() {
    }
 
    public static Profiler.Scope use(ProfilerFiller filler) {
        startUsing(filler);
        return Profiler::stopUsing;
    }
 
    private static void startUsing(ProfilerFiller filler) {
        if (ACTIVE.get() != null) {
            throw new IllegalStateException("Profiler is already active");
        } else {
            ProfilerFiller active = decorateFiller(filler);
            ACTIVE.set(active);
            ACTIVE_COUNT.incrementAndGet();
            active.startTick();
        }
    }
 
    private static void stopUsing() {
        ProfilerFiller active = ACTIVE.get();
        if (active == null) {
            throw new IllegalStateException("Profiler was not active");
        } else {
            ACTIVE.remove();
            ACTIVE_COUNT.decrementAndGet();
            active.endTick();
        }
    }
 
    private static ProfilerFiller decorateFiller(ProfilerFiller filler) {
        return ProfilerFiller.combine(getDefaultFiller(), filler);
    }
 
    public static ProfilerFiller get() {
        return ACTIVE_COUNT.get() == 0 ? getDefaultFiller() : Objects.requireNonNullElseGet(ACTIVE.get(), Profiler::getDefaultFiller);
    }
 
    private static ProfilerFiller getDefaultFiller() {
        return (ProfilerFiller)(TracyClient.isAvailable() ? TRACY_FILLER.get() : InactiveProfiler.INSTANCE);
    }
 
    public interface Scope extends AutoCloseable {
        @Override
        void close();
    }
}

引用的其他类