Accurate computation of elapsed time
@@ -126,11 +126,11 @@ public class StatisticsCollector implements IFloodlightModule, IStatisticsServic
txBytesCounted = pse.getTxBytes().subtract(spb.getPriorByteValueTx());
}
long speed = getSpeed(npt);
- long timeDifSec = ((System.nanoTime() - spb.getStartTime_ns()) / 1000000) / MILLIS_PER_SEC;
+ double timeDifSec = ((System.nanoTime() - spb.getStartTime_ns()) * 1.0 / 1000000) / MILLIS_PER_SEC;
portStats.put(npt, SwitchPortBandwidth.of(npt.getNodeId(), npt.getPortId(),
U64.ofRaw(speed),
- U64.ofRaw((rxBytesCounted.getValue() * BITS_PER_BYTE) / timeDifSec),
- U64.ofRaw((txBytesCounted.getValue() * BITS_PER_BYTE) / timeDifSec),
+ U64.ofRaw(Math.round((rxBytesCounted.getValue() * BITS_PER_BYTE) / timeDifSec)),
+ U64.ofRaw(Math.round((txBytesCounted.getValue() * BITS_PER_BYTE) / timeDifSec)),
pse.getRxBytes(), pse.getTxBytes())
);
