pig/src/main/java/com/twitter/elephantbird/pig/util/PigCounterHelper.java
public void incrCounter(String group, String counterName, long incr) {
    PigStatusReporter reporter = PigStatusReporter.getInstance();
    if (reporter != null) { // common case
      Counter counter = reporter.getCounter(group, counterName);
      if (counter != null) {
        HadoopCompat.incrementCounter(counter, incr);

        if (counterStringMap_.size() > 0) {
          for (Map.Entry<Pair<String, String>, Long> entry : counterStringMap_.entrySet()) {
            HadoopCompat.incrementCounter(
                reporter.getCounter(entry.getKey().first, entry.getKey().second),
                entry.getValue());
          }
          counterStringMap_.clear();
        }
        return;
      }
    }
    // In the case when reporter is not available, or we can't get the Counter,
    // store in the local map.
    Pair<String, String> key = new Pair<String, String>(group, counterName);
    Long currentValue = counterStringMap_.get(key);
    counterStringMap_.put(key, (currentValue == null ? 0 : currentValue) + incr);
  }
public void incrCounter(String group, String counterName, long incr) {
    PigStatusReporter reporter = PigStatusReporter.getInstance();
    if (reporter != null) { // common case
      Counter counter = reporter.getCounter(group, counterName);
      if (counter != null) {
        HadoopCompat.incrementCounter(counter, incr);

        if (counterStringMap_.size() > 0) {
          for (Map.Entry<Pair<String, String>, Long> entry : counterStringMap_.entrySet()) {
            HadoopCompat.incrementCounter(
                reporter.getCounter(entry.getKey().first, entry.getKey().second),
                entry.getValue());
          }
          counterStringMap_.clear();
        }
        return;
      }
    }
    // In the case when reporter is not available, or we can't get the Counter,
    // store in the local map.
    Pair<String, String> key = new Pair<String, String>(group, counterName);
    Long currentValue = counterStringMap_.get(key);
    counterStringMap_.put(key, (currentValue == null ? 0 : currentValue) + incr);
  }
Mocks the Reporter.incrCounter, but adds buffering.
See org.apache.hadoop.mapred.Reporter's incrCounter.