Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b58c882
commit 7d937f6
Showing
18 changed files
with
213 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/bgsoftware/superiorskyblock/core/profiler/ProfileType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.bgsoftware.superiorskyblock.core.profiler; | ||
|
||
import com.bgsoftware.superiorskyblock.core.LazyReference; | ||
import com.bgsoftware.superiorskyblock.core.formatting.Formatters; | ||
|
||
public enum ProfileType { | ||
|
||
CREATE_ISLAND, | ||
DISBAND_ISLAND, | ||
SCHEMATIC_PLACE; | ||
|
||
private final LazyReference<String> prettyName = new LazyReference<String>() { | ||
@Override | ||
protected String create() { | ||
return Formatters.CAPITALIZED_FORMATTER.format(ProfileType.this.name()); | ||
} | ||
}; | ||
|
||
ProfileType() { | ||
|
||
} | ||
|
||
public String getPrettyName() { | ||
return this.prettyName.get(); | ||
} | ||
|
||
} |
98 changes: 98 additions & 0 deletions
98
src/main/java/com/bgsoftware/superiorskyblock/core/profiler/Profiler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.bgsoftware.superiorskyblock.core.profiler; | ||
|
||
import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin; | ||
import com.bgsoftware.superiorskyblock.core.logging.Debug; | ||
import com.bgsoftware.superiorskyblock.core.logging.Log; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
public class Profiler { | ||
|
||
private static final SuperiorSkyblockPlugin plugin = SuperiorSkyblockPlugin.getPlugin(); | ||
|
||
private Profiler() { | ||
|
||
} | ||
|
||
private static final long INVALID_PROFILE_ID = -1; | ||
|
||
private static final Map<Long, ProfilerSession> profilerSessions = new ConcurrentHashMap<>(); | ||
private static final AtomicLong lastProfilerId = new AtomicLong(0); | ||
|
||
public static long start(ProfileType profileType) { | ||
return start(profileType, 1); | ||
} | ||
|
||
public static long start(ProfileType profileType, int stopCount) { | ||
if (!Log.isDebugged(Debug.PROFILER)) | ||
return INVALID_PROFILE_ID; | ||
|
||
ProfilerSession profilerSession = new ProfilerSession(lastProfilerId.incrementAndGet(), stopCount, profileType); | ||
profilerSessions.put(profilerSession.id, profilerSession); | ||
return profilerSession.id; | ||
} | ||
|
||
public static void end(long id) { | ||
if (id == INVALID_PROFILE_ID) | ||
return; | ||
|
||
ProfilerSession profilerSession = profilerSessions.get(id); | ||
|
||
if (profilerSession == null) | ||
return; | ||
|
||
if (profilerSession.end()) { | ||
profilerSessions.remove(id); | ||
Log.profile(profilerSession.dump()); | ||
} | ||
} | ||
|
||
private static class ProfilerSession { | ||
|
||
private final long id; | ||
private final AtomicInteger stopCount; | ||
private final ProfileType profileType; | ||
private final ProfiledData startData; | ||
private ProfiledData endData; | ||
|
||
ProfilerSession(long id, int stopCount, ProfileType profileType) { | ||
this.id = id; | ||
this.stopCount = new AtomicInteger(stopCount); | ||
this.profileType = profileType; | ||
this.startData = new ProfiledData(); | ||
} | ||
|
||
boolean end() { | ||
boolean ended = this.stopCount.decrementAndGet() <= 0; | ||
if (ended) | ||
this.endData = new ProfiledData(); | ||
return ended; | ||
} | ||
|
||
String[] dump() { | ||
List<String> dump = new ArrayList<>(); | ||
|
||
dump.add("Profiler #" + this.id); | ||
dump.add(" Type: " + this.profileType.getPrettyName()); | ||
dump.add(" Time elapsed: " + TimeUnit.NANOSECONDS.toMillis(this.endData.time - this.startData.time) + "ms"); | ||
dump.add(" TPS: " + this.startData.tps + " -> " + this.endData.tps); | ||
|
||
return dump.toArray(new String[0]); | ||
} | ||
|
||
} | ||
|
||
private static class ProfiledData { | ||
|
||
private final long time = System.nanoTime(); | ||
private final double tps = plugin.getNMSAlgorithms().getCurrentTps(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,4 +47,6 @@ public interface NMSAlgorithms { | |
|
||
int getMaxWorldSize(); | ||
|
||
double getCurrentTps(); | ||
|
||
} |
Oops, something went wrong.