Example usage for java.lang Runtime totalMemory

List of usage examples for java.lang Runtime totalMemory

Introduction

In this page you can find the example usage for java.lang Runtime totalMemory.

Prototype

public native long totalMemory();

Source Link

Document

Returns the total amount of memory in the Java virtual machine.

Usage

From source file:com.yobidrive.diskmap.buckets.BucketTableManager.java

public static void main(String[] args) {

    try {/*from   w  w  w.  j  a v a2  s.  c o m*/
        BucketTableManager nw = new BucketTableManager("/Users/Francois/Documents/NEEDLES/0.TestStore", 100,
                1000000, 3000L, true);

        nw.initialize();
        System.out.println(
                "Bucket table initialization: " + (nw.getCheckPoint().isEmpty() ? " Repair required" : " OK"));

        Runtime runtime = Runtime.getRuntime();
        long before = runtime.totalMemory() - runtime.freeMemory();

        nw.getCheckPoint().copyFrom(new NeedlePointer()); // reset checkpoint

        Date startDate = new Date();
        Date lapDate = new Date();
        System.out.println("Start test for " + TEST_COUNT + " pointers");
        long counter = 0;
        long lapCounter = 0;
        long offset = 0;
        BucketFNVHash hashFunc = new BucketFNVHash(1000000000L);
        while (counter < TEST_COUNT) {
            NeedlePointer needlePointer = new NeedlePointer();
            String key = "MYVERYNICEKEY" + counter;
            long bucket = hashFunc.hash(key);
            needlePointer.setNeedleFileNumber(4);
            needlePointer.setNeedleOffset(offset++);
            nw.writeNeedlePointer(bucket, needlePointer);
            counter++;
            Date lapDate2 = new Date();
            long spent = lapDate2.getTime() - lapDate.getTime();
            if (spent >= 1000 || (counter - lapCounter > TARGET_TPS)) { // Check each second or target tps
                if (spent < 1000) { // pause when tps reached
                    Thread.sleep(1000 - spent);
                    System.out.print(".");
                } else
                    System.out.print("*");
                lapDate = lapDate2; // Reset lap time
                lapCounter = counter; // Reset tps copunter
            }
        }
        long timeSpent = new Date().getTime() - startDate.getTime();
        System.out.println("\n\nWriting before cache commit of " + TEST_COUNT + " pointers \n"
                + "\tTotal time: " + timeSpent / 1000 + "s\n" + "\tThroughput: "
                + (TEST_COUNT / timeSpent * 1000) + " tps");

        timeSpent = new Date().getTime() - startDate.getTime();
        System.out.println("\n\nProcessed writing of " + TEST_COUNT + " pointers \n" + "\tTotal time: "
                + timeSpent / 1000 + "s\n" + "\tThroughput: " + (TEST_COUNT / timeSpent * 1000) + " tps");
        System.out.println("Max cycle time = " + (nw.getMaxCycleTimePass1() + nw.getMaxCycleTimePass2()));

    } catch (Throwable th) {
        th.printStackTrace();
    }

}

From source file:gov.jgi.meta.hadoop.input.FastaBlockLineReader.java

public static void main(String[] args) {

    int num = 1;//from w w  w  .  j a va  2  s  .  c om
    int last = -1;

    do {
        try {
            FileInputStream fstream = new FileInputStream("/scratch/karan/30mb.fas");
            FastaBlockLineReader fblr = new FastaBlockLineReader(fstream);

            Text key = new Text();
            Map<String, String> setofreads = new HashMap<String, String>();
            Map<String, String> setofreadsTotal = new HashMap<String, String>();
            int length = (int) (Math.random() * 10000);
            length = 3000000;
            System.out.println("lenght = " + length);

            int total = 0;

            fblr.readLine(key, setofreads, Integer.MAX_VALUE, length);
            //            System.out.println("setofreads.size = " + setofreads.size());
            total += setofreads.size();
            //for (String s : setofreads.keySet()) {
            //                System.out.println(s);
            //            }
            Runtime r = Runtime.getRuntime();
            while (setofreads.size() > 0) {
                setofreadsTotal.putAll(setofreads);
                setofreads.clear();
                fblr.readLine(key, setofreads, Integer.MAX_VALUE, length);
                //              System.out.println("setofreads.size = " + setofreads.size());
                total += setofreads.size();

                r.gc();
            }
            System.out.println("total = " + total);
            System.out.println("heap size = " + r.totalMemory() / 1048576);

            if (last != -1) {
                if (last != total) {
                    System.out.println(
                            "error!!!, length = " + length + ": last = " + last + " current = " + total);
                }
            }
            last = total;

        } catch (Exception e) {
            System.out.println(e);
        }
    } while (num-- > 0);

}

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 ww . j av 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 {/*www .j a  v  a 2  s .  c o  m*/
        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:com.qwazr.utils.RuntimeUtils.java

public static long getMemoryUsage() {
    Runtime runtime = Runtime.getRuntime();
    return runtime.totalMemory() - runtime.freeMemory();
}

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.
 *///www .j  av  a  2 s  .  c  o  m
public static long availableMemory() {
    Runtime rt = Runtime.getRuntime();
    return rt.maxMemory() - rt.totalMemory() + rt.freeMemory();
}

From source file:Main.java

public static long availableMemory() {
    final Runtime runtime = Runtime.getRuntime();
    final long used = runtime.totalMemory() - runtime.freeMemory();

    final ActivityManager activityManager = (ActivityManager) sContext
            .getSystemService(Context.ACTIVITY_SERVICE);
    final long total = activityManager.getMemoryClass() * 1024 * 1024;

    return total - used;
}

From source file:Mem.java

public static long used() {
    Runtime r = Runtime.getRuntime();
    return r.totalMemory() - r.freeMemory();
}

From source file:MemoryUtils.java

static double usedMemory(Runtime runtime) {
    long totalMemory = runtime.totalMemory();
    long freeMemory = runtime.freeMemory();
    double usedMemory = (double) (totalMemory - freeMemory) / (double) (1024 * 1024);
    return usedMemory;
}

From source file:Main.java

public static long getUsedMemorySize() {

    long freeSize = 0L;
    long totalSize = 0L;
    long usedSize = -1L;
    try {/*from w w w .j a v  a2  s  .c om*/
        Runtime info = Runtime.getRuntime();
        freeSize = info.freeMemory();
        totalSize = info.totalMemory();
        usedSize = totalSize - freeSize;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return usedSize;

}