-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from spacechunks/dev
Dev
- Loading branch information
Showing
80 changed files
with
1,868 additions
and
373 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
65 changes: 65 additions & 0 deletions
65
src/main/java/space/chunks/gamecup/dgr/launcher/profiler/ApplicationProfiler.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,65 @@ | ||
package space.chunks.gamecup.dgr.launcher.profiler; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.name.Named; | ||
import lombok.extern.log4j.Log4j2; | ||
import net.minestom.server.MinecraftServer; | ||
import net.minestom.server.event.EventListener; | ||
import net.minestom.server.event.GlobalEventHandler; | ||
import net.minestom.server.event.instance.InstanceTickEvent; | ||
import net.minestom.server.event.server.ServerTickMonitorEvent; | ||
import net.minestom.server.monitoring.BenchmarkManager; | ||
import net.minestom.server.utils.time.TimeUnit; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.time.Duration; | ||
|
||
|
||
/** | ||
* @author Nico_ND1 | ||
*/ | ||
@Log4j2 | ||
public final class ApplicationProfiler { | ||
private final ProfilerRepository profilerRepository; | ||
private final Profiler<ServerTickMonitorEvent> minecraftServerProfiler; | ||
private final ApplicationProfilerCommand command; | ||
|
||
@Inject | ||
public ApplicationProfiler( | ||
@NotNull ProfilerRepository profilerRepository, | ||
@NotNull @Named("minecraftServer") Profiler minecraftServerProfiler, | ||
@NotNull ApplicationProfilerCommand command | ||
) { | ||
this.profilerRepository = profilerRepository; | ||
this.minecraftServerProfiler = minecraftServerProfiler; | ||
this.command = command; | ||
} | ||
|
||
public void register() { | ||
/* | ||
// TODO: use to persist dirty data | ||
MinecraftServer.getSchedulerManager().buildShutdownTask(() -> { | ||
});*/ | ||
|
||
log.info("Registering application profiler"); | ||
|
||
BenchmarkManager benchmarkManager = MinecraftServer.getBenchmarkManager(); | ||
benchmarkManager.enable(Duration.of(10, TimeUnit.SECOND)); | ||
log.info("Enabled benchmark manager with a duration of 10 seconds"); | ||
|
||
GlobalEventHandler eventHandler = MinecraftServer.getGlobalEventHandler(); | ||
eventHandler.addListener(EventListener.of(ServerTickMonitorEvent.class, this.minecraftServerProfiler::feed)); | ||
|
||
eventHandler.addListener(EventListener.of(InstanceTickEvent.class, event -> { | ||
for (SessionProfiler profiler : this.profilerRepository.sessionProfilers()) { | ||
profiler.feed(event); | ||
} | ||
})); | ||
|
||
log.info("Registered event listeners for application profiler"); | ||
|
||
MinecraftServer.getCommandManager().register(this.command); | ||
log.info("Registered command for application profiler"); | ||
} | ||
|
||
} |
Oops, something went wrong.