From ca179bc73fba63f57c480e1f18e5006d473a1361 Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Mon, 21 Aug 2017 15:44:31 +0100 Subject: [PATCH] Fix another minor derp with disabled profiler, improve section hierarchy --- .../mixin/transformer/MixinTransformer.java | 7 +- .../asm/mixin/transformer/TreeInfo.java | 2 +- .../spongepowered/asm/util/perf/Profiler.java | 82 ++++++++++++++++--- 3 files changed, 79 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java index c282f159..f3664f71 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/MixinTransformer.java @@ -551,10 +551,12 @@ public class MixinTransformer extends TreeTransformer { long loadTime = this.profiler.get("class.load").getTotalTime(); long transformTime = this.profiler.get("class.transform").getTotalTime(); - long actualTime = totalMixinTime - loadTime - transformTime; + long exportTime = this.profiler.get("mixin.debug.export").getTotalTime(); + long actualTime = totalMixinTime - loadTime - transformTime - exportTime; double timeSliceMixin = ((double)actualTime / (double)totalMixinTime) * 100.0D; double timeSliceLoad = ((double)loadTime / (double)totalMixinTime) * 100.0D; double timeSliceTransform = ((double)transformTime / (double)totalMixinTime) * 100.0D; + double timeSliceExport = ((double)exportTime / (double)totalMixinTime) * 100.0D; long worstTransformerTime = 0L; Section worstTransformer = null; @@ -590,6 +592,9 @@ public class MixinTransformer extends TreeTransformer { printer.kv(" Time allocation: Processing mixins", "%9d ms %10s%% of total)", actualTime, onedp.format(timeSliceMixin)); printer.kv("Loading classes", "%9d ms %10s%% of total)", loadTime, onedp.format(timeSliceLoad)); printer.kv("Running transformers", "%9d ms %10s%% of total)", transformTime, onedp.format(timeSliceTransform)); + if (exportTime > 0L) { + printer.kv("Exporting classes (debug)", "%9d ms %10s%% of total)", exportTime, onedp.format(timeSliceExport)); + } printer.add(); try { diff --git a/src/main/java/org/spongepowered/asm/mixin/transformer/TreeInfo.java b/src/main/java/org/spongepowered/asm/mixin/transformer/TreeInfo.java index 65dd5d58..d9af1bbe 100644 --- a/src/main/java/org/spongepowered/asm/mixin/transformer/TreeInfo.java +++ b/src/main/java/org/spongepowered/asm/mixin/transformer/TreeInfo.java @@ -158,7 +158,7 @@ abstract class TreeInfo { } Class clazz = transformer.getClass(); - Section transformTime = profiler.begin(Profiler.ROOT | Profiler.FINE, "class.transform", clazz.getSimpleName().toLowerCase()); + Section transformTime = profiler.begin(Profiler.FINE, clazz.getSimpleName().toLowerCase()); transformTime.setInfo(clazz.getName()); basicClass = transformer.transform(name, transformedName, basicClass); transformTime.end(); diff --git a/src/main/java/org/spongepowered/asm/util/perf/Profiler.java b/src/main/java/org/spongepowered/asm/util/perf/Profiler.java index e4af3bea..322f4e05 100644 --- a/src/main/java/org/spongepowered/asm/util/perf/Profiler.java +++ b/src/main/java/org/spongepowered/asm/util/perf/Profiler.java @@ -56,21 +56,35 @@ public final class Profiler { */ public class Section { + static final String SEPARATOR_ROOT = " -> "; + + static final String SEPARATOR_CHILD = "."; + /** * Section name */ private final String name; + + /** + * True if this is a ROOT section + */ + private boolean root; /** * True if this is a FINE section */ private boolean fine; + /** + * True if this section has been invalidated by a call to Profiler#clear + */ + protected boolean invalidated; + /** * Auxilliary info for this section, used for context */ private String info; - + Section(String name) { this.name = name; this.info = name; @@ -83,8 +97,32 @@ public final class Profiler { return this; } + Section invalidate() { + this.invalidated = true; + return this; + } + + /** + * Mark this section as ROOT + * + * @return fluent + */ + Section setRoot(boolean root) { + this.root = root; + return this; + } + + /** + * Get whether this is a root section + */ + public boolean isRoot() { + return this.root; + } + /** * Set this section as FINE + * + * @return fluent */ Section setFine(boolean fine) { this.fine = fine; @@ -153,7 +191,9 @@ public final class Profiler { * @return fluent */ public Section end() { - Profiler.this.end(this); + if (!this.invalidated) { + Profiler.this.end(this); + } return this; } @@ -309,7 +349,9 @@ public final class Profiler { @Override public Section end() { this.stop(); - Profiler.this.end(this); + if (!this.invalidated) { + Profiler.this.end(this); + } return this; } @@ -399,6 +441,12 @@ public final class Profiler { this.root = root; } + @Override + Section invalidate() { + this.root.invalidate(); + return super.invalidate(); + } + @Override public String getBaseName() { return this.baseName; @@ -476,6 +524,10 @@ public final class Profiler { * Reset all profiler state */ public void reset() { + for (Section section : this.sections.values()) { + section.invalidate(); + } + this.sections.clear(); this.phases.clear(); this.phases.add("Initial"); @@ -557,7 +609,12 @@ public final class Profiler { String path = name; Section head = this.stack.peek(); if (head != null) { - path = head.getName() + (root ? " -> " : ".") + path; + path = head.getName() + (root ? Section.SEPARATOR_ROOT : Section.SEPARATOR_CHILD) + path; + if (head.isRoot() && !root) { + int pos = head.getName().lastIndexOf(Section.SEPARATOR_ROOT); + name = (pos > -1 ? head.getName().substring(pos + 4) : head.getName()) + Section.SEPARATOR_CHILD + name; + root = true; + } } Section section = this.get(root ? name : path); @@ -565,8 +622,9 @@ public final class Profiler { section = this.getSubSection(path, head.getName(), section); } - section.setFine(fine); + section.setFine(fine).setRoot(root); this.stack.push(section); + return section.start(); } @@ -577,13 +635,17 @@ public final class Profiler { * @param section section ending */ void end(Section section) { - for (Section head = this.stack.pop(), next = head; next != section; next = this.stack.pop()) { - if (next == null) { - if (head == null) { - throw new IllegalStateException("Attempted to pop " + section + " but the stack is empty"); + try { + for (Section head = this.stack.pop(), next = head; next != section; next = this.stack.pop()) { + if (next == null) { + if (head == null) { + throw new IllegalStateException("Attempted to pop " + section + " but the stack is empty"); + } + throw new IllegalStateException("Attempted to pop " + section + " which was not in the stack, head was " + head); } - throw new IllegalStateException("Attempted to pop " + section + " which was not in the stack, head was " + head); } + } catch (NoSuchElementException ex) { + throw new IllegalStateException("Attempted to pop " + section + " but the stack is empty"); } }