List of usage examples for java.lang.management MemoryUsage getMax
public long getMax()
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(); }/* www. j a v a 2 s. c o 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: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); }//from w w w . j a v a 2s .co 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:org.apache.hadoop.hbase.io.hfile.CacheConfig.java
/** * Returns the block cache or <code>null</code> in case none should be used. * * @param conf The current configuration. * @return The block cache or <code>null</code>. *//* w w w . jav a 2 s.c om*/ public static synchronized BlockCache instantiateBlockCache(Configuration conf) { if (GLOBAL_BLOCK_CACHE_INSTANCE != null) return GLOBAL_BLOCK_CACHE_INSTANCE; if (blockCacheDisabled) return null; float cachePercentage = conf.getFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, HConstants.HFILE_BLOCK_CACHE_SIZE_DEFAULT); if (cachePercentage == 0L) { blockCacheDisabled = true; return null; } if (cachePercentage > 1.0) { throw new IllegalArgumentException( HConstants.HFILE_BLOCK_CACHE_SIZE_KEY + " must be between 0.0 and 1.0, and not > 1.0"); } // Calculate the amount of heap to give the heap. MemoryUsage mu = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); long lruCacheSize = (long) (mu.getMax() * cachePercentage); int blockSize = conf.getInt("hbase.offheapcache.minblocksize", HConstants.DEFAULT_BLOCKSIZE); long slabCacheOffHeapCacheSize = (long) (conf.getFloat(SLAB_CACHE_OFFHEAP_PERCENTAGE_KEY, (float) 0) * DirectMemoryUtils.getDirectMemorySize()); if (slabCacheOffHeapCacheSize <= 0) { String bucketCacheIOEngineName = conf.get(BUCKET_CACHE_IOENGINE_KEY, null); float bucketCachePercentage = conf.getFloat(BUCKET_CACHE_SIZE_KEY, 0F); // A percentage of max heap size or a absolute value with unit megabytes long bucketCacheSize = (long) (bucketCachePercentage < 1 ? mu.getMax() * bucketCachePercentage : bucketCachePercentage * 1024 * 1024); boolean combinedWithLru = conf.getBoolean(BUCKET_CACHE_COMBINED_KEY, DEFAULT_BUCKET_CACHE_COMBINED); BucketCache bucketCache = null; if (bucketCacheIOEngineName != null && bucketCacheSize > 0) { int writerThreads = conf.getInt(BUCKET_CACHE_WRITER_THREADS_KEY, DEFAULT_BUCKET_CACHE_WRITER_THREADS); int writerQueueLen = conf.getInt(BUCKET_CACHE_WRITER_QUEUE_KEY, DEFAULT_BUCKET_CACHE_WRITER_QUEUE); String persistentPath = conf.get(BUCKET_CACHE_PERSISTENT_PATH_KEY); float combinedPercentage = conf.getFloat(BUCKET_CACHE_COMBINED_PERCENTAGE_KEY, DEFAULT_BUCKET_CACHE_COMBINED_PERCENTAGE); if (combinedWithLru) { lruCacheSize = (long) ((1 - combinedPercentage) * bucketCacheSize); bucketCacheSize = (long) (combinedPercentage * bucketCacheSize); } try { int ioErrorsTolerationDuration = conf.getInt( "hbase.bucketcache.ioengine.errors.tolerated.duration", BucketCache.DEFAULT_ERROR_TOLERATION_DURATION); bucketCache = new BucketCache(bucketCacheIOEngineName, bucketCacheSize, blockSize, writerThreads, writerQueueLen, persistentPath, ioErrorsTolerationDuration); } catch (IOException ioex) { LOG.error("Can't instantiate bucket cache", ioex); throw new RuntimeException(ioex); } } LOG.info("Allocating LruBlockCache size=" + StringUtils.byteDesc(lruCacheSize) + ", blockSize=" + StringUtils.byteDesc(blockSize)); LruBlockCache lruCache = new LruBlockCache(lruCacheSize, blockSize); lruCache.setVictimCache(bucketCache); if (bucketCache != null && combinedWithLru) { GLOBAL_BLOCK_CACHE_INSTANCE = new CombinedBlockCache(lruCache, bucketCache); } else { GLOBAL_BLOCK_CACHE_INSTANCE = lruCache; } } else { GLOBAL_BLOCK_CACHE_INSTANCE = new DoubleBlockCache(lruCacheSize, slabCacheOffHeapCacheSize, blockSize, blockSize, conf); } return GLOBAL_BLOCK_CACHE_INSTANCE; }
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:com.appeligo.captions.CaptionListener.java
private synchronized static void checkStats() { int interval = 5; // minutes long timestamp = new Date().getTime(); if ((timestamp - lastWrite) > (interval * 60 * 1000)) { lastWrite = timestamp;/*from www .j av a2 s . c o m*/ String day = Utils.getDatePath(timestamp); if (!day.equals(currentDay)) { if (statsFile != null) { statsFile.println("</table></body></html>"); statsFile.close(); statsFile = null; } currentDay = day; } if (hostname == null) { try { hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { hostname = "UnknownHost"; } } String dirname = documentRoot + "/stats/" + currentDay + "/" + hostname; String statsFileName = dirname + "/searchprocstats.html"; try { if (statsFile == null) { File dir = new File(dirname); if ((!dir.exists()) && (!dir.mkdirs())) { throw new IOException("Error creating directory " + dirname); } File file = new File(statsFileName); if (file.exists()) { statsFile = new PrintStream(new FileOutputStream(statsFileName, true)); statsFile.println("<tr><td colspan='5'>Restart</td></tr>"); } else { statsFile = new PrintStream(new FileOutputStream(statsFileName)); String title = "Search Process (tomcat) status for " + currentDay; statsFile.println("<html><head><title>" + title + "</title></head>"); statsFile.println("<body><h1>" + title + "</h1>"); statsFile.println("<table border='1'>"); statsFile.println("<tr>"); statsFile.println("<th colspan='2'>" + interval + " Minute Intervals</th>" + "<th colspan='3'>Mem Pre GC</th>" + "<th>GC</th>" + "<th colspan='3'>Mem Post GC</th>"); statsFile.println("</tr>"); statsFile.println("<tr>"); statsFile.println("<th>Timestamp</th>"); statsFile.println("<th>Time</th>"); statsFile.println("<th>Used</th>"); statsFile.println("<th>Committed</th>"); statsFile.println("<th>Max</th>"); statsFile.println("<th>Millis</th>"); statsFile.println("<th>Used</th>"); statsFile.println("<th>Committed</th>"); statsFile.println("<th>Max</th>"); statsFile.println("</tr>"); } } Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis(timestamp); String time = String.format("%1$tH:%1$tM:%1$tS", cal); MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); MemoryUsage memory = memoryBean.getHeapMemoryUsage(); statsFile.print("<tr>"); statsFile.print("<td>" + timestamp + "</td>"); statsFile.print("<td>" + time + "</td>"); statsFile.format("<td>%,d</td>", memory.getUsed()); statsFile.format("<td>%,d</td>", memory.getCommitted()); statsFile.format("<td>%,d</td>", memory.getMax()); long beforeGC = System.currentTimeMillis(); System.gc(); long elapsed = System.currentTimeMillis() - beforeGC; statsFile.format("<td>%,d</td>", (int) elapsed); memoryBean = ManagementFactory.getMemoryMXBean(); memory = memoryBean.getHeapMemoryUsage(); statsFile.format("<td>%,d</td>", memory.getUsed()); statsFile.format("<td>%,d</td>", memory.getCommitted()); statsFile.format("<td>%,d</td>", memory.getMax()); statsFile.println("</tr>"); } catch (IOException e) { log.error("Error opening or writing to " + statsFileName, e); } } }
From source file:org.jahia.bin.errors.ErrorFileDumper.java
private static void printMemoryUsage(String type, MemoryUsage usage, PrintWriter strOut) { strOut.println();//from www . ja v a2 s. c o m strOut.print(type); strOut.print(" : "); strOut.print(Math.round((float) usage.getUsed() / (float) usage.getMax() * 100f)); strOut.println("% used"); strOut.println("---------------"); strOut.print("Used : "); strOut.println(org.jahia.utils.FileUtils.humanReadableByteCount(usage.getUsed(), true)); strOut.print("Committed : "); strOut.println(org.jahia.utils.FileUtils.humanReadableByteCount(usage.getCommitted(), true)); strOut.print("Max : "); strOut.println(org.jahia.utils.FileUtils.humanReadableByteCount(usage.getMax(), true)); }
From source file:ch.admin.suis.msghandler.servlet.PingServlet.java
private String calcHeapSpace() { MemoryUsage heap = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); long max = heap.getMax(); long used = heap.getUsed(); int percent = (int) Math.round(100.0 * used / max); return used + ":" + max + ":" + percent; }
From source file:ch.admin.suis.msghandler.servlet.PingServlet.java
private String calcPermSpace() { MemoryUsage nonHeap = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage(); long max = nonHeap.getMax(); long used = nonHeap.getUsed(); int percent = (int) Math.round(100.0 * used / max); return used + ":" + max + ":" + percent; }
From source file:org.rhq.enterprise.agent.promptcmd.GCPromptCommand.java
private void printMemoryUsage(PrintWriter out, String name, MemoryType type, MemoryUsage memUsage) { long init = memUsage.getInit(); long max = memUsage.getMax(); long used = memUsage.getUsed(); long committed = memUsage.getCommitted(); String typeStr;/* w w w .ja v a 2 s .co m*/ switch (type) { case HEAP: typeStr = "Heap"; break; case NON_HEAP: typeStr = "Non-heap"; break; default: typeStr = "?"; } double usedPercentage = (used * 100.0) / committed; double committedPercentage = (committed * 100.0) / max; out.println(MSG.getMsg(AgentI18NResourceKeys.GC_MEM_USAGE, name, typeStr, init, max, used, usedPercentage, committed, committedPercentage)); }
From source file:com.attribyte.essem.model.index.IndexStats.java
public String getPercentHeapUsed() { MemoryUsage usage = mxBean.getHeapMemoryUsage(); return asPercent(RatioGauge.Ratio.of(usage.getUsed(), usage.getMax()).getValue()); }