use of java.lang.management.MemoryUsage in project spring-boot by spring-projects.
the class SystemPublicMetrics method addHeapMetrics.
/**
* Add JVM heap metrics.
* @param result the result
*/
protected void addHeapMetrics(Collection<Metric<?>> result) {
MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
result.add(newMemoryMetric("heap.committed", memoryUsage.getCommitted()));
result.add(newMemoryMetric("heap.init", memoryUsage.getInit()));
result.add(newMemoryMetric("heap.used", memoryUsage.getUsed()));
result.add(newMemoryMetric("heap", memoryUsage.getMax()));
}
use of java.lang.management.MemoryUsage in project android by JetBrains.
the class GoogleCrash method getDefaultParameters.
@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);
}
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());
// must match registration with Crash
map.put(KEY_PRODUCT_ID, CrashReport.PRODUCT_ANDROID_STUDIO);
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;
}
use of java.lang.management.MemoryUsage in project android by JetBrains.
the class GoogleCrash method createPost.
@NotNull
private HttpUriRequest createPost(@NotNull FlightRecorder flightRecorder, @NotNull String issueText, @NotNull List<Path> logFiles) {
HttpPost post = new HttpPost(myCrashUrl);
ApplicationInfo applicationInfo = getApplicationInfo();
String strictVersion = applicationInfo == null ? "0.0.0.0" : applicationInfo.getStrictVersion();
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
// key names recognized by crash
builder.addTextBody(KEY_PRODUCT_ID, "AndroidStudio");
builder.addTextBody(KEY_VERSION, strictVersion);
builder.addTextBody("exception_info", getUniqueStackTrace());
builder.addTextBody("user_report", issueText);
if (ANONYMIZED_UID != null) {
builder.addTextBody("guid", ANONYMIZED_UID);
}
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
builder.addTextBody("ptime", Long.toString(runtimeMXBean.getUptime()));
// product specific key value pairs
builder.addTextBody("fullVersion", applicationInfo == null ? "0.0.0.0" : applicationInfo.getFullVersion());
builder.addTextBody("osName", StringUtil.notNullize(SystemInfo.OS_NAME));
builder.addTextBody("osVersion", StringUtil.notNullize(SystemInfo.OS_VERSION));
builder.addTextBody("osArch", StringUtil.notNullize(SystemInfo.OS_ARCH));
builder.addTextBody("locale", StringUtil.notNullize(LOCALE));
builder.addTextBody("vmName", StringUtil.notNullize(runtimeMXBean.getVmName()));
builder.addTextBody("vmVendor", StringUtil.notNullize(runtimeMXBean.getVmVendor()));
builder.addTextBody("vmVersion", StringUtil.notNullize(runtimeMXBean.getVmVersion()));
MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
builder.addTextBody("heapUsed", Long.toString(usage.getUsed()));
builder.addTextBody("heapCommitted", Long.toString(usage.getCommitted()));
builder.addTextBody("heapMax", Long.toString(usage.getMax()));
// add report specific data
builder.addTextBody("Type", "InstantRunFlightRecorder");
addFlightRecorderLogs(builder, flightRecorder, logFiles);
post.setEntity(new GzipCompressingEntity(builder.build()));
return post;
}
use of java.lang.management.MemoryUsage in project eiger by wlloyd.
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();
String st = String.format("GC for %s: %s ms for %s collections, %s used; max is %s", gc.getName(), duration, count - previousCount, memoryUsed, memoryMax);
long durationPerCollection = duration / (count - previousCount);
if (durationPerCollection > MIN_DURATION)
logger.info(st);
else if (logger.isDebugEnabled())
logger.debug(st);
if (durationPerCollection > MIN_DURATION_TPSTATS)
StatusLogger.log();
// if we just finished a full collection and we're still using a lot of memory, try to reduce the pressure
if (gc.getName().equals("ConcurrentMarkSweep")) {
SSTableDeletingTask.rescheduleFailedTasks();
double usage = (double) memoryUsed / memoryMax;
if (memoryUsed > DatabaseDescriptor.getReduceCacheSizesAt() * memoryMax && !cacheSizesReduced) {
cacheSizesReduced = true;
logger.warn("Heap is " + usage + " full. You may need to reduce memtable and/or cache sizes. Cassandra is now reducing cache sizes to free up memory. Adjust reduce_cache_sizes_at threshold in cassandra.yaml if you don't want Cassandra to do this automatically");
CacheService.instance.reduceCacheSizes();
}
if (memoryUsed > DatabaseDescriptor.getFlushLargestMemtablesAt() * memoryMax) {
logger.warn("Heap is " + usage + " full. You may need to reduce memtable and/or cache sizes. Cassandra will now flush up to the two largest memtables to free up memory. Adjust flush_largest_memtables_at threshold in cassandra.yaml if you don't want Cassandra to do this automatically");
StorageService.instance.flushLargestMemtables();
}
}
}
}
use of java.lang.management.MemoryUsage in project ignite by apache.
the class GridCapacityLoadTest method printHeap.
private static void printHeap(long init) {
MemoryUsage heap = mem.getHeapMemoryUsage();
long max = heap.getMax() - init;
long used = heap.getUsed() - init;
long left = max - used;
X.println("Heap left: " + (left / (1024 * 1024)) + "MB");
}
Aggregations