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.kyne.webby.bukkit.RTKModuleSocket.java

private void getInfos(final Map<String, Object> responseParams) {
    final List<WebbyPlayer> playerList = new ArrayList<WebbyPlayer>();
    for (final Player player : Bukkit.getOnlinePlayers()) {
        playerList.add(new WebbyPlayer(player.getName(), player.isOp()));
    }/*from  w  ww .  java  2s .c om*/
    final Runtime runtime = Runtime.getRuntime();
    final long freeMemory = runtime.freeMemory();
    final long totalMemory = runtime.totalMemory();
    final long maxMemory = runtime.maxMemory();
    final int mb = 1024 * 1024;

    final ServerInfos serverInfos = new ServerInfos(Bukkit.getVersion(), Bukkit.getMaxPlayers(),
            playerList.size(), playerList, freeMemory / mb, totalMemory / mb, maxMemory / mb);
    responseParams.put("DATA", serverInfos);
}

From source file:org.apache.shindig.social.opensocial.util.JsonConverterPerformancePerf.java

public void testToJsonLibOnInheritedClassOutput() throws Exception {
    SpecialPerson[] spa = new SpecialPerson[TEST_SIZE];
    for (int i = 0; i < TEST_SIZE; i++) {
        spa[i] = new SpecialPerson(String.valueOf(i), "robot", "nonsense");
    }/*from   w  w w  .  ja va 2s  .  c o m*/
    Runtime r = Runtime.getRuntime();
    r.gc();
    long memstart = r.totalMemory() - r.freeMemory();
    long startOutput = System.currentTimeMillis();
    String[] output = new String[TEST_SIZE];
    for (int i = 0; i < TEST_SIZE; i++) {
        output[i] = beanJsonLibConverter.convertToString(spa[i]);
    }
    long endOutput = System.currentTimeMillis();
    long memend = r.totalMemory() - r.freeMemory();

    String[] serializeOutput = new String[TEST_SIZE];
    char[] source = output[0].toCharArray();
    r.gc();

    long stringsizeStart = r.totalMemory() - r.freeMemory();
    for (int i = 0; i < TEST_SIZE; i++) {
        serializeOutput[i] = new String(source);
    }
    long stringsizeEnd = r.totalMemory() - r.freeMemory();

    /*
     * Output the time per conversion and the memory usage - the output per
     * conversion.
     *
     */

    log.info("SF JSON Lib Output " + average(startOutput, endOutput, TEST_SIZE) + " ms/conversion, "
            + (average(memstart, memend, TEST_SIZE) - average(stringsizeStart, stringsizeEnd, TEST_SIZE))
            + " heap bytes/conversion, output packet consumed on average "
            + average(stringsizeStart, stringsizeEnd, TEST_SIZE) + " for a string length of "
            + output[0].length());
    log.info("Output Was [" + output[0] + ']');
}

From source file:alluxio.util.JvmPauseMonitor.java

private String getMemoryInfo() {
    Runtime runtime = Runtime.getRuntime();
    return "max memory = " + runtime.maxMemory() / (1024 * 1024) + "M total memory = "
            + runtime.totalMemory() / (1024 * 1024) + "M free memory = " + runtime.freeMemory() / (1024 * 1024)
            + "M";
}

From source file:org.polymap.core.model2.test.SimpleModelTest.java

protected void logHeap() {
    System.gc();/*from  ww w . j av  a2  s. c  o  m*/
    Runtime rt = Runtime.getRuntime();
    log.info("HEAP: free/total: " + FileUtils.byteCountToDisplaySize(rt.freeMemory()) + " / "
            + FileUtils.byteCountToDisplaySize(rt.totalMemory()));
}

From source file:org.loklak.api.susi.StatusService.java

