001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package EDU.purdue.cs.bloat.inline;
022:
023: import java.io.*;
024: import java.util.*;
025:
026: /**
027: * This class is used to gather statistics about inlining. Examples of such
028: * statistics are the number of call sites virtual methods resolve to and the
029: * number of live classes and methods.
030: */
031: public class InlineStats {
032: private String configName; // Name of configuration
033:
034: private Map morphicity; // Maps morphic number to count
035:
036: private int nLiveClasses; // Number of live classes
037:
038: private int nLiveMethods; // Number of live methods
039:
040: private int nNoPreexist; // Number of non-preexistent calls
041:
042: private int nInlined; // Number of methods inlined
043:
044: public InlineStats() {
045: this .configName = "Inlining stats";
046: this .morphicity = new TreeMap();
047: this .nLiveClasses = 0;
048: this .nLiveMethods = 0;
049: this .nNoPreexist = 0;
050: this .nInlined = 0;
051: }
052:
053: /**
054: * Sets the configuration name for this <tt>InlineStats</tt>.
055: */
056: public void setConfigName(final String configName) {
057: this .configName = configName;
058: }
059:
060: /**
061: * Maintains a count of the number of methods call sites resolve to. May
062: * give an idea as to how "dynamic" a program is.
063: */
064: public void noteMorphicity(final int morphicity) {
065: final Integer r = new Integer(morphicity);
066: final Integer count = (Integer) this .morphicity.get(r);
067: if (count == null) {
068: this .morphicity.put(r, new Integer(1));
069:
070: } else {
071: this .morphicity.put(r, new Integer(count.intValue() + 1));
072: }
073: }
074:
075: /**
076: * Notes that a call site's receiver is not preexistent.
077: */
078: public void noteNoPreexist() {
079: nNoPreexist++;
080: }
081:
082: /**
083: * Notes that a method was inlined
084: */
085: public void noteInlined() {
086: this .nInlined++;
087: }
088:
089: /**
090: * Notes the number of live methods.
091: */
092: public void noteLiveMethods(final int nLiveMethods) {
093: this .nLiveMethods = nLiveMethods;
094: }
095:
096: /**
097: * Notes the number of live classes.
098: */
099: public void noteLiveClasses(final int nLiveClasses) {
100: this .nLiveClasses = nLiveClasses;
101: }
102:
103: /**
104: * Print a summary of the statistics to a <tt>PrintWriter</tt>.
105: */
106: public void printSummary(final PrintWriter pw) {
107: pw.println("Statistics for " + this .configName + " ("
108: + new Date() + ")");
109: pw.println(" Number of live classes: " + this .nLiveClasses);
110: pw.println(" Number of live methods: " + this .nLiveMethods);
111: pw.println(" Call site morphism:");
112:
113: final Iterator morphs = this .morphicity.keySet().iterator();
114: int total = 0;
115: while (morphs.hasNext()) {
116: final Integer morph = (Integer) morphs.next();
117: final Integer count = (Integer) this .morphicity.get(morph);
118: total += count.intValue();
119: pw.println(" " + morph + "\t" + count);
120: }
121: pw.println(" Total number of call sites: " + total);
122: pw.println(" Number of non-preexistent call sites: "
123: + nNoPreexist);
124: pw.println(" Number of inlined methods: " + nInlined);
125:
126: }
127:
128: }
|