-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add performance monitoring for event listeners and tasks (#124)
This commit introduces a performance monitoring feature to Project Poseidon, aimed at enhancing server administration capabilities by tracking the execution times of synchronous event listeners and server tasks. This update provides tools for real-time performance insights and statistical reporting, facilitating the identification and management of performance issues. Key Features: - Real-time monitoring and alerts for performance thresholds. - Configurable settings to tailor monitoring to specific server needs. - Detailed performance statistics available at server shutdown. Files Modified: - `PoseidonConfig.java`: Added configuration options for monitoring. - `PerformanceStatistic.java`: New class for handling performance data. - `PoseidonServer.java`, `MinecraftServer.java`, `CraftServer.java`, `CraftScheduler.java`: Integrated performance monitoring. - `SimplePluginManager.java`: Updated to monitor event handling performance.
- Loading branch information
Showing
7 changed files
with
294 additions
and
27 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
50 changes: 50 additions & 0 deletions
50
src/main/java/com/legacyminecraft/poseidon/utility/PerformanceStatistic.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,50 @@ | ||
package com.legacyminecraft.poseidon.utility; | ||
|
||
public class PerformanceStatistic { | ||
private long minTime = Long.MAX_VALUE; | ||
private long maxTime = 0; | ||
private long totalTime = 0; | ||
private long count = 0; | ||
|
||
// Update the stats with a new execution time | ||
public void update(long duration) { | ||
if (duration < minTime) { | ||
minTime = duration; | ||
} | ||
if (duration > maxTime) { | ||
maxTime = duration; | ||
} | ||
totalTime += duration; | ||
count++; | ||
} | ||
|
||
// Retrieve the average execution time | ||
long getAverageTime() { | ||
return count > 0 ? totalTime / count : 0; | ||
} | ||
|
||
// Print the statistics for this listener | ||
public String printStats() { | ||
return String.format("Called: %d times, Min: %dms, Avg: %dms, Max: %dms", count, minTime, getAverageTime(), maxTime); | ||
} | ||
|
||
public long getEventCount() { | ||
return count; | ||
} | ||
|
||
public long getTotalExecutionTime() { | ||
return totalTime; | ||
} | ||
|
||
public long getAverageExecutionTime() { | ||
return getAverageTime(); | ||
} | ||
|
||
public long getMinExecutionTime() { | ||
return minTime; | ||
} | ||
|
||
public long getMaxExecutionTime() { | ||
return maxTime; | ||
} | ||
} |
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
Oops, something went wrong.