asysmon-res.js.ctrl-memgc.js Maven / Gradle / Ivy
angular.module('ASysMonApp').controller('CtrlMemGc', function($scope, $log, Rest) {
$('.btn').tooltip({
container: 'body',
html: true
});
//TODO display committed and maximum memory
//TODO get 'current' memory consumption in addition to GC requests
//TODO tool tip: left or right, depending on x coordinate
$scope.safeApply = function(fn) {
var phase = this.$root.$$phase;
if(phase == '$apply' || phase == '$digest') {
if(fn && (typeof(fn) === 'function')) {
fn();
}
} else {
this.$apply(fn);
}
};
$scope.showFullGcMarkers = true;
$scope.$watch('showFullGcMarkers', function() {
if($scope.gcs) {
$scope.dataAsMap['_full_'].points.show = $scope.showFullGcMarkers;
extractGcMarkings($scope.gcs);
doPlot();
}
});
$scope.showOtherGcMarkers = false;
$scope.$watch('showOtherGcMarkers', function() {
if($scope.gcs) {
extractGcMarkings($scope.gcs);
doPlot();
}
});
$scope.showLegend = true;
$scope.$watch('showLegend', function() {
if($scope.gcs) {
doPlot();
}
});
function endMillis(gc) {
return gc.durationNanos < 1000*1000 ? gc.startMillis : (gc.startMillis + gc.durationNanos / 1000 / 1000);
}
function isFullGc(gc) {
return gc.type.indexOf(' major ') !== -1;
}
function extractGcMarkings(gcs) {
$scope.gcMarkings = [];
for(var i=0; i $scope.xMaxData) {
// negative value for right overpan
overPan = $scope.xMaxDisplay - $scope.xMaxData;
}
var offsetAbs = ($scope.xMinDisplay - $scope.xMinData);
if(overPan < 0) {
offsetAbs -= overPan;
}
var visibleAbs = $scope.xMaxDisplay - $scope.xMinDisplay - Math.abs(overPan);
var dataRange = $scope.xMaxData - $scope.xMinData;
return {
percentOffset: offsetAbs / dataRange * 100,
percentVisible: visibleAbs / dataRange * 100
};
}
$scope.getZoomMinPercent = function() {
return presentationZoomPercents().percentOffset;
};
$scope.getZoomVisiblePercent = function() {
return presentationZoomPercents().percentVisible;
};
$scope.zoomIn = function() {
plot.zoom();
};
$scope.zoomOut = function() {
plot.zoomOut();
};
$scope.zoomReset = function() {
plot.getAxes().xaxis.min = $scope.xMinData;
plot.getAxes().xaxis.max = $scope.xMaxData;
$scope.xMinDisplay = $scope.xMinData;
$scope.xMaxDisplay = $scope.xMaxData;
doPlot();
};
function refreshZoom(evt, plot) {
$scope.safeApply(function() {
var xaxis = plot.getAxes().xaxis;
$scope.xMinDisplay = xaxis.min;
$scope.xMaxDisplay = xaxis.max;
});
}
//TODO limit zoom, limit pan
$('#mem-gc-placeholder')
.bind('plotzoom', refreshZoom)
.bind('plotpan', refreshZoom);
(function() {
var previousPoint = null;
function tooltipFor(item) {
for(var i=0; i<$scope.gcs.length; i++) {
var gc = $scope.gcs[i];
if(gc.startMillis !== item.datapoint[0]) { //TODO is there a better way to do this?
continue;
}
//TODO layout of tool tip
//TODO relative change of used memory per memgc kind
//TODO *committed* memory (+ info if changed)
return 'cause: ' + gc.cause + '
' +
'type: ' + gc.type + '
' +
'algorithm: ' + gc.algorithm + '
' +
'duration: ' + gc.durationNanos + 'ns';
}
return '';
}
$('#mem-gc-placeholder').bind("plothover", function (event, pos, item) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
$("#tooltip").remove();
var x = item.datapoint[0];
var y = item.datapoint[1];
// var text = 'moin moin: ' + item.series.label;
showTooltip(item.pageX, item.pageY, tooltipFor(item));
// months[x- 1] + "
" + "" + y + " (" + item.series.label + ")");
}
}
else {
$("#tooltip").remove();
previousPoint = null;
}
});
//TODO nicer styling, move styling to CSS file
function showTooltip(x, y, contents) {
$('' + contents + '').css({
position: 'absolute',
display: 'none',
top: y + 5,
left: x + 20,
border: '2px solid #4572A7',
padding: '2px',
size: '10',
'background-color': '#fff',
opacity: 0.90
}).appendTo("body").fadeIn(200);
}
}());
});