org.apache.hadoop.mapred
Class Counters

java.lang.Object
  extended by org.apache.hadoop.mapreduce.counters.AbstractCounters<Counters.Counter,Counters.Group>
      extended by org.apache.hadoop.mapred.Counters
All Implemented Interfaces:
Iterable<Counters.Group>, Writable

@InterfaceAudience.Public
@InterfaceStability.Stable
public class Counters
extends AbstractCounters<Counters.Counter,Counters.Group>

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.Counter
          A counter record, comprising its name and value.
static class Counters.Group
          Group of counters, comprising of counters from a particular counter Enum class.
 
Field Summary
static int MAX_COUNTER_LIMIT
           
static int MAX_GROUP_LIMIT
           
 
Fields inherited from class org.apache.hadoop.mapreduce.counters.AbstractCounters
LOG
 
Constructor Summary
Counters()
           
Counters(Counters newCounters)
           
 
Method Summary
 Counters.Counter findCounter(String group, int id, String name)
          Deprecated. use findCounter(String, String) instead
 Counters.Counter findCounter(String group, String name)
          Find a counter, create one if necessary
static Counters fromEscapedCompactString(String compactString)
          Convert a stringified (by makeEscapedCompactString() counter representation into a counter object.
 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 incrCounter(String group, String counter, 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.
 String makeCompactString()
           
 String makeEscapedCompactString()
          Represent the counter in a textual format that can be converted back to its object form
 int size()
          Deprecated. use AbstractCounters.countCounters() instead
static Counters sum(Counters a, Counters b)
          Convenience method for computing the sum of two sets of counters.
 
Methods inherited from class org.apache.hadoop.mapreduce.counters.AbstractCounters
countCounters, equals, findCounter, hashCode, incrAllCounters, iterator, readFields, toString, write
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_COUNTER_LIMIT

public static int MAX_COUNTER_LIMIT

MAX_GROUP_LIMIT

public static int MAX_GROUP_LIMIT
Constructor Detail

Counters

public Counters()

Counters

public Counters(Counters newCounters)
Method Detail

getGroup

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

Overrides:
getGroup in class AbstractCounters<Counters.Counter,Counters.Group>
Parameters:
groupName - name of the group
Returns:
the group

getGroupNames

public Collection<String> getGroupNames()
Description copied from class: AbstractCounters
Returns the names of all counter classes.

Overrides:
getGroupNames in class AbstractCounters<Counters.Counter,Counters.Group>
Returns:
Set of counter names.

makeCompactString

public String makeCompactString()

findCounter

public Counters.Counter findCounter(String group,
                                    String name)
Description copied from class: AbstractCounters
Find a counter, create one if necessary

Overrides:
findCounter in class AbstractCounters<Counters.Counter,Counters.Group>
Parameters:
group - of the counter
name - name of the counter
Returns:
the matching counter

findCounter

@Deprecated
public Counters.Counter findCounter(String group,
                                               int id,
                                               String name)
Deprecated. use findCounter(String, String) instead

Find a counter by using strings

Parameters:
group - the name of the group
id - the id of the counter within the group (0 to N-1)
name - the internal name of the counter
Returns:
the counter for that 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

incrCounter

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

Parameters:
group - the name of the group
counter - the internal name of the 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.

Parameters:
key - the counter enum to lookup
Returns:
the counter value or 0 if counter not found

incrAllCounters

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

Parameters:
other - the other Counters instance

size

public int size()
Deprecated. use AbstractCounters.countCounters() instead

Returns:
the total number of counters

sum

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

Parameters:
a - the first counters
b - the second counters
Returns:
a new summed counters object

log

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

Parameters:
log - The log to use.

makeEscapedCompactString

public String makeEscapedCompactString()
Represent the counter in a textual format that can be converted back to its object form

Returns:
the string in the following format {(groupName)(group-displayName)[(counterName)(displayName)(value)][]*}*

fromEscapedCompactString

public static Counters fromEscapedCompactString(String compactString)
                                         throws ParseException
Convert a stringified (by makeEscapedCompactString() counter representation into a counter object.

Parameters:
compactString - to parse
Returns:
a new counters object
Throws:
ParseException


Copyright © 2014 Apache Software Foundation. All Rights Reserved.