List of usage examples for java.lang Runtime freeMemory
public native long freeMemory();
From source file:com.aestel.chemistry.openEye.fp.Fingerprinter.java
public static void main(String... args) throws IOException { long start = System.currentTimeMillis(); long iCounter = 0; // create command line Options object Options options = new Options(); Option opt = new Option("in", true, "input file [.ism,.sdf,...]"); opt.setRequired(true);//from w w w . jav a 2 s . c o m options.addOption(opt); opt = new Option("out", true, "output file .tsv or oe-supported"); opt.setRequired(true); options.addOption(opt); opt = new Option("idTag", true, "field with ID (default title)"); opt.setRequired(false); options.addOption(opt); opt = new Option("fpType", true, "fingerPrintType: maccs|linear7|linear7*4|HashLinear7*4\n" + " maccs: generate maccs keys\n" + " linear7 generate 7 bonds long linear fingerprints (210k known rest hashed)\n" + " linear7*4 linear 7 bonds if more than 4 atoms code atoms as * (5.1k known rest hashed)\n" + " HashLinear7*4: as linear7*4 but hashed to 16k"); opt.setRequired(true); options.addOption(opt); opt = new Option("format", true, "folded512|folded2048|bitList|fragList|none\n" + " folded512/2048: hex encoded 512/2048 bits\n" + " bitList: list of bitpositions\n" + " none: no fp output for use with writeCodeMap"); opt.setRequired(true); options.addOption(opt); opt = new Option("writeCodeMap", false, "Overwrite the codeMap file at the end of processing"); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } String idTag = null; if (cmd.hasOption("idTag")) idTag = cmd.getOptionValue("idTag"); String outformat = cmd.getOptionValue("format").toLowerCase().intern(); if (args.length != 0) { exitWithHelp(options); } String type = cmd.getOptionValue("fpType"); boolean updateDictionaryFile = cmd.hasOption("writeCodeMap"); boolean hashUnknownFrag = true; if (type.equals("HashLinear7*4")) hashUnknownFrag = false; if (type.equals("maccs")) hashUnknownFrag = false; if (updateDictionaryFile) hashUnknownFrag = false; Fingerprinter fprinter = createFingerprinter(type, updateDictionaryFile, hashUnknownFrag); OEMolBase mol = new OEGraphMol(); String inFile = cmd.getOptionValue("in"); String outFile = cmd.getOptionValue("out"); oemolistream ifs = new oemolistream(inFile); Runtime rt = Runtime.getRuntime(); Outputter out; if (outFile.endsWith(".txt") || outFile.endsWith(".tab")) out = new TabOutputter(fprinter.getMapper(), outFile, outformat); else out = new OEOutputter(fprinter.getMapper(), outFile, type, outformat); while (oechem.OEReadMolecule(ifs, mol)) { iCounter++; Fingerprint fp = fprinter.getFingerprint(mol); String id; if (idTag == null) id = mol.GetTitle(); else id = oechem.OEGetSDData(mol, idTag); if (iCounter % 100 == 0) System.err.print("."); if (iCounter % 4000 == 0) { System.err.printf(" %d %dsec\tt=%d f=%d u=%d m=%d tf=%d\n", iCounter, (System.currentTimeMillis() - start) / 1000, rt.totalMemory() / 1024, rt.freeMemory() / 1024, (rt.totalMemory() - rt.freeMemory()) / 1024, rt.maxMemory() / 1024, (rt.freeMemory() + (rt.maxMemory() - rt.totalMemory())) / 1024); } out.output(id, mol, fp); } System.err.printf("Fingerprinter: Read %d structures in %d sec\n", iCounter, (System.currentTimeMillis() - start) / 1000); if (updateDictionaryFile) fprinter.writeDictionary(); out.close(); fprinter.close(); }
From source file:com.yobidrive.diskmap.needles.NeedleManager.java
public static void main(String[] args) { try {/*from w w w . java2s. c om*/ BasicConfigurator.configure(); NeedleManager nw = new NeedleManager("/Users/Francois/Documents/NEEDLES", 1000000000L, 8, 10000000L, 10000000L, 0); nw.initialize(); Runtime runtime = Runtime.getRuntime(); long before = runtime.totalMemory() - runtime.freeMemory(); // Measure cache impact for (long i = 0; i < TEST_COUNT; i++) { NeedlePointer np = new NeedlePointer(); np.setNeedleOffset(i); Needle n = new Needle(); n.setKey("kjdskljsdhklgjfdklgh"); n.setData(new byte[10000]); nw.needleHeaderReadCache.put(np, n.getNeedleHeader(np)); } runtime = Runtime.getRuntime(); long after = runtime.totalMemory() - runtime.freeMemory(); System.out.println( "Usage=" + ((after - before) / TEST_COUNT) + ", total= " + ((after - before) / (1024 * 1024))); /* long counter = 0 ; int initialLogNumber = nw.getLogNumber() ; Date startDate = new Date() ; System.out.println("Start test for "+TEST_COUNT+" needles with 10K bytes data") ; while ( counter < TEST_COUNT ) { Needle needle = new Needle() ; needle.setKey("KEY_"+counter) ; VectorClock vc = new VectorClock(new Date().getTime()) ; needle.setVersion(vc) ; needle.setData(testData) ; nw.writeNewNeedle(needle) ; counter++ ; if ( counter % 10000 == 0 ) System.out.print(".") ; } long timeSpent = new Date().getTime() - startDate.getTime() ; System.out.println("\n\nProcessed creation of "+TEST_COUNT+" needles with 10K bytes data each\n"+ "\tInital log number: "+initialLogNumber+"\n"+ "\tFinal log number: "+nw.getLogNumber()+"\n"+ "\tTotal time: "+timeSpent/1000+"s\n"+ "\tThroughput: "+TEST_COUNT*testData.length/(timeSpent/1000)+" byte/s\n"+ "\t "+TEST_COUNT/(timeSpent/1000)+" needle/s") ; */ } catch (Throwable th) { th.printStackTrace(); } }
From source file:org.cloudata.core.tabletserver.ColumnCollection.java
License:asdf
public static void main(String[] args) throws Exception { /*/*from w w w. j a v a 2 s .c o m*/ Assuming 32-bit words and a 12 byte overhead per array instance, int[4,100,000][2][2][5] 4th dim. = overhead + length * sizeof(int) = 12 + 5 * 4 = 32 3rd dim. = overhead + length * (sizeof(ref) + sizeof(4th_dim)) = 12 + 2 * (4 + 32) = 84 2nd dim. = overhead + length * (sizeof(ref) + sizeof(3rd_dim)) = 12 + 2 * (4 + 84) = 188 1st dim. = overhead + length * (sizeof(ref) + sizeof(2nd_dim)) = 12 + 4,100,000 * (4 + 188) = 787,200,012 byte[]? ? = 12 + ((length + 3)/8) * 8 + 4 byte? 0 ~ 4 12 + 4 ? ??? 8 ? : 0 ~ 4: 16, 5 ~ 12: 24, 13 ~ 20: 32 ? Text? ? header 4byte, byte[] ? 4byte, int length 4byte, length? ? 4 byte = 16 + len(byte[]) */ //Cell.Key, Row.Key: 16byte + byte[] //ColumnValue: 16 + rowKey, columnKey, value //ColumnCollection: ColumnValue + 124 Runtime runtime = Runtime.getRuntime(); Cell.Key columnKey = new Cell.Key("123"); Row.Key rowKey = new Row.Key("123"); ColumnValue columnValue = new ColumnValue(); ColumnCollection collection = new ColumnCollection(new CloudataConf()); collection.addValue(rowKey, new ColumnValue(rowKey, columnKey, "".getBytes()), 0); byte[] valueBuf = "0123456789".getBytes(); byte[] columnKeyBuf = "abcdefghij".getBytes(); byte[] rowKeyBuf = "!@#$%^&*()".getBytes(); Cell.Key columnKey2 = new Cell.Key("qwertyuiop".getBytes()); Row.Key rowKey2 = new Row.Key("asdfghjkl;".getBytes()); ColumnValue columnValue2 = new ColumnValue(rowKey2, columnKey2, "zxcvbnm,./".getBytes()); columnKey = new Cell.Key(columnKeyBuf); rowKey = new Row.Key(rowKeyBuf); columnValue = new ColumnValue(rowKey, columnKey, valueBuf); runtime.gc(); long before = runtime.freeMemory(); collection.addValue(rowKey, columnValue, 0); collection.addValue(rowKey2, columnValue2, 0); runtime.gc(); long after = runtime.freeMemory(); int byteLen = 12 + ((valueBuf.length + 3) / 8) * 8 + 4; int rowKeyLen = 16 + byteLen; int columnKeyLen = 16 + byteLen; int columnValueLen = 16 + rowKeyLen + columnKeyLen + byteLen; System.out.printf("%d - %d = %d, %d\n", before, after, (before - after), columnValueLen); }
From source file:Main.java
public static long getUsedMemorySize() { long freeSize = 0L; long totalSize = 0L; long usedSize = -1L; try {/*from w ww . j a v a 2 s . c om*/ Runtime info = Runtime.getRuntime(); freeSize = info.freeMemory(); totalSize = info.totalMemory(); usedSize = totalSize - freeSize; } catch (Exception e) { e.printStackTrace(); } return usedSize; }
From source file:Main.java
public static long getUsedMemorySize() { long freeSize = 0L; long totalSize = 0L; long usedSize = -1L; try {/* w w w .j a v a2 s . com*/ Runtime info = Runtime.getRuntime(); freeSize = info.freeMemory(); totalSize = info.totalMemory(); usedSize = totalSize - freeSize; } catch (Exception e) { e.printStackTrace(); } return usedSize / 1048576L; }
From source file:Main.java
public static long getPhysicalMemorySize() { long freeSize = 0L; long totalSize = 0L; long usedSize = -1L; try {/*from w ww . j ava 2 s. c o m*/ Runtime info = Runtime.getRuntime(); freeSize = info.freeMemory(); totalSize = info.totalMemory(); usedSize = totalSize - freeSize; } catch (Exception e) { e.printStackTrace(); } return totalSize / 1048576L; }
From source file:Util.java
/** * Returns a report of used and available memory. * //ww w.j a v a 2 s.com * @return a report of used and available memory */ @SuppressWarnings("boxing") public static String memoryReport() { Runtime runtime = Runtime.getRuntime(); long freemem = runtime.freeMemory(); long totalmem = runtime.totalMemory(); return String.format( "%.1f MB of memory free out of %.1f MB total in JVM (%.1f MB used). Configured maximum: %.1f MB.", freemem / BYTES_PER_MB, totalmem / BYTES_PER_MB, (totalmem - freemem) / BYTES_PER_MB, runtime.maxMemory() / BYTES_PER_MB); }
From source file:Main.java
/** * Determine the amount of available memory. "Available" memory is calculated as * <code>(max - total) + free</code>. * * @return the number of bytes of memory available according to the above algorithm. *//*from w ww. j av a 2s . com*/ public static long availableMemory() { Runtime rt = Runtime.getRuntime(); return rt.maxMemory() - rt.totalMemory() + rt.freeMemory(); }
From source file:com.qwazr.utils.RuntimeUtils.java
public static long getMemoryUsage() { Runtime runtime = Runtime.getRuntime(); return runtime.totalMemory() - runtime.freeMemory(); }
From source file:org.codelibs.fess.util.MemoryUtil.java
public static long getUsedMemory() { final Runtime runtime = Runtime.getRuntime(); final long freeBytes = runtime.freeMemory(); final long totalBytes = runtime.totalMemory(); return totalBytes - freeBytes; }