| |   |
| /* |
| * $Id$ |
| * |
| * Copyright (C) 2003-2009 JNode.org |
| * |
| * This library is free software; you can redistribute it and/or modify it |
| * under the terms of the GNU Lesser General Public License as published |
| * by the Free Software Foundation; either version 2.1 of the License, or |
| * (at your option) any later version. |
| * |
| * This library is distributed in the hope that it will be useful, but |
| * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| * License for more details. |
| * |
| * You should have received a copy of the GNU Lesser General Public License |
| * along with this library; If not, write to the Free Software Foundation, Inc., |
| * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| */ |
|
| package org.jnode.vm.memmgr.generational; |
|
| import org.jnode.vm.VmSystem; |
| import org.jnode.vm.memmgr.GCStatistics; |
|
| final class GenGCStatCounter extends GCStatistics { |
|
| private String title; |
| private long lastDuration; |
| private long lastPauseDuration; |
| private long avgDuration; |
| private long avgPauseDuration; |
| private long lastExecutionDate; |
| private long firstExecutionDate = -1L; |
| private long nbExecutions = 0L; |
|
| public GenGCStatCounter(String title) { |
| this.title = title; |
| } |
| |
| public void addExecutionDuration(long duration) { |
| long currentDate = currentMillis(); |
| lastDuration = duration; |
| lastPauseDuration = lastExecutionDate - currentDate; |
| avgDuration = computeAvg(lastDuration, avgDuration); |
| avgPauseDuration = computeAvg(lastPauseDuration, avgPauseDuration); |
| lastExecutionDate = currentDate; |
| if (firstExecutionDate < 0L) { |
| firstExecutionDate = currentDate; |
| } |
| nbExecutions++; |
| } |
| |
| @Override |
| public String toString() { |
| return "--------------------\n\t" + |
| title + "--------------------\n" + |
| addString("last duration", lastDuration, "ms") + |
| addString("last pause duration", lastPauseDuration, "ms") + |
| addString("average duration", avgDuration, "ms") + |
| addString("average pause duration", avgPauseDuration, "ms") + |
| addString("last execution", currentMillis() - lastExecutionDate, "ms ago") + |
| addString("overhead", getOverhead()) + |
| addString("time executed", nbExecutions) + |
| "--------------------\n"; |
| } |
|
| private String addString(String property, long value) { |
| return addString(property, value, ""); |
| } |
|
| private String addString(String property, long value, String unit) { |
| return property + ": " + value + " " + unit; |
| } |
| |
| private long getOverhead() { |
| return (100 * avgDuration) / (lastExecutionDate - firstExecutionDate); |
| } |
|
| private long currentMillis() { |
| return VmSystem.currentKernelMillis(); |
| } |
| |
| private long computeAvg(long newValue, long previousAvg) { |
| return (previousAvg * nbExecutions + newValue) / (nbExecutions + 1); |
| } |
| } |