use of com.biglybt.core.dht.transport.DHTTransportStats in project BiglyBT by BiglySoftware.
the class LongTermStatsImpl method sessionStart.
private void sessionStart() {
OverallStatsImpl stats = (OverallStatsImpl) StatsFactory.getStats();
synchronized (this) {
if (closing) {
return;
}
boolean enabled = COConfigurationManager.getBooleanParameter("long.term.stats.enable");
if (active || !enabled) {
return;
}
active = true;
long[] snap = stats.getLastSnapshot();
ss_d_received = gm_stats.getTotalDataBytesReceived();
ss_p_received = gm_stats.getTotalProtocolBytesReceived();
ss_d_sent = gm_stats.getTotalDataBytesSent();
ss_p_sent = gm_stats.getTotalProtocolBytesSent();
ss_dht_sent = 0;
ss_dht_received = 0;
if (core.isStarted()) {
DHT[] dhts = getDHTs();
if (dhts != null) {
for (DHT dht : dhts) {
DHTTransportStats dht_stats = dht.getTransport().getStats();
ss_dht_sent += dht_stats.getBytesSent();
ss_dht_received += dht_stats.getBytesReceived();
}
}
}
st_p_sent = snap[0] + (ss_p_sent - snap[6]);
st_d_sent = snap[1] + (ss_d_sent - snap[7]);
st_p_received = snap[2] + (ss_p_received - snap[8]);
st_d_received = snap[3] + (ss_d_received - snap[9]);
st_dht_sent = snap[4] + (ss_dht_sent - snap[10]);
st_dht_received = snap[5] + (ss_dht_received - snap[11]);
write(RT_SESSION_START, new long[] { st_p_sent, st_d_sent, st_p_received, st_d_received, st_dht_sent, st_dht_received });
if (event == null) {
// should always be null but hey ho
event = SimpleTimer.addPeriodicEvent("LongTermStats", MIN_IN_MILLIS, new TimerEventPerformer() {
@Override
public void perform(TimerEvent event) {
if (destroyed) {
event.cancel();
return;
}
updateStats();
}
});
}
}
}
use of com.biglybt.core.dht.transport.DHTTransportStats in project BiglyBT by BiglySoftware.
the class OverallStatsImpl method updateStats.
private void updateStats(boolean force) {
try {
this_mon.enter();
long current_time = SystemTime.getCurrentTime() / 1000;
if (current_time < lastUptime) {
// time went backwards
lastUptime = current_time;
return;
}
long current_total_d_received = gm_stats.getTotalDataBytesReceived();
long current_total_p_received = gm_stats.getTotalProtocolBytesReceived();
long current_total_d_sent = gm_stats.getTotalDataBytesSent();
long current_total_p_sent = gm_stats.getTotalProtocolBytesSent();
long current_total_received = current_total_d_received + current_total_p_received;
long current_total_sent = current_total_d_sent + current_total_p_sent;
// overall totals
totalDownloaded += current_total_received - lastDownloaded;
lastDownloaded = current_total_received;
if (totalDownloaded < 0)
totalDownloaded = 0;
totalUploaded += current_total_sent - lastUploaded;
lastUploaded = current_total_sent;
if (totalUploaded < 0)
totalUploaded = 0;
// split totals
totalDataDownloaded += current_total_d_received - lastDataDownloaded;
lastDataDownloaded = current_total_d_received;
if (totalDataDownloaded < 0)
totalDataDownloaded = 0;
totalProtocolDownloaded += current_total_p_received - lastProtocolDownloaded;
lastProtocolDownloaded = current_total_p_received;
if (totalProtocolDownloaded < 0)
totalProtocolDownloaded = 0;
totalDataUploaded += current_total_d_sent - lastDataUploaded;
lastDataUploaded = current_total_d_sent;
if (totalDataUploaded < 0)
totalDataUploaded = 0;
totalProtocolUploaded += current_total_p_sent - lastProtocolUploaded;
lastProtocolUploaded = current_total_p_sent;
if (totalProtocolUploaded < 0)
totalProtocolUploaded = 0;
if (dhts == null) {
try {
PluginManager pm = core.getPluginManager();
if (pm.isInitialized()) {
PluginInterface dht_pi = pm.getPluginInterfaceByClass(DHTPlugin.class);
if (dht_pi == null) {
dhts = new DHT[0];
} else {
DHTPlugin plugin = (DHTPlugin) dht_pi.getPlugin();
if (!plugin.isInitialising()) {
if (plugin.isEnabled()) {
dhts = ((DHTPlugin) dht_pi.getPlugin()).getDHTs();
} else {
dhts = new DHT[0];
}
}
}
}
} catch (Throwable e) {
dhts = new DHT[0];
}
}
long current_total_dht_up = 0;
long current_total_dht_down = 0;
if (dhts != null) {
for (DHT dht : dhts) {
DHTTransportStats stats = dht.getTransport().getStats();
current_total_dht_up += stats.getBytesSent();
current_total_dht_down += stats.getBytesReceived();
}
}
totalDHTUploaded += current_total_dht_up - lastDHTUploaded;
lastDHTUploaded = current_total_dht_up;
if (totalDHTUploaded < 0)
totalDHTUploaded = 0;
totalDHTDownloaded += current_total_dht_down - lastDHTDownloaded;
lastDHTDownloaded = current_total_dht_down;
if (totalDHTDownloaded < 0)
totalDHTDownloaded = 0;
// TIME
long delta = current_time - lastUptime;
if (delta > 100 || delta < 0) {
// make sure the time diff isn't borked
lastUptime = current_time;
return;
}
if (totalUptime < 0)
totalUptime = 0;
totalUptime += delta;
lastUptime = current_time;
lastSnapshot = new long[] { totalProtocolUploaded, totalDataUploaded, totalProtocolDownloaded, totalDataDownloaded, totalDHTUploaded, totalDHTDownloaded, current_total_p_sent, current_total_d_sent, current_total_p_received, current_total_d_received, current_total_dht_up, current_total_dht_down };
HashMap overallMap = new HashMap();
overallMap.put("downloaded", new Long(totalDownloaded));
overallMap.put("uploaded", new Long(totalUploaded));
overallMap.put("uptime", new Long(totalUptime));
overallMap.put("mark_time", new Long(markTime));
overallMap.put("mark_downloaded", new Long(markTotalDownloaded));
overallMap.put("mark_uploaded", new Long(markTotalUploaded));
overallMap.put("mark_uptime", new Long(markTotalUptime));
overallMap.put("dht_down", new Long(totalDHTDownloaded));
overallMap.put("dht_up", new Long(totalDHTUploaded));
overallMap.put("p_uploaded", new Long(totalProtocolUploaded));
overallMap.put("d_uploaded", new Long(totalDataUploaded));
overallMap.put("p_downloaded", new Long(totalProtocolDownloaded));
overallMap.put("d_downloaded", new Long(totalDataDownloaded));
Map map = new HashMap();
map.put("all", overallMap);
tick_count++;
if (force || tick_count % SAVE_TICKS == 0) {
save(map);
}
} finally {
this_mon.exit();
}
}
use of com.biglybt.core.dht.transport.DHTTransportStats in project BiglyBT by BiglySoftware.
the class DHTView method refreshTransportDetails.
private void refreshTransportDetails() {
DHTTransportStats transportStats = dht.getTransport().getStats();
lblReceivedBytes.setText(DisplayFormatters.formatByteCountToKiBEtc(transportStats.getBytesReceived()));
lblSentBytes.setText(DisplayFormatters.formatByteCountToKiBEtc(transportStats.getBytesSent()));
lblReceivedPackets.setText("" + transportStats.getPacketsReceived());
lblSentPackets.setText("" + transportStats.getPacketsSent());
}
Aggregations