01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.cldchi.tools.memoryprofiler.data;
28:
29: /**
30: * This class is container for all statististics for a Java Class.
31: * It provides the following information: number of objects, total size of all object of the class,
32: * percentage of live objects, percentage of old generation objects
33: *
34: * @see com.sun.cldchi.tools.memoryprofiler.data.MPDataProvider
35: *
36: */
37: public class ClassStatistics {
38: public final String _class_name;
39: private int _count;
40: private int _total_size;
41: private static int _total_heap_size;
42: private int _dead_size;
43: private int _old_gen_size;
44:
45: public ClassStatistics(String class_name) {
46: _class_name = class_name;
47: _count = _total_size = _dead_size = _old_gen_size = 0;
48: }
49:
50: public int getHeapPercentage() {
51: if (_total_heap_size == 0)
52: return 0;
53: return (10000 * _total_size) / _total_heap_size;
54: }
55:
56: public int getAverageSize() {
57: if (_count == 0)
58: return 0;
59: return _total_size / _count;
60: }
61:
62: public int getLivePercentage() {
63: if (_total_size == 0)
64: return 0;
65: return (10000 * (_total_size - _dead_size)) / _total_size;
66: }
67:
68: public int getOldGenPercentage() {
69: if (_total_size == 0)
70: return 0;
71: return (10000 * _old_gen_size) / _total_size;
72: }
73:
74: public void add(JavaObject obj, int old_gen_end) {
75: _total_heap_size += obj.size;
76: _count++;
77: _total_size += obj.size;
78: if (!obj.alive()) {
79: _dead_size += obj.size;
80: }
81: if (obj.address < old_gen_end) {
82: _old_gen_size += obj.size;
83: }
84: }
85:
86: public static void reset() {
87: _total_heap_size = 0;
88: }
89:
90: public int getCount() {
91: return _count;
92: }
93:
94: public int getTotalSize() {
95: return _total_size;
96: }
97: }
|