001/* 002 * This file is part of the Jikes RVM project (http://jikesrvm.org). 003 * 004 * This file is licensed to You under the Eclipse Public License (EPL); 005 * You may not use this file except in compliance with the License. You 006 * may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/eclipse-1.0.php 009 * 010 * See the COPYRIGHT.txt file distributed with this work for information 011 * regarding copyright ownership. 012 */ 013package org.mmtk.utility.statistics; 014 015import org.vmmagic.pragma.*; 016 017/** 018 * This class implements a simple counter of events of different sizes 019 * (eg object allocations, where total number of objects and total 020 * volume of objects would be counted).<p> 021 * 022 * The counter is trivially composed from two event counters (one for 023 * counting the number of events, the other for counting the volume). 024 */ 025@Uninterruptible 026public class SizeCounter { 027 028 /**************************************************************************** 029 * 030 * Instance variables 031 */ 032 033 /** 034 * 035 */ 036 private final EventCounter units; 037 private final EventCounter volume; 038 039 /**************************************************************************** 040 * 041 * Initialization 042 */ 043 044 /** 045 * Constructor 046 * 047 * @param name The name to be associated with this counter 048 */ 049 public SizeCounter(String name) { 050 this(name, true, false); 051 } 052 053 /** 054 * Constructor 055 * 056 * @param name The name to be associated with this counter 057 * @param start True if this counter is to be implicitly started 058 * when <code>startAll()</code> is called (otherwise the counter 059 * must be explicitly started). 060 */ 061 public SizeCounter(String name, boolean start) { 062 this(name, start, false); 063 } 064 065 /** 066 * Constructor 067 * 068 * @param name The name to be associated with this counter 069 * @param start True if this counter is to be implicitly started 070 * when <code>startAll()</code> is called (otherwise the counter 071 * must be explicitly started). 072 * @param mergephases True if this counter does not separately 073 * report GC and Mutator phases. 074 */ 075 public SizeCounter(String name, boolean start, boolean mergephases) { 076 units = new EventCounter(name, start, mergephases); 077 volume = new EventCounter(name + "Volume", start, mergephases); 078 } 079 080 /**************************************************************************** 081 * 082 * Counter-specific methods 083 */ 084 085 /** 086 * Increment the event counter by <code>value</code> 087 * 088 * @param value The amount by which the counter should be incremented. 089 */ 090 public void inc(int value) { 091 units.inc(); 092 volume.inc(value); 093 } 094 095 /**************************************************************************** 096 * 097 * Generic counter control methods: start, stop, print etc 098 */ 099 100 /** 101 * Start this counter 102 */ 103 public void start() { 104 units.start(); 105 volume.start(); 106 } 107 108 /** 109 * Stop this counter 110 */ 111 public void stop() { 112 units.stop(); 113 volume.stop(); 114 } 115 116 /** 117 * Print current (mid-phase) units 118 */ 119 public void printCurrentUnits() { 120 units.printCurrent(); 121 } 122 123 /** 124 * Print (mid-phase) volume 125 */ 126 public void printCurrentVolume() { 127 volume.printCurrent(); 128 } 129 130 /** 131 * Print units 132 */ 133 public void printUnits() { 134 units.printTotal(); 135 } 136 137 /** 138 * Print volume 139 */ 140 public void printVolume() { 141 volume.printTotal(); 142 } 143}