Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

New ticker and NetworkManager was updated #381

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class FullServerTickHandler extends TimingHandler {
}

@Override
public void startTiming() {
if (TimingsManager.needsFullReset) {
TimingsManager.resetTimings();
} else if (TimingsManager.needsRecheckEnabled) {
TimingsManager.recheckEnabled();
public Timing startTiming() {
if (needsFullReset) {
resetTimings();
} else if (needsRecheckEnabled) {
recheckEnabled();
}
super.startTiming();
return super.startTiming();
}

@Override
Expand All @@ -48,7 +48,7 @@ public void stopTiming() {
}

long start = System.nanoTime();
TimingsManager.tick();
tick();
long diff = System.nanoTime() - start;
CURRENT = TIMINGS_TICK;
TIMINGS_TICK.addDiff(diff);
Expand All @@ -68,8 +68,8 @@ public void stopTiming() {
minuteData.reset();
}
if (TimingHistory.timedTicks % Timings.getHistoryInterval() == 0) {
TimingsManager.HISTORY.add(new TimingHistory());
TimingsManager.resetTimings();
HISTORY.add(new TimingHistory());
resetTimings();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
package co.aikar.timings;

public final class NullTimingHandler implements Timing {
@Override
public void startTiming() {
public static final Timing NULL = new NullTimingHandler();

@Override
public Timing startTiming() {
return this;
}

@Override
Expand All @@ -35,8 +37,8 @@ public void stopTiming() {
}

@Override
public void startTimingIfSync() {

public Timing startTimingIfSync() {
return this;
}

@Override
Expand All @@ -54,6 +56,11 @@ public TimingHandler getTimingHandler() {
return null;
}

@Override
public double getAverage() {
return 0;
}

@Override
public void close() {

Expand Down
6 changes: 4 additions & 2 deletions NachoSpigot-API/src/main/java/co/aikar/timings/Timing.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface Timing extends AutoCloseable {
/**
* Starts timing the execution until {@link #stopTiming()} is called.
*/
public void startTiming();
public Timing startTiming();

/**
* <p>Stops timing and records the data. Propagates the data up to group handlers.</p>
Expand All @@ -44,7 +44,7 @@ public interface Timing extends AutoCloseable {
*
* But only if we are on the primary thread.
*/
public void startTimingIfSync();
public Timing startTimingIfSync();

/**
* <p>Stops timing and records the data. Propagates the data up to group handlers.</p>
Expand All @@ -67,6 +67,8 @@ public interface Timing extends AutoCloseable {
*/
TimingHandler getTimingHandler();

double getAverage();

@Override
void close();
}
29 changes: 21 additions & 8 deletions NachoSpigot-API/src/main/java/co/aikar/timings/TimingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/
package co.aikar.timings;

import co.aikar.util.LoadingIntMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import org.bukkit.Bukkit;
import co.aikar.util.LoadingIntMap;

import java.util.logging.Level;

Expand All @@ -42,6 +42,8 @@ class TimingHandler implements Timing {
final TimingData record;
final TimingHandler groupHandler;

public int count;
public int total;
long start = 0;
int timingDepth = 0;
boolean added;
Expand Down Expand Up @@ -83,10 +85,11 @@ void processTick(boolean violated) {
}

@Override
public void startTimingIfSync() {
public Timing startTimingIfSync() {
if (Bukkit.isPrimaryThread()) {
startTiming();
}
return this;
}

@Override
Expand All @@ -96,12 +99,13 @@ public void stopTimingIfSync() {
}
}

public void startTiming() {
public Timing startTiming() {
if (enabled && ++timingDepth == 1) {
start = System.nanoTime();
parent = TimingsManager.CURRENT;
TimingsManager.CURRENT = this;
}
return this;
}

public void stopTiming() {
Expand All @@ -112,12 +116,9 @@ public void stopTiming() {
start = 0;
return;
}
try
{
try {
addDiff(System.nanoTime() - start);
}
catch (ArrayIndexOutOfBoundsException ex)
{
} catch (ArrayIndexOutOfBoundsException ex) {
ex.printStackTrace();
}
start = 0;
Expand All @@ -132,6 +133,12 @@ public void abort() {
}

void addDiff(long diff) {
total += diff;
count++;
if (count > 20) {
count--;
total -= ((double) total / (double) count);
}
if (TimingsManager.CURRENT == this) {
TimingsManager.CURRENT = parent;
if (parent != null) {
Expand Down Expand Up @@ -172,6 +179,12 @@ public TimingHandler getTimingHandler() {
return this;
}

@Override
public double getAverage() {
if (count < 20) return 0;
return total / count;
}

@Override
public boolean equals(Object o) {
return (this == o);
Expand Down
18 changes: 7 additions & 11 deletions NachoSpigot-API/src/main/java/co/aikar/timings/TimingHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package co.aikar.timings;

import co.aikar.util.LoadingMap;
import co.aikar.util.MRUMapCache;
import com.google.common.base.Function;
import com.google.common.collect.Sets;
import org.bukkit.Bukkit;
Expand All @@ -33,15 +35,9 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import co.aikar.util.LoadingMap;
import co.aikar.util.MRUMapCache;

import java.lang.management.ManagementFactory;
import java.util.Collection;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

import static co.aikar.timings.TimingsManager.FULL_SERVER_TICK;
import static co.aikar.timings.TimingsManager.MINUTE_REPORTS;
Expand Down Expand Up @@ -202,10 +198,10 @@ static class MinuteReport {

final TicksRecord ticksRecord = new TicksRecord();
final PingRecord pingRecord = new PingRecord();
final TimingData fst = TimingsManager.FULL_SERVER_TICK.minuteData.clone();
final TimingData fst = FULL_SERVER_TICK.minuteData.clone();
final double tps = 1E9 / ( System.nanoTime() - lastMinuteTime ) * ticksRecord.timed;
final double usedMemory = TimingsManager.FULL_SERVER_TICK.avgUsedMemory;
final double freeMemory = TimingsManager.FULL_SERVER_TICK.avgFreeMemory;
final double usedMemory = FULL_SERVER_TICK.avgUsedMemory;
final double freeMemory = FULL_SERVER_TICK.avgFreeMemory;
final double loadAvg = ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage();

public List export() {
Expand Down Expand Up @@ -235,7 +231,7 @@ static class TicksRecord {
final long activatedEntity;

TicksRecord() {
timed = timedTicks - (TimingsManager.MINUTE_REPORTS.size() * 1200);
timed = timedTicks - (MINUTE_REPORTS.size() * 1200);
player = playerTicks;
entity = entityTicks;
tileEntity = tileEntityTicks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/
package co.aikar.timings;

import com.google.common.base.Function;
import co.aikar.util.LoadingMap;
import co.aikar.util.MRUMapCache;
import com.google.common.base.Function;

import java.util.ArrayDeque;
import java.util.Map;
Expand Down
Loading