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

@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package ru.windcorp.progressia.server; package ru.windcorp.progressia.server;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -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");
@ -151,6 +152,10 @@ public class TickerCoordinator {
public double getTPS() { public double getTPS() {
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();
@ -163,6 +168,10 @@ public class TickerCoordinator {
tickStart = System.currentTimeMillis(); tickStart = System.currentTimeMillis();
} }
private void onTickEnd() {
ticks++;
}
/* /*
* runOneTick & Friends * runOneTick & Friends
@ -182,6 +191,8 @@ public class TickerCoordinator {
logger.debug("Pass complete"); logger.debug("Pass complete");
passes++; passes++;
} }
onTickEnd();
logger.debug("Tick complete; run {} passes", passes); logger.debug("Tick complete; run {} passes", passes);
@ -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");
} }
} }