org.apache.hadoop.mapred
Class Counters

java.lang.Object
  extended by org.apache.hadoop.mapred.Counters
All Implemented Interfaces:
Writable

public class Counters
extends Object
implements Writable

A set of named counters.

Counters represent global counters, defined either by the Map-Reduce framework or applications. Each Counter can be of any Enum type.

Counters are bunched into Counters.Groups, each comprising of counters from a particular Enum class.


Nested Class Summary
static class Counters.Group
          Group of counters, comprising of counters from a particular counter Enum class.
 
Constructor Summary
Counters()
           
 
Method Summary
 long getCounter(Enum key)
          Returns current value of the specified counter, or 0 if the counter does not exist.
 Counters.Group getGroup(String groupName)
          Returns the named counter group, or an empty group if there is none with the specified name.
 Collection<String> getGroupNames()
          Returns the names of all counter classes.
 void incrAllCounters(Counters other)
          Increments multiple counters by their amounts in another Counters instance.
 void incrCounter(Enum key, long amount)
          Increments the specified counter by the specified amount, creating it if it didn't already exist.
 void log(org.apache.commons.logging.Log log)
          Logs the current counter values.
 void readFields(DataInput in)
          Deserialize the fields of this object from in.
 int size()
          Returns the total number of counters, by summing the number of counters in each group.
static Counters sum(Counters a, Counters b)
          Convenience method for computing the sum of two sets of counters.
 String toString()
          Return textual representation of the counter values.
 void write(DataOutput out)
          Serialize the fields of this object to out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Counters

public Counters()
Method Detail

getGroupNames

public Collection<String> getGroupNames()
Returns the names of all counter classes.

Returns:
Set of counter names.

getGroup

public Counters.Group getGroup(String groupName)
Returns the named counter group, or an empty group if there is none with the specified name.


incrCounter

public void incrCounter(Enum key,
                        long amount)
Increments the specified counter by the specified amount, creating it if it didn't already exist.

Parameters:
key - identifies a counter
amount - amount by which counter is to be incremented

getCounter

public long getCounter(Enum key)
Returns current value of the specified counter, or 0 if the counter does not exist.


incrAllCounters

public void incrAllCounters(Counters other)
Increments multiple counters by their amounts in another Counters instance.

Parameters:
other - the other Counters instance

sum

public static Counters sum(Counters a,
                           Counters b)
Convenience method for computing the sum of two sets of counters.


size

public int size()
Returns the total number of counters, by summing the number of counters in each group.


write

public void write(DataOutput out)
           throws IOException
Description copied from interface: Writable
Serialize the fields of this object to out.

Specified by:
write in interface Writable
Parameters:
out - DataOuput to serialize this object into.
Throws:
IOException

readFields

public void readFields(DataInput in)
                throws IOException
Description copied from interface: Writable
Deserialize the fields of this object from in.

For efficiency, implementations should attempt to re-use storage in the existing object where possible.

Specified by:
readFields in interface Writable
Parameters:
in - DataInput to deseriablize this object from.
Throws:
IOException

log

public void log(org.apache.commons.logging.Log log)
Logs the current counter values.

Parameters:
log - The log to use.

toString

public String toString()
Return textual representation of the counter values.

Overrides:
toString in class Object


Copyright © 2006 The Apache Software Foundation