Skip to content

Commit 4bd4dd4

Browse files
Merge pull request #25 from Slimefun/feature/average-timing-chart
Add average timing chart
2 parents b8a0590 + e688697 commit 4bd4dd4

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<dependency>
3131
<groupId>com.github.TheBusyBiscuit</groupId>
3232
<artifactId>Slimefun4</artifactId>
33-
<version>RC-22</version>
33+
<version>326a431151</version>
3434
<scope>provided</scope>
3535
</dependency>
3636

src/main/java/dev/walshy/sfmetrics/MetricsModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import javax.annotation.ParametersAreNonnullByDefault;
77

8+
import dev.walshy.sfmetrics.charts.AverageTimingsChart;
89
import dev.walshy.sfmetrics.charts.DisabledItemsChart;
910
import org.bstats.bukkit.Metrics;
1011
import org.bstats.charts.CustomChart;
@@ -67,6 +68,7 @@ public static void start() {
6768
addChart(metrics, IntegrationsChart::new);
6869
addChart(metrics, CSCoreLibChart::new);
6970
addChart(metrics, DisabledItemsChart::new);
71+
addChart(metrics, AverageTimingsChart::new);
7072

7173
SlimefunPlugin.instance().getLogger().log(Level.INFO, "Now running MetricsModule build #{0}", VERSION);
7274
SlimefunPlugin.instance().getLogger().log(Level.INFO, "with a total of {0}/{1} chart(s)!", new Object[] { enabledCharts, totalCharts });
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package dev.walshy.sfmetrics.charts;
2+
3+
import dev.walshy.sfmetrics.VersionDependentChart;
4+
import io.github.thebusybiscuit.slimefun4.api.SlimefunBranch;
5+
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
6+
import org.bstats.charts.SimplePie;
7+
import org.bstats.json.JsonObjectBuilder;
8+
9+
import javax.annotation.Nonnull;
10+
11+
public class AverageTimingsChart extends SimplePie implements VersionDependentChart {
12+
13+
// If there's more than 15 values bStats will create an "Other" section (which cannot be viewed)
14+
// So we make sure there's 15 or less (currently, 13 values)
15+
public AverageTimingsChart() {
16+
super("average_timings", () -> {
17+
long averageMsTiming = SlimefunPlugin.getProfiler().getAndResetAverageTimings();
18+
19+
// 10ms diffs
20+
if (averageMsTiming <= 10) {
21+
return "0-10";
22+
} else if (averageMsTiming <= 20) {
23+
return "11-20";
24+
} else if (averageMsTiming <= 30) {
25+
return "21-30";
26+
} else if (averageMsTiming <= 40) {
27+
return "31-40";
28+
} else if (averageMsTiming <= 50) {
29+
return "41-50";
30+
31+
// 25ms diffs
32+
} else if (averageMsTiming <= 75) {
33+
return "51-75";
34+
} else if (averageMsTiming <= 100) {
35+
return "76-100";
36+
} else if (averageMsTiming <= 125) {
37+
return "36-125";
38+
} else if (averageMsTiming <= 150) {
39+
return "41-150";
40+
} else if (averageMsTiming <= 175) {
41+
return "46-175";
42+
} else if (averageMsTiming <= 200) {
43+
return "178-200";
44+
45+
// 50ms
46+
} else if (averageMsTiming <= 250) {
47+
return "201-250";
48+
49+
// Other
50+
} else {
51+
return "> 250";
52+
}
53+
});
54+
}
55+
56+
@Nonnull
57+
@Override
58+
public String getName() {
59+
return "Average SF Tick (ms)";
60+
}
61+
62+
@Nonnull
63+
@Override
64+
public JsonObjectBuilder.JsonObject getDataSample() throws Exception {
65+
return getChartData();
66+
}
67+
68+
@Override
69+
public boolean isCompatible(@Nonnull SlimefunBranch branch, int build) {
70+
if (branch == SlimefunBranch.STABLE && build >= 25) {
71+
return true;
72+
} else {
73+
return branch == SlimefunBranch.DEVELOPMENT && build >= 933;
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)