Skip to content

Commit

Permalink
Merge pull request #19 from bdarfler/memory_pool_stats
Browse files Browse the repository at this point in the history
Tracks memory pool stats (eden, survivor, tenured, etc.)
  • Loading branch information
ajsquared committed Jul 2, 2015
2 parents 0f15862 + b071619 commit 2d54785
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ public class MemoryProfiler extends Profiler {
private List<GarbageCollectorMXBean> gcMXBeans;
private HashMap<GarbageCollectorMXBean, AtomicLong> gcTimes = new HashMap<>();
private ClassLoadingMXBean classLoadingMXBean;
private List<MemoryPoolMXBean> memoryPoolMXBeans;

public MemoryProfiler(Reporter reporter, Arguments arguments) {
super(reporter, arguments);
memoryMXBean = ManagementFactory.getMemoryMXBean();
gcMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
classLoadingMXBean = ManagementFactory.getClassLoadingMXBean();
memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();

for (GarbageCollectorMXBean b : gcMXBeans) gcTimes.put(b, new AtomicLong());
}
Expand Down Expand Up @@ -67,8 +69,8 @@ private void recordStats() {
MemoryUsage nonHeap = memoryMXBean.getNonHeapMemoryUsage();

recordGaugeValue("pending-finalization-count", finalizationPendingCount);
recordMemoryUsage("heap", heap);
recordMemoryUsage("nonheap", nonHeap);
recordMemoryUsage("heap.total", heap);
recordMemoryUsage("nonheap.total", nonHeap);

for (GarbageCollectorMXBean gcMXBean : gcMXBeans) {
recordGaugeValue("gc." + gcMXBean.getName() + ".count", gcMXBean.getCollectionCount());
Expand All @@ -90,6 +92,15 @@ private void recordStats() {
recordGaugeValue("loaded-class-count", loadedClassCount);
recordGaugeValue("total-loaded-class-count", totalLoadedClassCount);
recordGaugeValue("unloaded-class-count", unloadedClassCount);

for (MemoryPoolMXBean memoryPoolMXBean: memoryPoolMXBeans) {
String type = poolTypeToMetricName(memoryPoolMXBean.getType());
String name = poolNameToMetricName(memoryPoolMXBean.getName());
String prefix = type + '.' + name;
MemoryUsage usage = memoryPoolMXBean.getUsage();

recordMemoryUsage(prefix, usage);
}
}

/**
Expand All @@ -104,4 +115,31 @@ private void recordMemoryUsage(String prefix, MemoryUsage memory) {
recordGaugeValue(prefix + ".committed", memory.getCommitted());
recordGaugeValue(prefix + ".max", memory.getMax());
}

/**
* Formats a MemoryType into a valid metric name
*
* @param memoryType a MemoryType
* @return a valid metric name
*/
private String poolTypeToMetricName(MemoryType memoryType) {
switch (memoryType) {
case HEAP:
return "heap";
case NON_HEAP:
return "nonheap";
default:
return "unknown";
}
}

/**
* Formats a pool name into a valid metric name
*
* @param poolName a pool name
* @return a valid metric name
*/
private String poolNameToMetricName(String poolName) {
return poolName.toLowerCase().replaceAll("\\s+", "-");
}
}
12 changes: 6 additions & 6 deletions visualization/influxdb-dashboard/public/scripts/render-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $(document).ready(function() {
config = data;
}
});

var user = params.user;
var job = params.job;
var run = params.run;
Expand All @@ -24,8 +24,8 @@ $(document).ready(function() {

var prefix = base + '.' + user + '.' + job + '.' + run + '.' + stage + '.' + phase;
var cpuPrefix = prefix + '.cpu.trace';
var heapPrefix = prefix + '.heap';
var nonHeapPrefix = prefix + '.nonheap';
var heapPrefix = prefix + '.heap.total';
var nonHeapPrefix = prefix + '.nonheap.total';
var finalizePrefix = prefix + '.pending-finalization-count';
var gcPrefix = prefix + '.gc';

Expand All @@ -34,7 +34,7 @@ $(document).ready(function() {
var gcCountMetrics = [{metric:'PS MarkSweep.count', alias:'PS MarkSweep'},{metric:'PS Scavenge.count', alias:'PS Scavenge'}];
var gcTimeMetrics = [{metric:'PS MarkSweep.time', alias:'PS MarkSweep'},{metric:'PS Scavenge.time', alias:'PS Scavenge'}];
var gcRuntimeMetrics = [{metric:'PS MarkSweep.runtime', alias:'PS MarkSweep'},{metric:'PS Scavenge.runtime', alias:'PS Scavenge'}];

$("#toc ul").append('<li class=toc-h2><a href=/cpu/' + cpuPrefix + ' target=_blank>Flame Graph</a></li>');
$('#toc').affix({
offset: {
Expand All @@ -46,13 +46,13 @@ $(document).ready(function() {
var nonHeapGet = $.get('/data/' + nonHeapPrefix);
var finalizeGet = $.get('/data/' + finalizePrefix);
var gcGet = $.get('/data/' + gcPrefix);

$.when(heapGet, nonHeapGet, finalizeGet, gcGet).done(function() {
var heapResults = heapGet['responseJSON'];
var nonHeapResults = nonHeapGet['responseJSON'];
var finalizeResults = finalizeGet['responseJSON'];
var gcResults = gcGet['responseJSON'];

ViewUtil.renderGraph(heapResults, 'Heap Usage', '#heap', memoryMetrics);
ViewUtil.renderGraph(nonHeapResults, 'Non-Heap Usage', '#nonheap', memoryMetrics);
ViewUtil.renderGraph(finalizeResults, 'Objects Pending Finalization', '#finalize', finalizeMetrics);
Expand Down

0 comments on commit 2d54785

Please sign in to comment.