List of usage examples for java.lang.management ManagementFactory getGarbageCollectorMXBeans
public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans()
From source file:org.apache.hadoop.metrics.jvm.JvmMetrics.java
private void doGarbageCollectionUpdates() { List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); long count = 0; long timeMillis = 0; for (GarbageCollectorMXBean gcBean : gcBeans) { count += gcBean.getCollectionCount(); timeMillis += gcBean.getCollectionTime(); }/*from ww w . j a v a 2s. c o m*/ metrics.incrMetric("gcCount", (int) (count - gcCount)); metrics.incrMetric("gcTimeMillis", (int) (timeMillis - gcTimeMillis)); gcCount = count; gcTimeMillis = timeMillis; }
From source file:com.simiacryptus.util.io.HtmlNotebookOutput.java
@javax.annotation.Nonnull @SuppressWarnings("unchecked") @Override/* w ww . j av a 2 s . com*/ public <T> T code(@javax.annotation.Nonnull final UncheckedSupplier<T> fn, final int maxLog, final int framesNo) { try { final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); final StackTraceElement callingFrame = stackTrace[framesNo]; final String sourceCode = CodeUtil.getInnerText(callingFrame); @javax.annotation.Nonnull final SysOutInterceptor.LoggedResult<TimedResult<Object>> result = SysOutInterceptor.withOutput(() -> { long priorGcMs = ManagementFactory.getGarbageCollectorMXBeans().stream() .mapToLong(x -> x.getCollectionTime()).sum(); final long start = System.nanoTime(); try { @Nullable Object result1 = null; try { result1 = fn.get(); } catch (@javax.annotation.Nonnull final RuntimeException e) { throw e; } catch (@javax.annotation.Nonnull final Exception e) { throw new RuntimeException(e); } long gcTime = ManagementFactory.getGarbageCollectorMXBeans().stream() .mapToLong(x -> x.getCollectionTime()).sum() - priorGcMs; return new TimedResult<Object>(result1, System.nanoTime() - start, gcTime); } catch (@javax.annotation.Nonnull final Throwable e) { long gcTime = ManagementFactory.getGarbageCollectorMXBeans().stream() .mapToLong(x -> x.getCollectionTime()).sum() - priorGcMs; return new TimedResult<Object>(e, System.nanoTime() - start, gcTime); } }); try { @javax.annotation.Nonnull final URI resolved = URI.create(sourceRoot) .resolve(Util.pathTo(CodeUtil.projectRoot, CodeUtil.findFile(callingFrame))); out("<p>Code from <a href='%s#L%s'>%s:%s</a> executed in %.2f seconds: <br/>", resolved, callingFrame.getLineNumber(), callingFrame.getFileName(), callingFrame.getLineNumber(), result.obj.seconds()); } catch (@javax.annotation.Nonnull final Exception e) { out("<p>Code from %s:%s executed in %.2f seconds: <br/>", callingFrame.getFileName(), callingFrame.getLineNumber(), result.obj.seconds()); } out("<pre>"); out(sourceCode); out("</pre>"); if (!result.log.isEmpty()) { out("Logging: <br/>"); out("<pre>"); out(summarize(maxLog, result.log)); out("</pre>"); } out(""); final Object eval = result.obj.result; if (null != eval) { out("Returns: <br/>"); String str; boolean escape; if (eval instanceof Throwable) { @javax.annotation.Nonnull final ByteArrayOutputStream out = new ByteArrayOutputStream(); ((Throwable) eval).printStackTrace(new PrintStream(out)); str = new String(out.toByteArray(), "UTF-8"); escape = true;// } else if (eval instanceof Component) { str = image(Util.toImage((Component) eval), "Result"); escape = false; } else if (eval instanceof BufferedImage) { str = image((BufferedImage) eval, "Result"); escape = false; } else if (eval instanceof TableOutput) { str = ((TableOutput) eval).toHtmlTable(); escape = false; } else { str = eval.toString(); escape = true; } if (escape) { out("<pre>" + summarize(maxLog, str) + "</pre>"); } else { out(summarize(maxLog, str)); } if (escape) { } out("\n\n"); if (eval instanceof Throwable) { throw new RuntimeException((Throwable) result.obj.result); } } out("</p>"); return (T) eval; } catch (@javax.annotation.Nonnull final IOException e) { throw new RuntimeException(e); } }
From source file:com.buaa.cfs.utils.JvmPauseMonitor.java
private Map<String, GcTimes> getGcTimes() { Map<String, GcTimes> map = Maps.newHashMap(); List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean gcBean : gcBeans) { map.put(gcBean.getName(), new GcTimes(gcBean)); }//from w w w .j a v a 2s .c o m return map; }
From source file:co.aikar.timings.TimingsExport.java
/** * Checks if any pending reports are being requested, and builds one if needed. *//* www. ja va2 s . com*/ static void reportTimings() { if (requestingReport.isEmpty()) { return; } TimingsReportListener listeners = new TimingsReportListener(requestingReport); listeners.addConsoleIfNeeded(); requestingReport.clear(); long now = System.currentTimeMillis(); final long lastReportDiff = now - lastReport; if (lastReportDiff < 60000) { listeners.sendMessage(ChatColor.RED + "Please wait at least 1 minute in between Timings reports. (" + (int) ((60000 - lastReportDiff) / 1000) + " seconds)"); listeners.done(); return; } final long lastStartDiff = now - TimingsManager.timingStart; if (lastStartDiff < 180000) { listeners.sendMessage(ChatColor.RED + "Please wait at least 3 minutes before generating a Timings report. Unlike Timings v1, v2 benefits from longer timings and is not as useful with short timings. (" + (int) ((180000 - lastStartDiff) / 1000) + " seconds)"); listeners.done(); return; } listeners.sendMessage(ChatColor.GREEN + "Preparing Timings Report..."); lastReport = now; Map parent = createObject( // Get some basic system details about the server pair("version", Bukkit.getVersion()), pair("maxplayers", Bukkit.getMaxPlayers()), pair("start", TimingsManager.timingStart / 1000), pair("end", System.currentTimeMillis() / 1000), pair("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000)); if (!TimingsManager.privacy) { appendObjectData(parent, pair("server", Bukkit.getServerName()), pair("motd", Bukkit.getServer().getMotd()), pair("online-mode", Bukkit.getServer().getOnlineMode()), pair("icon", Bukkit.getServer().getServerIcon().getData())); } final Runtime runtime = Runtime.getRuntime(); RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); parent.put("system", createObject(pair("timingcost", getCost()), pair("name", System.getProperty("os.name")), pair("version", System.getProperty("os.version")), pair("jvmversion", System.getProperty("java.version")), pair("arch", System.getProperty("os.arch")), pair("maxmem", runtime.maxMemory()), pair("cpu", runtime.availableProcessors()), pair("runtime", ManagementFactory.getRuntimeMXBean().getUptime()), pair("flags", StringUtils.join(runtimeBean.getInputArguments(), " ")), pair("gc", toObjectMapper(ManagementFactory.getGarbageCollectorMXBeans(), input -> pair(input.getName(), toArray(input.getCollectionCount(), input.getCollectionTime())))))); Set<Material> tileEntityTypeSet = Sets.newHashSet(); Set<EntityType> entityTypeSet = Sets.newHashSet(); int size = HISTORY.size(); TimingHistory[] history = new TimingHistory[size + 1]; int i = 0; for (TimingHistory timingHistory : HISTORY) { tileEntityTypeSet.addAll(timingHistory.tileEntityTypeSet); entityTypeSet.addAll(timingHistory.entityTypeSet); history[i++] = timingHistory; } history[i] = new TimingHistory(); // Current snapshot tileEntityTypeSet.addAll(history[i].tileEntityTypeSet); entityTypeSet.addAll(history[i].entityTypeSet); Map handlers = createObject(); for (TimingIdentifier.TimingGroup group : TimingIdentifier.GROUP_MAP.values()) { for (TimingHandler id : group.handlers) { if (!id.isTimed() && !id.isSpecial()) { continue; } handlers.put(id.id, toArray(group.id, id.name)); } } parent.put("idmap", createObject( pair("groups", toObjectMapper( TimingIdentifier.GROUP_MAP.values(), group -> pair(group.id, group.name))), pair("handlers", handlers), pair( "worlds", toObjectMapper(TimingHistory.worldMap.entrySet(), input -> pair(input.getValue(), input.getKey()))), pair("tileentity", toObjectMapper(tileEntityTypeSet, input -> pair(input.getId(), input.name()))), pair("entity", toObjectMapper(entityTypeSet, input -> pair(input.getTypeId(), input.name()))))); // Information about loaded plugins parent.put("plugins", toObjectMapper(Bukkit.getPluginManager().getPlugins(), plugin -> pair(plugin.getName(), createObject(pair("version", plugin.getDescription().getVersion()), pair("description", String.valueOf(plugin.getDescription().getDescription()).trim()), pair("website", plugin.getDescription().getWebsite()), pair("authors", StringUtils.join(plugin.getDescription().getAuthors(), ", ")))))); // Information on the users Config parent.put("config", createObject(pair("bukkit", mapAsJSON(Bukkit.spigot().getConfig(), null)))); new TimingsExport(listeners, parent, history).start(); }
From source file:com.snowstore.mercury.core.metric.SystemPublicMetrics.java
/** * Add garbage collection metrics./*from w ww. jav a 2 s . c o m*/ * * @param result * the result */ protected void addGarbageCollectionMetrics(Collection<Metric<?>> result) { List<GarbageCollectorMXBean> garbageCollectorMxBeans = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMxBeans) { String name = beautifyGcName(garbageCollectorMXBean.getName()); result.add(new Metric<Long>("gc." + name + ".count", garbageCollectorMXBean.getCollectionCount())); result.add(new Metric<Long>("gc." + name + ".time", garbageCollectorMXBean.getCollectionTime())); } }
From source file:gridool.util.system.SystemUtils.java
public static int countGC() { int count = 0; final List<GarbageCollectorMXBean> gclist = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean gcmx : gclist) { count += gcmx.getCollectionCount(); }// ww w .j a v a 2 s . com return count; }
From source file:alluxio.util.JvmPauseMonitor.java
private Map<String, GarbageCollectorMXBean> getGarbageCollectorMXBeans() { List<GarbageCollectorMXBean> gcBeanList = ManagementFactory.getGarbageCollectorMXBeans(); Map<String, GarbageCollectorMXBean> gcBeanMap = new HashMap(); for (GarbageCollectorMXBean gcBean : gcBeanList) { gcBeanMap.put(gcBean.getName(), gcBean); }/* w ww . j a v a2 s. com*/ return gcBeanMap; }
From source file:org.apache.hadoop.hbase.util.JSONMetricUtil.java
public static List<GarbageCollectorMXBean> getGcCollectorBeans() { List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); return gcBeans; }
From source file:org.apache.hyracks.control.nc.NodeControllerService.java
public NodeControllerService(NCConfig ncConfig) throws Exception { this.ncConfig = ncConfig; id = ncConfig.nodeId;//from ww w .j av a 2 s.c o m ipc = new IPCSystem(new InetSocketAddress(ncConfig.clusterNetIPAddress, ncConfig.clusterNetPort), new NodeControllerIPCI(this), new CCNCFunctions.SerializerDeserializer()); ioManager = new IOManager(getDevices(ncConfig.ioDevices)); if (id == null) { throw new Exception("id not set"); } partitionManager = new PartitionManager(this); netManager = new NetworkManager(ncConfig.dataIPAddress, ncConfig.dataPort, partitionManager, ncConfig.nNetThreads, ncConfig.nNetBuffers, ncConfig.dataPublicIPAddress, ncConfig.dataPublicPort, FullFrameChannelInterfaceFactory.INSTANCE); lccm = new LifeCycleComponentManager(); workQueue = new WorkQueue(id, Thread.NORM_PRIORITY); // Reserves MAX_PRIORITY of the heartbeat thread. jobletMap = new Hashtable<>(); timer = new Timer(true); serverCtx = new ServerContext(ServerContext.ServerType.NODE_CONTROLLER, new File(new File(NodeControllerService.class.getName()), id)); memoryMXBean = ManagementFactory.getMemoryMXBean(); gcMXBeans = ManagementFactory.getGarbageCollectorMXBeans(); threadMXBean = ManagementFactory.getThreadMXBean(); runtimeMXBean = ManagementFactory.getRuntimeMXBean(); osMXBean = ManagementFactory.getOperatingSystemMXBean(); registrationPending = true; getNodeControllerInfosAcceptor = new MutableObject<>(); memoryManager = new MemoryManager( (long) (memoryMXBean.getHeapMemoryUsage().getMax() * MEMORY_FUDGE_FACTOR)); ioCounter = new IOCounterFactory().getIOCounter(); }
From source file:fr.inria.wimmics.coresetimer.CoreseTimer.java
private long getGcCount() { long sum = 0; for (GarbageCollectorMXBean b : ManagementFactory.getGarbageCollectorMXBeans()) { long count = b.getCollectionCount(); if (count != -1) { sum += count;/*from w w w. ja va2s .co m*/ } } return sum; }