本文整理汇总了Java中java.lang.management.MemoryUsage.getUsed方法的典型用法代码示例。如果您正苦于以下问题:Java MemoryUsage.getUsed方法的具体用法?Java MemoryUsage.getUsed怎么用?Java MemoryUsage.getUsed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.management.MemoryUsage
的用法示例。
在下文中一共展示了MemoryUsage.getUsed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reportUsage
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
private void reportUsage(MemoryPoolMXBean mxBean, MetricRecorder.Context metricContext)
{
String name = mxBean.getName();
Metric usedMetric = Metric.define("MemoryPoolUsed_" + name);
Metric maxMetric = Metric.define("MemoryPoolMax_" + name);
Metric percMetric = Metric.define("MemoryPoolUsage_" + name);
MemoryUsage usage = mxBean.getUsage();
long used = usage.getUsed();
long max = usage.getMax();
metricContext.record(usedMetric, used / M, Unit.MEGABYTE);
// max can be undefined (-1) https://docs.oracle.com/javase/8/docs/api/java/lang/management/MemoryUsage.html
if (max >= 0) {
metricContext.record(maxMetric, max / M, Unit.MEGABYTE);
double used_percent = 100.0 * ((double)used/(double)max);
metricContext.record(percMetric, used_percent, Unit.PERCENT);
}
}
示例2: next
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
@Override
public Object next() {
if (!beforeFirst) {
throw new IllegalStateException();
}
beforeFirst = false;
final MemoryInfo memoryInfo = new MemoryInfo();
final DrillbitEndpoint endpoint = context.getIdentity();
memoryInfo.hostname = endpoint.getAddress();
memoryInfo.user_port = endpoint.getUserPort();
final MemoryUsage heapMemoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
memoryInfo.heap_current = heapMemoryUsage.getUsed();
memoryInfo.heap_max = heapMemoryUsage.getMax();
BufferPoolMXBean directBean = getDirectBean();
memoryInfo.jvm_direct_current = directBean.getMemoryUsed();
memoryInfo.direct_current = context.getDrillbitContext().getAllocator().getAllocatedMemory();
memoryInfo.direct_max = TopLevelAllocator.MAXIMUM_DIRECT_MEMORY;
return memoryInfo;
}
示例3: eatMetaspace
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
private List<Object> eatMetaspace(float targetUsage) {
List<Object> list = new ArrayList<>();
MemoryPoolMXBean metaspacePool = getMatchedMemoryPool(".*Metaspace.*");
float currentUsage;
GeneratedClassProducer gp = new GeneratedClassProducer();
do {
try {
list.add(gp.create(0));
} catch (OutOfMemoryError oome) {
list = null;
throw new RuntimeException("Unexpected OOME '" + oome.getMessage() + "' while eating " + targetUsage + " of Metaspace.");
}
MemoryUsage memoryUsage = metaspacePool.getUsage();
currentUsage = (((float) memoryUsage.getUsed()) / memoryUsage.getMax());
} while (currentUsage < targetUsage);
return list;
}
示例4: chore
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
@Override
protected void chore() {
// Sample heap occupancy
MemoryUsage memUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
heapOccupancyPercent = (float)memUsage.getUsed() / (float)memUsage.getCommitted();
// If we are above the heap occupancy alarm low watermark, switch to short
// sleeps for close monitoring. Stop autotuning, we are in a danger zone.
if (heapOccupancyPercent >= heapOccupancyLowWatermark) {
if (!alarming) {
LOG.warn("heapOccupancyPercent " + heapOccupancyPercent +
" is above heap occupancy alarm watermark (" + heapOccupancyLowWatermark + ")");
alarming = true;
}
triggerNow();
try {
// Need to sleep ourselves since we've told the chore's sleeper
// to skip the next sleep cycle.
Thread.sleep(1000);
} catch (InterruptedException e) {
// Interrupted, propagate
Thread.currentThread().interrupt();
}
} else {
if (alarming) {
LOG.info("heapOccupancyPercent " + heapOccupancyPercent +
" is now below the heap occupancy alarm watermark (" +
heapOccupancyLowWatermark + ")");
alarming = false;
}
}
// Autotune if tuning is enabled and allowed
if (tunerOn && !alarming) {
tune();
}
}
示例5: reportHeapUsage
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
private void reportHeapUsage(MemoryMXBean memoryMxBean, MetricRecorder.Context metricContext) {
MemoryUsage usage = memoryMxBean.getHeapMemoryUsage();
long used = usage.getUsed();
metricContext.record(HEAP, used / M, Unit.MEGABYTE);
long max = usage.getMax();
if (max >= 0) {
metricContext.record(HEAP_MAX, max / M, Unit.MEGABYTE);
double used_percent = 100.0 * ((double)used/(double)max);
metricContext.record(HEAP_USED, used_percent, Unit.PERCENT);
}
}
示例6: reportNonHeapUsage
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
private void reportNonHeapUsage(MemoryMXBean memoryMxBean, MetricRecorder.Context metricContext) {
MemoryUsage usage = memoryMxBean.getNonHeapMemoryUsage();
long used = usage.getUsed();
metricContext.record(NON_HEAP, used / M, Unit.MEGABYTE);
long max = usage.getMax();
if (max >= 0) {
metricContext.record(NON_HEAP_MAX, max / M, Unit.MEGABYTE);
double used_percent = 100.0 * ((double)used/(double)max);
metricContext.record(NON_HEAP_USED, used_percent, Unit.PERCENT);
}
}
示例7: call
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
@Override
public Boolean call() throws Exception {
if (this.memBean != null) {
final MemoryUsage usage = this.memBean.getHeapMemoryUsage();
if (usage != null) {
long used = usage.getUsed();
long max = usage.getMax();
final boolean res = used > max * heapLimit;
if (LOG.isLoggable(Level.FINEST)) {
final long now = System.currentTimeMillis();
if (now - lastTime > LOGGER_RATE) {
LOG.log(
Level.FINEST,
"Max memory: {0}, Used memory: {1}, Low memory condition: {2}", //NOI18N
new Object[]{
max,
used,
res
});
lastTime = now;
}
}
return res;
}
}
return false;
}
示例8: testXDMModelSize
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
public void testXDMModelSize() throws Exception {
System.out.println("XDM Mem usage");
MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
long mem0 = usage.getUsed();
javax.swing.text.Document swdoc = Util.getResourceAsDocument("resources/fields.xsd");
usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
long mem1 = usage.getUsed();
long memuse = mem1-mem0;
System.out.println("Document creation = " + memuse + " bytes");
Lookup lookup = Lookups.singleton(swdoc);
usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
long mem2 = usage.getUsed();
ModelSource ms = new ModelSource(lookup, true);
usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
long mem3 = usage.getUsed();
memuse = mem3-mem2;
System.out.println("Model source creation = " + memuse + " bytes");
XDMModel m = new XDMModel(ms);
m.sync();
usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
long mem4 = usage.getUsed();
memuse = mem4-mem3;
System.out.println("XDM creation = " + memuse + " bytes");
//System.out.println("Time taken to create XDM model: " + (endTime - startTime));
}
示例9: Datum
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
/**
* Constructor accepts some system values and generates some Java values.
*
* @param rss Resident set size.
*/
Datum(long rss) {
MemoryMXBean mmxb = ManagementFactory.getMemoryMXBean();
MemoryUsage muheap = mmxb.getHeapMemoryUsage();
MemoryUsage musys = mmxb.getNonHeapMemoryUsage();
timestamp = System.currentTimeMillis();
this.rss = rss;
javatotalheapmem = muheap.getCommitted();
javausedheapmem = muheap.getUsed();
javatotalsysmem = musys.getCommitted();
javausedsysmem = musys.getUsed();
}
示例10: isUsageThresholdExceeded
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
public boolean isUsageThresholdExceeded() {
if (!isUsageThresholdSupported()) {
throw new UnsupportedOperationException(
"Usage threshold is not supported");
}
// return false if usage threshold crossing checking is disabled
if (usageThreshold == 0) {
return false;
}
MemoryUsage u = getUsage0();
return (u.getUsed() >= usageThreshold ||
usageSensor.isOn());
}
示例11: isCollectionUsageThresholdExceeded
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
public boolean isCollectionUsageThresholdExceeded() {
if (!isCollectionUsageThresholdSupported()) {
throw new UnsupportedOperationException(
"CollectionUsage threshold is not supported");
}
// return false if usage threshold crossing checking is disabled
if (collectionThreshold == 0) {
return false;
}
MemoryUsage u = getCollectionUsage0();
return (gcSensor.isOn() ||
(u != null && u.getUsed() >= collectionThreshold));
}
示例12: printMemoryUsage
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
void printMemoryUsage() {
if (options.verbose) {
MemoryUsage memusage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
float freeratio = 1f - (float) memusage.getUsed() / memusage.getCommitted();
log.format(" [used: %-7s, comm: %-7s, freeRatio ~= %.1f%%]",
humanReadableByteCount(memusage.getUsed()),
humanReadableByteCount(memusage.getCommitted()),
freeratio * 100);
}
}
示例13: printMemoryUsage
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
public static void printMemoryUsage(String label) {
MemoryUsage memusage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
float freeratio = 1f - (float) memusage.getUsed() / memusage.getCommitted();
System.out.format("[%-24s] init: %-7s, used: %-7s, comm: %-7s, freeRatio ~= %.1f%%%n",
label,
NF.format(memusage.getInit()),
NF.format(memusage.getUsed()),
NF.format(memusage.getCommitted()),
freeratio * 100
);
}
示例14: jvmStats
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
public static JvmStats jvmStats() {
MemoryUsage memUsage = memoryMXBean.getHeapMemoryUsage();
long heapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
long heapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
long heapMax = memUsage.getMax() < 0 ? 0 : memUsage.getMax();
memUsage = memoryMXBean.getNonHeapMemoryUsage();
long nonHeapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
long nonHeapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
List<MemoryPool> pools = new ArrayList<>();
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
try {
MemoryUsage usage = memoryPoolMXBean.getUsage();
MemoryUsage peakUsage = memoryPoolMXBean.getPeakUsage();
String name = GcNames.getByMemoryPoolName(memoryPoolMXBean.getName(), null);
if (name == null) { // if we can't resolve it, its not interesting.... (Per Gen, Code Cache)
continue;
}
pools.add(new MemoryPool(name,
usage.getUsed() < 0 ? 0 : usage.getUsed(),
usage.getMax() < 0 ? 0 : usage.getMax(),
peakUsage.getUsed() < 0 ? 0 : peakUsage.getUsed(),
peakUsage.getMax() < 0 ? 0 : peakUsage.getMax()
));
} catch (Exception ex) {
/* ignore some JVMs might barf here with:
* java.lang.InternalError: Memory Pool not found
* we just omit the pool in that case!*/
}
}
Mem mem = new Mem(heapCommitted, heapUsed, heapMax, nonHeapCommitted, nonHeapUsed, Collections.unmodifiableList(pools));
Threads threads = new Threads(threadMXBean.getThreadCount(), threadMXBean.getPeakThreadCount());
List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
GarbageCollector[] collectors = new GarbageCollector[gcMxBeans.size()];
for (int i = 0; i < collectors.length; i++) {
GarbageCollectorMXBean gcMxBean = gcMxBeans.get(i);
collectors[i] = new GarbageCollector(GcNames.getByGcName(gcMxBean.getName(), gcMxBean.getName()),
gcMxBean.getCollectionCount(), gcMxBean.getCollectionTime());
}
GarbageCollectors garbageCollectors = new GarbageCollectors(collectors);
List<BufferPool> bufferPoolsList = Collections.emptyList();
try {
List<BufferPoolMXBean> bufferPools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
bufferPoolsList = new ArrayList<>(bufferPools.size());
for (BufferPoolMXBean bufferPool : bufferPools) {
bufferPoolsList.add(new BufferPool(bufferPool.getName(), bufferPool.getCount(),
bufferPool.getTotalCapacity(), bufferPool.getMemoryUsed()));
}
} catch (Exception e) {
// buffer pools are not available
}
Classes classes = new Classes(classLoadingMXBean.getLoadedClassCount(), classLoadingMXBean.getTotalLoadedClassCount(),
classLoadingMXBean.getUnloadedClassCount());
return new JvmStats(System.currentTimeMillis(), runtimeMXBean.getUptime(), mem, threads,
garbageCollectors, bufferPoolsList, classes);
}
示例15: getCurrentUsageRatio
import java.lang.management.MemoryUsage; //导入方法依赖的package包/类
private double getCurrentUsageRatio() {
final MemoryUsage memoryUsage = memoryPool.getMemoryUsage();
return memoryUsage.getUsed() * 100d / memoryUsage.getMax();
}