List of usage examples for java.lang.management MemoryUsage getUsed
public long getUsed()
From source file:MainClass.java
public static void premain(final Instrumentation inst) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { PrintWriter out = new PrintWriter(System.err); ThreadMXBean tb = ManagementFactory.getThreadMXBean(); out.printf("Current thread count: %d%n", tb.getThreadCount()); out.printf("Peak thread count: %d%n", tb.getPeakThreadCount()); List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); for (MemoryPoolMXBean pool : pools) { MemoryUsage peak = pool.getPeakUsage(); out.printf("Peak %s memory used: %,d%n", pool.getName(), peak.getUsed()); out.printf("Peak %s memory reserved: %,d%n", pool.getName(), peak.getCommitted()); }//from ww w . j a va 2s . c om Class[] loaded = inst.getAllLoadedClasses(); out.println("Loaded classes:"); for (Class c : loaded) out.println(c.getName()); out.close(); } catch (Throwable t) { System.err.println("Exception in agent: " + t); } } }); }
From source file:org.commoncrawl.util.JVMStats.java
public static float getHeapUtilizationRatio() { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage(); return ((float) memHeap.getUsed()) / ((float) memHeap.getMax()); }
From source file:gridool.util.system.SystemUtils.java
public static long getHeapUsedMemory() { MemoryUsage usage = mbean.getHeapMemoryUsage(); final long used = usage.getUsed(); return used;/* w w w .jav a 2 s . c o m*/ }
From source file:com.android.tools.idea.diagnostics.crash.GoogleCrash.java
@NotNull private static Map<String, String> getDefaultParameters() { Map<String, String> map = new HashMap<>(); ApplicationInfo applicationInfo = getApplicationInfo(); if (ANONYMIZED_UID != null) { map.put("guid", ANONYMIZED_UID); }/* www . j a va2s . c o m*/ RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); map.put("ptime", Long.toString(runtimeMXBean.getUptime())); // product specific key value pairs map.put(KEY_VERSION, applicationInfo == null ? "0.0.0.0" : applicationInfo.getStrictVersion()); map.put(KEY_PRODUCT_ID, CrashReport.PRODUCT_ANDROID_STUDIO); // must match registration with Crash map.put("fullVersion", applicationInfo == null ? "0.0.0.0" : applicationInfo.getFullVersion()); map.put("osName", StringUtil.notNullize(SystemInfo.OS_NAME)); map.put("osVersion", StringUtil.notNullize(SystemInfo.OS_VERSION)); map.put("osArch", StringUtil.notNullize(SystemInfo.OS_ARCH)); map.put("locale", StringUtil.notNullize(LOCALE)); map.put("vmName", StringUtil.notNullize(runtimeMXBean.getVmName())); map.put("vmVendor", StringUtil.notNullize(runtimeMXBean.getVmVendor())); map.put("vmVersion", StringUtil.notNullize(runtimeMXBean.getVmVersion())); MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); map.put("heapUsed", Long.toString(usage.getUsed())); map.put("heapCommitted", Long.toString(usage.getCommitted())); map.put("heapMax", Long.toString(usage.getMax())); return map; }
From source file:gridool.util.system.SystemUtils.java
public static long getHeapFreeMemory() { MemoryUsage usage = mbean.getHeapMemoryUsage(); final long max = usage.getMax(); final long used = usage.getUsed(); final long free = max - used; return free;/*w ww .j a va2 s . c o m*/ }
From source file:gridool.util.system.SystemUtils.java
public static float getHeapFreeRatio() { MemoryUsage usage = mbean.getHeapMemoryUsage(); final long max = usage.getMax(); final long used = usage.getUsed(); final long free = max - used; return (float) free / (float) max; }
From source file:org.commoncrawl.util.JVMStats.java
public static void dumpMemoryStats() { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage(); List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); long gcTime = 0; for (GarbageCollectorMXBean gcBean : gcBeans) { gcTime += gcBean.getCollectionTime(); }/*from ww w . ja va 2s . co m*/ float utilizationRatio = ((float) memHeap.getUsed()) / ((float) memHeap.getMax()); LOG.info("Heap Size:" + memHeap.getUsed() / MBytes + " (MB) CommitSize:" + memHeap.getCommitted() / MBytes + " (MB) Max:" + memHeap.getMax() + " Ratio:" + utilizationRatio + " GCTime:" + (gcTime - lastGCTime) + "PendingFinalCnt:" + memoryMXBean.getObjectPendingFinalizationCount()); lastGCTime = gcTime; }
From source file:jef.testbase.JefTester.java
private static void printMem(MemoryUsage m) { System.out.println("??:" + StringUtils.formatSize(m.getMax())); System.out.println("?:" + StringUtils.formatSize(m.getCommitted())); System.out.println("?:" + StringUtils.formatSize(m.getInit())); System.out.println(":" + StringUtils.formatSize(m.getUsed())); }
From source file:org.soitoolkit.commons.mule.util.MiscUtil.java
private static void printMemUsage() { int mb = 1024 * 1024; MemoryMXBean mxb = ManagementFactory.getMemoryMXBean(); MemoryUsage hm = mxb.getHeapMemoryUsage(); MemoryUsage nhm = mxb.getNonHeapMemoryUsage(); // int finalizable = mxb.getObjectPendingFinalizationCount(); logger.trace("Heap Memory: init/used/committed/max=" + hm.getInit() / mb + "/" + hm.getUsed() / mb + "/" + hm.getCommitted() / mb + "/" + hm.getMax() / mb); logger.trace("Non-Heap Mem: init/used/committed/max=" + nhm.getInit() / mb + "/" + nhm.getUsed() / mb + "/" + nhm.getCommitted() / mb + "/" + nhm.getMax() / mb); // logger.trace("finalizable: " + finalizable); //Getting the runtime reference from system Runtime runtime = Runtime.getRuntime(); logger.trace("Used/Free/Total/Max:" //Print used memory + (runtime.totalMemory() - runtime.freeMemory()) / mb + "/" //Print free memory + runtime.freeMemory() / mb + "/" //Print total available memory + runtime.totalMemory() / mb + "/" //Print Maximum available memory + runtime.maxMemory() / mb); }
From source file:io.ecarf.core.utils.Utils.java
/** * Log memory usage/*ww w. ja v a 2 s. com*/ * @return */ public static long getMemoryUsage() { List<MemoryPoolMXBean> memoryPools = new ArrayList<MemoryPoolMXBean>( ManagementFactory.getMemoryPoolMXBeans()); long usedHeapMemoryAfterLastGC = 0; for (MemoryPoolMXBean memoryPool : memoryPools) { if (memoryPool.getType().equals(MemoryType.HEAP)) { MemoryUsage poolCollectionMemoryUsage = memoryPool.getCollectionUsage(); usedHeapMemoryAfterLastGC += poolCollectionMemoryUsage.getUsed(); } } return usedHeapMemoryAfterLastGC; }