@Override
public JSONObject serviceImpl(Query post, HttpServletResponse response, Authorization rights,
        JSONObjectWithDefault permissions) throws APIException {

    post.setResponse(response, "application/javascript");

    // generate json
    Runtime runtime = Runtime.getRuntime();
    JSONObject json = new JSONObject(true);
    JSONObject system = new JSONObject(true);
    system.put("assigned_memory", runtime.maxMemory());
    system.put("used_memory", runtime.totalMemory() - runtime.freeMemory());
    system.put("available_memory", runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory());
    system.put("cores", runtime.availableProcessors());
    system.put("threads", Thread.activeCount());
    system.put("runtime", System.currentTimeMillis() - Caretaker.startupTime);
    system.put("load_system_average", OS.getSystemLoadAverage());
    system.put("load_system_cpu", OS.getSystemCpuLoad());
    system.put("load_process_cpu", OS.getProcessCpuLoad());
    system.put("server_threads", SusiServer.getServerThreads());
    system.put("server_uri", SusiServer.getServerURI());

    JSONObject index = new JSONObject(true);
    JSONObject messages = new JSONObject(true);
    JSONObject queue = new JSONObject(true);
    messages.put("queue", queue);
    JSONObject users = new JSONObject(true);
    JSONObject queries = new JSONObject(true);
    JSONObject accounts = new JSONObject(true);
    JSONObject user = new JSONObject(true);
    index.put("messages", messages);
    index.put("users", users);
    index.put("queries", queries);
    index.put("accounts", accounts);
    index.put("user", user);

    JSONObject client_info = new JSONObject(true);
    client_info.put("RemoteHost", post.getClientHost());
    client_info.put("IsLocalhost", post.isLocalhostAccess() ? "true" : "false");

    JSONObject request_header = new JSONObject(true);
    Enumeration<String> he = post.getRequest().getHeaderNames();
    while (he.hasMoreElements()) {
        String h = he.nextElement();
        request_header.put(h, post.getRequest().getHeader(h));
    }/*w  w w. j  ava 2s  . c  o m*/
    client_info.put("request_header", request_header);

    json.put("system", system);
    json.put("index", index);
    json.put("client_info", client_info);

    return json;
}

From source file:qa.qcri.nadeef.test.core.SQLTableTest.java

public void testSize() throws InterruptedException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    SQLTable table = new SQLTable("TB_test60m", connectionFactory);
    table.get(0);/*  w  ww .  j a  v a2  s. c o  m*/

    long elapsedTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);
    int mb = 1024 * 1024;

    //Getting the runtime reference from system
    Runtime runtime = Runtime.getRuntime();

    System.out.println("##### Heap utilization statistics [MB] #####");

    long usedMemory = (runtime.totalMemory() - runtime.freeMemory()) / mb;
    System.out.println("Used Memory:" + usedMemory);
    System.out.println("Free Memory:" + runtime.freeMemory() / mb);
    System.out.println("Total Memory:" + runtime.totalMemory() / mb);
    System.out.println("Max Memory:" + runtime.maxMemory() / mb);
    System.out.println("Load time: " + elapsedTime + " ms.");

    // memory usage should be less than 700 mb.
    Assert.assertTrue(usedMemory < 700);

    // load time should be less than 18000 ms
    Assert.assertTrue(elapsedTime < 18000);
}

From source file:ai.susi.server.api.susi.StatusService.java

