mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 14:33:56 +01:00
4d3bf20155
This is highly useful for profiling vanilla code, and in some cases plugin code. It is somewhat expensive, though, which is why it was initially disabled.
I chose to use a system property instead of a configuration setting because 1) the MethodProfiler is exclusive to CraftBukkit and not part of the general API (the timings system is the general API equivalent), and 2) using a static final boolean property _may_ allow the JITter to optimize out the methods when disabled (though I'm not sure of it).
There are several changes to fix cases where the profiler code was broken slightly by other craftbukkit changes. All of cases have been fixed, except for the block entity ticking one, due to the cost of the getSimpleName call. For that, a ticking entry is used instead, so that time spent actually ticking the block entities can be compared with time processing the list.
This (effectively) reverts 7dde6cc566
.
66 lines
2.1 KiB
Diff
66 lines
2.1 KiB
Diff
--- a/net/minecraft/server/MethodProfiler.java
|
|
+++ b/net/minecraft/server/MethodProfiler.java
|
|
@@ -12,6 +12,7 @@
|
|
|
|
public class MethodProfiler {
|
|
|
|
+ public static final boolean ENABLED = Boolean.getBoolean("enableDebugMethodProfiler"); // CraftBukkit - disable unless specified in JVM arguments
|
|
private static final Logger b = LogManager.getLogger();
|
|
private final List<String> c = Lists.newArrayList();
|
|
private final List<Long> d = Lists.newArrayList();
|
|
@@ -22,12 +23,14 @@
|
|
public MethodProfiler() {}
|
|
|
|
public void a() {
|
|
+ if (!ENABLED) return; // CraftBukkit
|
|
this.f.clear();
|
|
this.e = "";
|
|
this.c.clear();
|
|
}
|
|
|
|
public void a(String s) {
|
|
+ if (!ENABLED) return; // CraftBukkit
|
|
if (this.a) {
|
|
if (this.e.length() > 0) {
|
|
this.e = this.e + ".";
|
|
@@ -40,6 +43,7 @@
|
|
}
|
|
|
|
public void b() {
|
|
+ if (!ENABLED) return; // CraftBukkit
|
|
if (this.a) {
|
|
long i = System.nanoTime();
|
|
long j = ((Long) this.d.remove(this.d.size() - 1)).longValue();
|
|
@@ -62,7 +66,7 @@
|
|
}
|
|
|
|
public List<MethodProfiler.ProfilerInfo> b(String s) {
|
|
- if (!this.a) {
|
|
+ if (!ENABLED || !this.a) { // CraftBukkit
|
|
return Collections.emptyList();
|
|
} else {
|
|
long i = this.f.containsKey("root") ? ((Long) this.f.get("root")).longValue() : 0L;
|
|
@@ -128,11 +132,13 @@
|
|
}
|
|
|
|
public void c(String s) {
|
|
+ if (!ENABLED) return; // CraftBukkit
|
|
this.b();
|
|
this.a(s);
|
|
}
|
|
|
|
public String c() {
|
|
+ if (!ENABLED) return "[DISABLED]"; // CraftBukkit
|
|
return this.c.size() == 0 ? "[UNKNOWN]" : (String) this.c.get(this.c.size() - 1);
|
|
}
|
|
|
|
@@ -152,7 +158,7 @@
|
|
return methodprofiler_profilerinfo.a < this.a ? -1 : (methodprofiler_profilerinfo.a > this.a ? 1 : methodprofiler_profilerinfo.c.compareTo(this.c));
|
|
}
|
|
|
|
- public int compareTo(Object object) {
|
|
+ public int compareTo(MethodProfiler.ProfilerInfo object) { // CraftBukkit: decompile error
|
|
return this.a((MethodProfiler.ProfilerInfo) object);
|
|
}
|
|
}
|