use of java.lang.management.MemoryUsage in project jdk8u_jdk by JetBrains.
the class MemoryPoolImpl method setUsageThreshold.
public void setUsageThreshold(long newThreshold) {
if (!isUsageThresholdSupported()) {
throw new UnsupportedOperationException("Usage threshold is not supported");
}
Util.checkControlAccess();
MemoryUsage usage = getUsage0();
if (newThreshold < 0) {
throw new IllegalArgumentException("Invalid threshold: " + newThreshold);
}
if (usage.getMax() != -1 && newThreshold > usage.getMax()) {
throw new IllegalArgumentException("Invalid threshold: " + newThreshold + " must be <= maxSize." + " Committed = " + usage.getCommitted() + " Max = " + usage.getMax());
}
synchronized (this) {
if (!usageSensorRegistered) {
// pass the sensor to VM to begin monitoring
usageSensorRegistered = true;
setPoolUsageSensor(usageSensor);
}
setUsageThreshold0(usageThreshold, newThreshold);
this.usageThreshold = newThreshold;
}
}
use of java.lang.management.MemoryUsage in project voltdb by VoltDB.
the class GCInspector method logGCResults.
private void logGCResults() {
for (GarbageCollectorMXBean gc : beans) {
Long previousTotal = gctimes.get(gc.getName());
Long total = gc.getCollectionTime();
if (previousTotal == null)
previousTotal = 0L;
if (previousTotal.equals(total))
continue;
gctimes.put(gc.getName(), total);
// may be zero for a really fast collection
Long duration = total - previousTotal;
Long previousCount = gccounts.get(gc.getName());
Long count = gc.getCollectionCount();
if (previousCount == null)
previousCount = 0L;
if (count.equals(previousCount))
continue;
gccounts.put(gc.getName(), count);
MemoryUsage mu = membean.getHeapMemoryUsage();
long memoryUsed = mu.getUsed();
long memoryMax = mu.getMax();
long durationPerCollection = duration / (count - previousCount);
if (durationPerCollection > MIN_DURATION) {
String st = String.format("GC for %s: %s ms for %s collections, %s used; max is %s", gc.getName(), duration, count - previousCount, memoryUsed, memoryMax);
logger.info(st);
} else if (logger.isDebugEnabled()) {
String st = String.format("GC for %s: %s ms for %s collections, %s used; max is %s", gc.getName(), duration, count - previousCount, memoryUsed, memoryMax);
logger.debug(st);
}
// if we just finished a full collection and we're still using a lot of memory, log
if (newGenGCs.contains(gc.getName())) {
m_voltGcStats.gcInspectorReport(true, (int) (count - previousCount), duration);
}
if (oldGenGCs.contains(gc.getName())) {
m_voltGcStats.gcInspectorReport(false, (int) (count - previousCount), duration);
if (memoryUsed > .5 * memoryMax) {
double usage = (double) memoryUsed / memoryMax;
String usageStr = String.format("%.2f", usage * 100);
//2^20 Bytes
String memoryMaxStr = String.format("%.2f", (double) memoryMax / 1_048_576);
if (.5 <= usage && usage < .6) {
logger.info("Heap is " + usageStr + "% full out of " + memoryMaxStr + "MB.");
} else if (.6 <= usage) {
logger.warn("Heap is " + usageStr + "% full out of " + memoryMaxStr + "MB.");
}
}
}
}
}
use of java.lang.management.MemoryUsage in project hive by apache.
the class JvmMetrics method getMemoryUsage.
private void getMemoryUsage(MetricsRecordBuilder rb) {
MemoryUsage memNonHeap = memoryMXBean.getNonHeapMemoryUsage();
MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage();
Runtime runtime = Runtime.getRuntime();
rb.addGauge(MemNonHeapUsedM, memNonHeap.getUsed() / M).addGauge(MemNonHeapCommittedM, memNonHeap.getCommitted() / M).addGauge(MemNonHeapMaxM, memNonHeap.getMax() / M).addGauge(MemHeapUsedM, memHeap.getUsed() / M).addGauge(MemHeapCommittedM, memHeap.getCommitted() / M).addGauge(MemHeapMaxM, memHeap.getMax() / M).addGauge(MemMaxM, runtime.maxMemory() / M);
}
use of java.lang.management.MemoryUsage in project ignite by apache.
the class GridManagerMxBeanIllegalArgumentHandleTest method createAlwaysFailingMxBean.
/**
* MX bean which is always failing to respond with metrics
*/
@NotNull
private MemoryMXBean createAlwaysFailingMxBean() {
final Answer<MemoryUsage> failingAnswer = new Answer<MemoryUsage>() {
@Override
public MemoryUsage answer(InvocationOnMock invocationOnMock) throws Throwable {
throw new IllegalArgumentException("java.lang.IllegalArgumentException: committed = 5274103808 should be < max = 5274095616");
}
};
final MemoryMXBean memoryMXBean = Mockito.mock(MemoryMXBean.class);
when(memoryMXBean.getHeapMemoryUsage()).thenAnswer(failingAnswer);
when(memoryMXBean.getNonHeapMemoryUsage()).thenAnswer(failingAnswer);
return memoryMXBean;
}
use of java.lang.management.MemoryUsage in project ignite by apache.
the class GridCapacityLoadTest method main.
/**
* Main method.
*
* @param args Parameters.
* @throws Exception If failed.
*/
public static void main(String[] args) throws Exception {
// Initialize Spring factory.
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("org/apache/ignite/loadtests/capacity/spring-capacity-cache.xml");
IgniteConfiguration cfg = (IgniteConfiguration) ctx.getBean("grid.cfg");
try (Ignite g = G.start(cfg)) {
IgniteCache<Integer, Integer> c = g.cache("test-cache");
long init = mem.getHeapMemoryUsage().getUsed();
printHeap(init);
int cnt = 0;
for (; cnt < 3000000; cnt++) {
c.put(cnt, cnt);
if (cnt % 10000 == 0) {
X.println("Stored count: " + cnt);
printHeap(init);
if (cnt > 2100000 && cnt % 100000 == 0)
System.gc();
}
}
System.gc();
Thread.sleep(1000);
printHeap(init);
MemoryUsage heap = mem.getHeapMemoryUsage();
long used = heap.getUsed() - init;
long entrySize = cnt > 0 ? used / cnt : 0;
X.println("Average entry size: " + entrySize);
}
}
Aggregations