Commit 96690e97fcd72de0ef3ee6e6423a86d51f966cb3

  • avatar
  • loic <loic @x37-l…top.(none)>
  • Tue Feb 02 17:53:32 CET 2010
Add a statistics utilities for gc stats
  
1/*
2 * $Id$
3 *
4 * Copyright (C) 2003-2009 JNode.org
5 *
6 * This library is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 * License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library; If not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21package org.jnode.vm.memmgr.generational;
22
23import org.jnode.vm.VmSystem;
24import org.jnode.vm.memmgr.GCStatistics;
25
26final class GenGCStatCounter extends GCStatistics {
27
28 private String title;
29 private long lastDuration;
30 private long lastPauseDuration;
31 private long avgDuration;
32 private long avgPauseDuration;
33 private long lastExecutionDate;
34 private long firstExecutionDate = -1L;
35 private long nbExecutions = 0L;
36
37 public GenGCStatCounter(String title) {
38 this.title = title;
39 }
40
41 public void addExecutionDuration(long duration) {
42 long currentDate = currentMillis();
43 lastDuration = duration;
44 lastPauseDuration = lastExecutionDate - currentDate;
45 avgDuration = computeAvg(lastDuration, avgDuration);
46 avgPauseDuration = computeAvg(lastPauseDuration, avgPauseDuration);
47 lastExecutionDate = currentDate;
48 if (firstExecutionDate < 0L) {
49 firstExecutionDate = currentDate;
50 }
51 nbExecutions++;
52 }
53
54 @Override
55 public String toString() {
56 return "--------------------\n\t" +
57 title + "--------------------\n" +
58 addString("last duration", lastDuration, "ms") +
59 addString("last pause duration", lastPauseDuration, "ms") +
60 addString("average duration", avgDuration, "ms") +
61 addString("average pause duration", avgPauseDuration, "ms") +
62 addString("last execution", currentMillis() - lastExecutionDate, "ms ago") +
63 addString("overhead", getOverhead()) +
64 addString("time executed", nbExecutions) +
65 "--------------------\n";
66 }
67
68 private String addString(String property, long value) {
69 return addString(property, value, "");
70 }
71
72 private String addString(String property, long value, String unit) {
73 return property + ": " + value + " " + unit;
74 }
75
76 private long getOverhead() {
77 return (100 * avgDuration) / (lastExecutionDate - firstExecutionDate);
78 }
79
80 private long currentMillis() {
81 return VmSystem.currentKernelMillis();
82 }
83
84 private long computeAvg(long newValue, long previousAvg) {
85 return (previousAvg * nbExecutions + newValue) / (nbExecutions + 1);
86 }
87}