private JSONObject getCountersJson(Counters ctrs) throws JSONException { JSONObject countersJson = new JSONObject(); Iterator<Counters.Group> iterator = ctrs.iterator(); while(iterator.hasNext()) { Counters.Group group = iterator.next(); Iterator<Counters.Counter> groupIterator = group.iterator(); JSONObject groupJson = new JSONObject(); while(groupIterator.hasNext()) { Counters.Counter counter = groupIterator.next(); groupJson.put(counter.getDisplayName(), counter.getCounter()); } countersJson.put(group.getDisplayName(), groupJson); } return countersJson; }
@Test public void testFileSystemGroupIteratorConcurrency() { Counters counters = new Counters(); // create 2 filesystem counter groups counters.findCounter("fs1", FileSystemCounter.BYTES_READ).increment(1); counters.findCounter("fs2", FileSystemCounter.BYTES_READ).increment(1); // Iterate over the counters in this group while updating counters in // the group Group group = counters.getGroup(FileSystemCounter.class.getName()); Iterator<Counter> iterator = group.iterator(); counters.findCounter("fs3", FileSystemCounter.BYTES_READ).increment(1); assertTrue(iterator.hasNext()); iterator.next(); counters.findCounter("fs3", FileSystemCounter.BYTES_READ).increment(1); assertTrue(iterator.hasNext()); iterator.next(); }
@SuppressWarnings("deprecation") @Test public void testGroupIteratorConcurrency() { Counters counters = new Counters(); counters.incrCounter("group1", "counter1", 1); Group group = counters.getGroup("group1"); Iterator<Counter> iterator = group.iterator(); counters.incrCounter("group1", "counter2", 1); iterator.next(); }
Iterator<Counter> it = groupCounters.iterator(); while (it.hasNext()) { try {
Group reduceGroup = reduceCounters.getGroup(groupName); Format decimal = new DecimalFormat(); Iterator<Counter> ctrItr = totalGroup.iterator(); while (ctrItr.hasNext()) { Counter counter = ctrItr.next();
/** * @return the name of all counters */ public Collection<Pair<String, String>> findCounterValues() { final Collection<Pair<String, String>> counters = new LinkedList<Pair<String, String>>(); final Iterable<String> groupNames = getGroupNames(); if (mapred != null) { for (String groupName : groupNames) { final Group group = mapred.getGroup(groupName); collectCounters(counters, groupName, group.iterator()); } } else { for (String groupName : groupNames) { final CounterGroup group = mapreduce.getGroup(groupName); collectCounters(counters, groupName, group.iterator()); } } return counters; }
private static List<Counter> getAllFromHadoopGroup(org.apache.hadoop.mapred.Counters.Group counterGroup) { Iterator<org.apache.hadoop.mapred.Counters.Counter> counterIterator = counterGroup.iterator(); List<Counter> counters = new ArrayList<>(); while (counterIterator.hasNext()) { org.apache.hadoop.mapred.Counters.Counter counter = counterIterator.next(); counters.add(new Counter(counterGroup.getName(), counter.getName(), counter.getValue())); } return counters; }
@Override public synchronized boolean equals(Object genericRight) { if (genericRight instanceof CounterGroupBase<?>) { @SuppressWarnings("unchecked") CounterGroupBase<Counter> right = ((CounterGroupBase<Counter>) genericRight).getUnderlyingGroup(); return Iterators.elementsEqual(iterator(), right.iterator()); } return false; }
@Override public synchronized boolean equals(Object genericRight) { if (genericRight instanceof CounterGroupBase<?>) { @SuppressWarnings("unchecked") CounterGroupBase<Counter> right = ((CounterGroupBase<Counter>) genericRight).getUnderlyingGroup(); return Iterators.elementsEqual(iterator(), right.iterator()); } return false; }
@Override public synchronized boolean equals(Object genericRight) { if (genericRight instanceof CounterGroupBase<?>) { @SuppressWarnings("unchecked") CounterGroupBase<Counter> right = ((CounterGroupBase<Counter>) genericRight).getUnderlyingGroup(); return Iterators.elementsEqual(iterator(), right.iterator()); } return false; }
@Override public synchronized boolean equals(Object genericRight) { if (genericRight instanceof CounterGroupBase<?>) { @SuppressWarnings("unchecked") CounterGroupBase<Counter> right = ((CounterGroupBase<Counter>) genericRight).getUnderlyingGroup(); return Iterators.elementsEqual(iterator(), right.iterator()); } return false; }