Add memory logs, log when removed on disconnect

This commit is contained in:
Manfred Karrer 2016-06-10 21:21:10 +02:00
parent fc9f904da0
commit f6d595653f
3 changed files with 25 additions and 6 deletions

View File

@ -20,15 +20,24 @@ package io.bitsquare.common.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class Profiler {
public class Profiler {
private static final Logger log = LoggerFactory.getLogger(Profiler.class);
public static void printSystemLoad(Logger log) {
String msg = printSystemLoadString();
log.info(msg);
}
public static String printSystemLoadString() {
long used = getUsedMemory();
return "System load (nr. threads/used memory (MB)): " + Thread.activeCount() + "/" + used;
}
public static long getUsedMemory() {
Runtime runtime = Runtime.getRuntime();
long free = runtime.freeMemory() / 1024 / 1024;
long total = runtime.totalMemory() / 1024 / 1024;
long used = total - free;
log.info("System load (nr. threads/used memory (MB)): " + Thread.activeCount() + "/" + used);
return total - free;
}
}

View File

@ -18,6 +18,7 @@
package io.bitsquare.gui.main.offer.offerbook;
import io.bitsquare.app.DevFlags;
import io.bitsquare.common.util.Profiler;
import io.bitsquare.trade.TradeManager;
import io.bitsquare.trade.offer.Offer;
import io.bitsquare.trade.offer.OfferBookService;
@ -63,7 +64,7 @@ public class OfferBook {
offerBookListItems.add(offerBookListItem);
if (DevFlags.STRESS_TEST_MODE)
System.err.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " - Offer added: Nr. of offers = " + offerBookListItems.size());
System.err.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " - Offer added: Nr. of offers = " + offerBookListItems.size() + " / Memory(MB): " + Profiler.getUsedMemory());
}
}
@ -83,7 +84,7 @@ public class OfferBook {
offerBookListItems.remove(item);
if (DevFlags.STRESS_TEST_MODE)
System.err.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " - Offer removed: Nr. of offers = " + offerBookListItems.size());
System.err.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " - Offer removed: Nr. of offers = " + offerBookListItems.size() + " / Memory(MB): " + Profiler.getUsedMemory());
}
}
}
@ -107,7 +108,7 @@ public class OfferBook {
offerBookListItems.addAll(list);
if (DevFlags.STRESS_TEST_MODE)
System.err.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " - Offer filled: Nr. of offers = " + offerBookListItems.size());
System.err.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " - Offer filled: Nr. of offers = " + offerBookListItems.size() + " / Memory(MB): " + Profiler.getUsedMemory());
log.debug("offerBookListItems " + offerBookListItems.size());
}

View File

@ -1,6 +1,7 @@
package io.bitsquare.p2p.storage;
import com.google.common.annotations.VisibleForTesting;
import io.bitsquare.app.DevFlags;
import io.bitsquare.app.Log;
import io.bitsquare.app.Version;
import io.bitsquare.common.Timer;
@ -9,6 +10,7 @@ import io.bitsquare.common.crypto.CryptoException;
import io.bitsquare.common.crypto.Hash;
import io.bitsquare.common.crypto.Sig;
import io.bitsquare.common.persistance.Persistable;
import io.bitsquare.common.util.Profiler;
import io.bitsquare.common.wire.Payload;
import io.bitsquare.p2p.Message;
import io.bitsquare.p2p.NodeAddress;
@ -32,6 +34,7 @@ import java.io.File;
import java.io.Serializable;
import java.security.KeyPair;
import java.security.PublicKey;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
@ -159,6 +162,12 @@ public class P2PDataStorage implements MessageListener, ConnectionListener {
if (containsKey) {
log.info("We remove the data as the data owner got disconnected with " +
"closeConnectionReason=" + closeConnectionReason);
if (DevFlags.STRESS_TEST_MODE)
System.err.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) +
" - We remove the data as the data owner got disconnected with " +
"closeConnectionReason=" + closeConnectionReason +
" / isIntended=" + closeConnectionReason.isIntended +
" / Memory(MB): " + Profiler.getUsedMemory());
doRemoveProtectedExpirableData(protectedData, hashOfPayload);
} else {
log.debug("Remove data ignored as we don't have an entry for that data.");