@Override
public JSONObject serviceImpl(Query post, HttpServletResponse response, Authorization rights,
        JsonObjectWithDefault permissions) throws APIException {

    post.setResponse(response, "application/javascript");

    // generate json
    Runtime runtime = Runtime.getRuntime();
    JSONObject json = new JSONObject(true);
    JSONObject system = new JSONObject(true);
    system.put("assigned_memory", runtime.maxMemory());
    system.put("used_memory", runtime.totalMemory() - runtime.freeMemory());
    system.put("available_memory", runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory());
    system.put("cores", runtime.availableProcessors());
    system.put("threads", Thread.activeCount());
    system.put("runtime", System.currentTimeMillis() - Caretaker.startupTime);
    system.put("load_system_average", OS.getSystemLoadAverage());
    system.put("load_system_cpu", OS.getSystemCpuLoad());
    system.put("load_process_cpu", OS.getProcessCpuLoad());
    system.put("server_threads", SusiServer.getServerThreads());
    system.put("server_uri", SusiServer.getServerURI());

    JSONObject index = new JSONObject(true);
    JSONObject messages = new JSONObject(true);
    JSONObject queue = new JSONObject(true);
    messages.put("queue", queue);
    JSONObject users = new JSONObject(true);
    JSONObject queries = new JSONObject(true);
    JSONObject accounts = new JSONObject(true);
    JSONObject user = new JSONObject(true);
    index.put("messages", messages);
    index.put("users", users);
    index.put("queries", queries);
    index.put("accounts", accounts);
    index.put("user", user);

    JSONObject client_info = new JSONObject(true);
    client_info.put("RemoteHost", post.getClientHost());
    client_info.put("IsLocalhost", post.isLocalhostAccess() ? "true" : "false");

    JSONObject request_header = new JSONObject(true);
    Enumeration<String> he = post.getRequest().getHeaderNames();
    while (he.hasMoreElements()) {
        String h = he.nextElement();
        request_header.put(h, post.getRequest().getHeader(h));
    }/*from   w  w  w.j  a  v  a  2 s  . c  o m*/
    client_info.put("request_header", request_header);

    json.put("system", system);
    json.put("index", index);
    json.put("client_info", client_info);

    return json;
}

From source file:com.redhat.developers.containers.MyController.java

@CrossOrigin
@RequestMapping(method = RequestMethod.GET, value = "/memory", produces = "text/plain")
public String memory() {
    System.out.println("Starting to allocate memory...");
    Runtime rt = Runtime.getRuntime();
    StringBuilder sb = new StringBuilder();
    long maxMemory = rt.maxMemory();
    long usedMemory = 0;
    while (((float) usedMemory / maxMemory) < 0.80) {
        sb.append(System.nanoTime() + sb.toString());
        usedMemory = rt.totalMemory();
    }/* w w  w.  j  a  va 2s .  co m*/
    String msg = "Allocated more than 80% (" + humanReadableByteCount(usedMemory, false)
            + ") of the max allowed JVM memory size (" + humanReadableByteCount(maxMemory, false) + ")";
    System.out.println(msg);
    return msg;
}

From source file:tachyon.master.InodeFolderTest.java

@Test
public void getChildTest() {
    // large number of small files
    InodeFolder inodeFolder = new InodeFolder("testFolder1", 1, 0, System.currentTimeMillis());
    int nFiles = (int) 1E5;
    Inode[] inodes = new Inode[nFiles];
    for (int i = 0; i < nFiles; i++) {
        inodes[i] = new InodeFile(String.format("testFile%d", i + 1), i + 2, 1, 1, System.currentTimeMillis());
        inodeFolder.addChild(inodes[i]);
    }/*from   w w w  . j a  va  2  s  .c o m*/

    Runtime runtime = Runtime.getRuntime();
    System.out.println(String.format("Used Memory = %dB when number of files = %d",
            runtime.totalMemory() - runtime.freeMemory(), nFiles));

    long start = System.currentTimeMillis();
    for (int i = 0; i < nFiles; i++) {
        Assert.assertEquals(inodes[i], inodeFolder.getChild(i + 2));
    }
    System.out.println(String.format("getChild(int fid) called sequentially %d times, cost %d ms", nFiles,
            System.currentTimeMillis() - start));

    start = System.currentTimeMillis();
    for (int i = 0; i < nFiles; i++) {
        Assert.assertEquals(inodes[i], inodeFolder.getChild(String.format("testFile%d", i + 1)));
    }
    System.out.println(String.format("getChild(String name) called sequentially %d times, cost %d ms", nFiles,
            System.currentTimeMillis() - start));
}

From source file:com.openddal.test.BaseTestCase.java

/**
 * Get the number of bytes heap memory in use.
 *
 * @return the used bytes// www .  j  av  a 2  s. com
 */
public static long getMemoryUsedBytes() {
    Runtime rt = Runtime.getRuntime();
    long memory = Long.MAX_VALUE;
    for (int i = 0; i < 8; i++) {
        rt.gc();
        long memNow = rt.totalMemory() - rt.freeMemory();
        if (memNow >= memory) {
            break;
        }
        memory = memNow;
    }
    return memory;
}