Added a serverside uptime tick counter

This commit is contained in:
OLEGSHA 2021-04-09 20:34:47 +03:00
parent c49fdfa5ff
commit 32851b8fb0
Signed by: OLEGSHA
GPG Key ID: E57A4B08D64AFF7A
2 changed files with 25 additions and 2 deletions

View File

@ -183,6 +183,18 @@ public class Server {
return this.serverThread.getTicker().getTPS(); return this.serverThread.getTicker().getTPS();
} }
/**
* Returns the amount of ticks performed since the server has started. This
* value resets on shutdowns. The counter is incremented at the end of a
* tick.
*
* @return the number of times the world has finished a tick since the
* server has started.
*/
public long getUptimeTicks() {
return this.serverThread.getTicker().getUptimeTicks();
}
/** /**
* Returns the {@link WorldAccessor} object for this server. Use the * Returns the {@link WorldAccessor} object for this server. Use the
* provided accessor to * provided accessor to

View File

@ -82,6 +82,7 @@ public class TickerCoordinator {
private boolean isTickStartSet = false; private boolean isTickStartSet = false;
private long tickStart = -1; private long tickStart = -1;
private double tickLength = 1.0 / 20; // Do something about it private double tickLength = 1.0 / 20; // Do something about it
private long ticks = 0;
private final Logger logger = LogManager.getLogger("Ticker Coordinator"); private final Logger logger = LogManager.getLogger("Ticker Coordinator");
@ -152,6 +153,10 @@ public class TickerCoordinator {
return 1 / tickLength; return 1 / tickLength;
} }
public long getUptimeTicks() {
return ticks;
}
private void onTickStart() { private void onTickStart() {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
@ -164,6 +169,10 @@ public class TickerCoordinator {
tickStart = System.currentTimeMillis(); tickStart = System.currentTimeMillis();
} }
private void onTickEnd() {
ticks++;
}
/* /*
* runOneTick & Friends * runOneTick & Friends
*/ */
@ -183,6 +192,8 @@ public class TickerCoordinator {
passes++; passes++;
} }
onTickEnd();
logger.debug("Tick complete; run {} passes", passes); logger.debug("Tick complete; run {} passes", passes);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -191,7 +202,7 @@ public class TickerCoordinator {
// ...or almost silently // ...or almost silently
logger.debug("Tick interrupted. WTF?"); logger.debug("Tick interrupted. WTF?");
} catch (Exception e) { } catch (Exception e) {
crash(e, "Coordinator"); throw CrashReports.report(e, "Coordinator");
} }
} }