Modified MemoryControl.main() test to properly end for better results

displaying.
pull/34/head
luc 9 years ago
parent 020630efd8
commit 70595d05d0

@ -27,6 +27,8 @@ package net.yacy.kelondro.util;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import net.yacy.cora.util.ConcurrentLog;
/** /**
* Use this to get information about memory usage or try to free some memory * Use this to get information about memory usage or try to free some memory
*/ */
@ -183,33 +185,54 @@ public class MemoryControl {
* main * main
* @param args use 'force' to request by force, use 'std' / 'gen' to specify strategy * @param args use 'force' to request by force, use 'std' / 'gen' to specify strategy
*/ */
public static void main(final String[] args) { public static void main(final String[] args) {
// try this with different strategy and compare results long beginTime = System.nanoTime();
final int mb = 1024 * 1024; int i = 0;
boolean force = false; try {
for (final String arg : args) { // try this with different strategy and compare results
if (arg.equals("force")) force = true; final int mb = 1024 * 1024;
if (arg.equalsIgnoreCase("gen")) usingStandardStrategy = false; boolean force = false;
if (arg.equalsIgnoreCase("std")) usingStandardStrategy = true; for (final String arg : args) {
} if (arg.equals("force"))
System.out.println("vm: " + System.getProperty("java.vm.version")); force = true;
System.out.println("computed max = " + (maxMemory() / mb) + " mb"); if (arg.equalsIgnoreCase("gen"))
System.out.println("using " + getStrategyName()); usingStandardStrategy = false;
final byte[][] x = new byte[100000][]; if (arg.equalsIgnoreCase("std"))
usingStandardStrategy = true;
for (int i = 0; i < 100000; i++) { }
if (request(mb, force)) System.out.println("vm: " + System.getProperty("java.vm.version"));
{ System.out.println("computed max = " + (maxMemory() / mb) + " mb");
x[i] = new byte[mb]; System.out.println("using " + getStrategyName());
System.out.println("used = " + i + " / " + (used() /mb) + if(force) {
", total = " + (total() / mb) + System.out.println("forcing garbage collector when requesting");
", free = " + (free() / mb) + } else {
", max = " + (maxMemory() / mb) + System.out.println("not forcing garbage collector when requesting");
", avail = " + (available() / mb) + }
(usingStandardStrategy? ", averageGC = " + ((StandardMemoryStrategy)getStrategy()).getAverageGCFree() : "")); final byte[][] x = new byte[100000][];
} else System.exit(0);
} for (i = 0; i < 100000; i++) {
if (request(mb, force)) {
x[i] = new byte[mb];
System.out
.println("used = " + i + " / " + (used() / mb) + ", total = " + (total() / mb) + ", free = "
+ (free() / mb) + ", max = " + (maxMemory() / mb) + ", avail = "
+ (available() / mb)
+ (usingStandardStrategy
? ", averageGC = "
+ ((StandardMemoryStrategy) getStrategy()).getAverageGCFree()
: ""));
} else {
System.out.println("No more memory available!");
break;
}
}
} finally {
long time = System.nanoTime() - beginTime;
System.out.println("Test run in " + time / 1000000 + " ms");
ConcurrentLog.shutdown();
System.out.println("Succesfull requests : " + i);
}
} }
} }

Loading…
Cancel
Save