mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Refactoring
This commit is contained in:
parent
ef7624dde9
commit
697b173359
@ -36,6 +36,11 @@ public enum PerformanceRating implements Predicate<Float> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(Float value) {
|
public boolean test(Float value) {
|
||||||
|
if (value == null) {
|
||||||
|
// null will only test true for UNKNOWN
|
||||||
|
return threshold < 0;
|
||||||
|
}
|
||||||
|
|
||||||
return value <= threshold;
|
return value <= threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ class PerformanceSummary {
|
|||||||
private final PerformanceRating rating;
|
private final PerformanceRating rating;
|
||||||
private final long totalElapsedTime;
|
private final long totalElapsedTime;
|
||||||
private final int totalTickedBlocks;
|
private final int totalTickedBlocks;
|
||||||
|
private final float percentage;
|
||||||
|
|
||||||
private final Map<String, Long> chunks;
|
private final Map<String, Long> chunks;
|
||||||
private final Map<String, Long> items;
|
private final Map<String, Long> items;
|
||||||
@ -38,6 +39,7 @@ class PerformanceSummary {
|
|||||||
PerformanceSummary(SlimefunProfiler profiler, long totalElapsedTime, int totalTickedBlocks) {
|
PerformanceSummary(SlimefunProfiler profiler, long totalElapsedTime, int totalTickedBlocks) {
|
||||||
this.profiler = profiler;
|
this.profiler = profiler;
|
||||||
this.rating = profiler.getPerformance();
|
this.rating = profiler.getPerformance();
|
||||||
|
this.percentage = profiler.getPercentageOfTick();
|
||||||
this.totalElapsedTime = totalElapsedTime;
|
this.totalElapsedTime = totalElapsedTime;
|
||||||
this.totalTickedBlocks = totalTickedBlocks;
|
this.totalTickedBlocks = totalTickedBlocks;
|
||||||
|
|
||||||
@ -48,13 +50,13 @@ class PerformanceSummary {
|
|||||||
public void send(CommandSender sender) {
|
public void send(CommandSender sender) {
|
||||||
sender.sendMessage("");
|
sender.sendMessage("");
|
||||||
sender.sendMessage(ChatColor.GREEN + "===== Slimefun Lag Profiler =====");
|
sender.sendMessage(ChatColor.GREEN + "===== Slimefun Lag Profiler =====");
|
||||||
sender.sendMessage(ChatColors.color("&6Total: &e" + NumberUtils.getAsMillis(totalElapsedTime)));
|
sender.sendMessage(ChatColor.GOLD + "Total: " + ChatColor.YELLOW + NumberUtils.getAsMillis(totalElapsedTime));
|
||||||
sender.sendMessage(ChatColors.color("&6Performance: " + getPerformanceRating()));
|
sender.sendMessage(ChatColor.GOLD + "Performance: " + getPerformanceRating());
|
||||||
sender.sendMessage(ChatColors.color("&6Active Chunks: &e" + chunks.size()));
|
sender.sendMessage(ChatColor.GOLD + "Active Chunks: " + ChatColor.YELLOW + chunks.size());
|
||||||
sender.sendMessage(ChatColors.color("&6Active Blocks: &e" + totalTickedBlocks));
|
sender.sendMessage(ChatColor.GOLD + "Active Blocks: " + ChatColor.YELLOW + totalTickedBlocks);
|
||||||
sender.sendMessage("");
|
sender.sendMessage("");
|
||||||
|
|
||||||
summarizeTimings("Chunks", sender, entry -> {
|
summarizeTimings("Blocks", sender, entry -> {
|
||||||
int count = profiler.getBlocksOfId(entry.getKey());
|
int count = profiler.getBlocksOfId(entry.getKey());
|
||||||
String time = NumberUtils.getAsMillis(entry.getValue());
|
String time = NumberUtils.getAsMillis(entry.getValue());
|
||||||
|
|
||||||
@ -70,7 +72,7 @@ class PerformanceSummary {
|
|||||||
|
|
||||||
sender.sendMessage("");
|
sender.sendMessage("");
|
||||||
|
|
||||||
summarizeTimings("Blocks", sender, entry -> {
|
summarizeTimings("Chunks", sender, entry -> {
|
||||||
int count = profiler.getBlocksInChunk(entry.getKey());
|
int count = profiler.getBlocksInChunk(entry.getKey());
|
||||||
String time = NumberUtils.getAsMillis(entry.getValue());
|
String time = NumberUtils.getAsMillis(entry.getValue());
|
||||||
|
|
||||||
@ -93,7 +95,7 @@ class PerformanceSummary {
|
|||||||
|
|
||||||
for (Map.Entry<String, Long> entry : results) {
|
for (Map.Entry<String, Long> entry : results) {
|
||||||
if (entry.getValue() > VISIBILITY_THRESHOLD) {
|
if (entry.getValue() > VISIBILITY_THRESHOLD) {
|
||||||
builder.append("\n&e").append(formatter.apply(entry));
|
builder.append("\n").append(ChatColor.YELLOW).append(formatter.apply(entry));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
hidden++;
|
hidden++;
|
||||||
@ -108,26 +110,28 @@ class PerformanceSummary {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int hidden = 0;
|
int hidden = 0;
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
sender.sendMessage(ChatColor.GOLD + prefix);
|
builder.append(ChatColor.GOLD + prefix);
|
||||||
|
|
||||||
for (Map.Entry<String, Long> entry : results) {
|
for (Map.Entry<String, Long> entry : results) {
|
||||||
if (entry.getValue() > VISIBILITY_THRESHOLD) {
|
if (entry.getValue() > VISIBILITY_THRESHOLD) {
|
||||||
sender.sendMessage(" " + ChatColor.stripColor(formatter.apply(entry)));
|
builder.append(" ");
|
||||||
|
builder.append(ChatColor.stripColor(formatter.apply(entry)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
hidden++;
|
hidden++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage("+ " + hidden + " more");
|
builder.append("\n+ ");
|
||||||
|
builder.append(hidden);
|
||||||
|
builder.append(" more...");
|
||||||
|
sender.sendMessage(builder.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPerformanceRating() {
|
private String getPerformanceRating() {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
float percentage = Math.round(((((totalElapsedTime / 1000000.0) * 100.0F) / MAX_TICK_DURATION) * 100.0F) / 100.0F);
|
|
||||||
builder.append(NumberUtils.getColorFromPercentage(100 - Math.min(percentage, 100)));
|
builder.append(NumberUtils.getColorFromPercentage(100 - Math.min(percentage, 100)));
|
||||||
|
|
||||||
int rest = 20;
|
int rest = 20;
|
||||||
|
@ -28,11 +28,11 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
|||||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link SlimefunProfiler} works closely to the {@link TickerTask} and is responsible for
|
* The {@link SlimefunProfiler} works closely to the {@link TickerTask} and is
|
||||||
* monitoring that task.
|
* responsible for monitoring that task.
|
||||||
* It collects timings data for any ticked {@link Block} and the corresponding {@link SlimefunItem}.
|
* It collects timings data for any ticked {@link Block} and the corresponding {@link SlimefunItem}.
|
||||||
* This allows developers to identify laggy {@link SlimefunItem SlimefunItems} or {@link SlimefunAddon SlimefunAddons}.
|
* This allows developers to identify laggy {@link SlimefunItem SlimefunItems} or {@link SlimefunAddon SlimefunAddons}.
|
||||||
* But it also enabled Server Admins to locate lag-inducing areas on the {@link Server}.
|
* But it also enables Server Admins to locate lag-inducing areas on the {@link Server}.
|
||||||
*
|
*
|
||||||
* @author TheBusyBiscuit
|
* @author TheBusyBiscuit
|
||||||
*
|
*
|
||||||
@ -151,6 +151,8 @@ public class SlimefunProfiler {
|
|||||||
* The {@link CommandSender} who shall receive this summary.
|
* The {@link CommandSender} who shall receive this summary.
|
||||||
*/
|
*/
|
||||||
public void requestSummary(CommandSender sender) {
|
public void requestSummary(CommandSender sender) {
|
||||||
|
Validate.notNull(sender, "Cannot request a summary for null");
|
||||||
|
|
||||||
requests.add(sender);
|
requests.add(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,13 +208,19 @@ public class SlimefunProfiler {
|
|||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected float getPercentageOfTick() {
|
||||||
|
float millis = totalElapsedTime / 1000000.0F;
|
||||||
|
float fraction = (millis * 100.0F) / PerformanceSummary.MAX_TICK_DURATION;
|
||||||
|
return Math.round((fraction * 100.0F) / 100.0F);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns the current {@link PerformanceRating}.
|
* This method returns the current {@link PerformanceRating}.
|
||||||
*
|
*
|
||||||
* @return The current performance grade
|
* @return The current performance grade
|
||||||
*/
|
*/
|
||||||
public PerformanceRating getPerformance() {
|
public PerformanceRating getPerformance() {
|
||||||
float percentage = Math.round(((((totalElapsedTime / 1000000.0) * 100.0F) / PerformanceSummary.MAX_TICK_DURATION) * 100.0F) / 100.0F);
|
float percentage = getPercentageOfTick();
|
||||||
|
|
||||||
for (PerformanceRating rating : PerformanceRating.values()) {
|
for (PerformanceRating rating : PerformanceRating.values()) {
|
||||||
if (rating.test(percentage)) {
|
if (rating.test(percentage)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user