浏览代码

MAPREDUCE-2633. Add a getCounter(Enum) method to the Counters record. Contributed by Josh Wills.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/MR-279@1143665 13f79535-47bb-0310-9956-ffa450edef68
Sharad Agarwal 14 年之前
父节点
当前提交
a062038422

+ 3 - 0
mapreduce/CHANGES.txt

@@ -5,6 +5,9 @@ Trunk (unreleased changes)
 
 
     MAPREDUCE-279
     MAPREDUCE-279
 
 
+    MAPREDUCE-2633. Add a getCounter(Enum) method to the Counters record. 
+    (Josh Wills via sharad)
+
     Reinstate resolve path fixes for viewfs. (Siddharth Seth via llu)
     Reinstate resolve path fixes for viewfs. (Siddharth Seth via llu)
 
 
     Major ASM cleanup. Streamlining classes, interface and events. (vinodkv)
     Major ASM cleanup. Streamlining classes, interface and events. (vinodkv)

+ 15 - 33
mapreduce/mr-client/hadoop-mapreduce-client-app/src/main/java/org/apache/hadoop/mapreduce/v2/app/job/impl/TaskAttemptImpl.java

@@ -946,43 +946,25 @@ public abstract class TaskAttemptImpl implements
             (int) (now - start));
             (int) (now - start));
       }
       }
 
 
-      // TODO Fix the Counter API
-      CounterGroup cpuCounterGroup = counters
-          .getCounterGroup(TaskCounter.CPU_MILLISECONDS.getDeclaringClass()
-              .getName());
-      if (cpuCounterGroup != null) {
-        Counter cpuCounter = cpuCounterGroup
-            .getCounter(TaskCounter.CPU_MILLISECONDS.name());
-        if (cpuCounter != null && cpuCounter.getValue() <= Integer.MAX_VALUE) {
-          splitsBlock.getProgressCPUTime().extend(newProgress,
-              (int) cpuCounter.getValue());
-        }
+      Counter cpuCounter = counters.getCounter(
+          TaskCounter.CPU_MILLISECONDS);
+      if (cpuCounter != null && cpuCounter.getValue() <= Integer.MAX_VALUE) {
+        splitsBlock.getProgressCPUTime().extend(newProgress,
+            (int) cpuCounter.getValue());
       }
       }
 
 
-      // TODO Fix the Counter API
-      CounterGroup vbCounterGroup = counters
-          .getCounterGroup(TaskCounter.VIRTUAL_MEMORY_BYTES.getDeclaringClass()
-              .getName());
-      if (vbCounterGroup != null) {
-        Counter virtualBytes = vbCounterGroup
-            .getCounter(TaskCounter.VIRTUAL_MEMORY_BYTES.name());
-        if (virtualBytes != null) {
-          splitsBlock.getProgressVirtualMemoryKbytes().extend(newProgress,
-              (int) (virtualBytes.getValue() / (MEMORY_SPLITS_RESOLUTION)));
-        }
+      Counter virtualBytes = counters.getCounter(
+          TaskCounter.VIRTUAL_MEMORY_BYTES);
+      if (virtualBytes != null) {
+        splitsBlock.getProgressVirtualMemoryKbytes().extend(newProgress,
+            (int) (virtualBytes.getValue() / (MEMORY_SPLITS_RESOLUTION)));
       }
       }
 
 
-      // TODO Fix the Counter API
-      CounterGroup pbCounterGroup = counters
-          .getCounterGroup(TaskCounter.PHYSICAL_MEMORY_BYTES
-              .getDeclaringClass().getName());
-      if (pbCounterGroup != null) {
-        Counter physicalBytes = pbCounterGroup
-            .getCounter(TaskCounter.PHYSICAL_MEMORY_BYTES.name());
-        if (physicalBytes != null) {
-          splitsBlock.getProgressPhysicalMemoryKbytes().extend(newProgress,
-              (int) (physicalBytes.getValue() / (MEMORY_SPLITS_RESOLUTION)));
-        }
+      Counter physicalBytes = counters.getCounter(
+          TaskCounter.PHYSICAL_MEMORY_BYTES);
+      if (physicalBytes != null) {
+        splitsBlock.getProgressPhysicalMemoryKbytes().extend(newProgress,
+            (int) (physicalBytes.getValue() / (MEMORY_SPLITS_RESOLUTION)));
       }
       }
     }
     }
   }
   }

+ 1 - 0
mapreduce/mr-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/api/records/Counters.java

@@ -5,6 +5,7 @@ import java.util.Map;
 public interface Counters {
 public interface Counters {
   public abstract Map<String, CounterGroup> getAllCounterGroups();
   public abstract Map<String, CounterGroup> getAllCounterGroups();
   public abstract CounterGroup getCounterGroup(String key);
   public abstract CounterGroup getCounterGroup(String key);
+  public abstract Counter getCounter(Enum<?> key);
   
   
   public abstract void addAllCounterGroups(Map<String, CounterGroup> counterGroups);
   public abstract void addAllCounterGroups(Map<String, CounterGroup> counterGroups);
   public abstract void setCounterGroup(String key, CounterGroup value);
   public abstract void setCounterGroup(String key, CounterGroup value);

+ 9 - 3
mapreduce/mr-client/hadoop-mapreduce-client-common/src/main/java/org/apache/hadoop/mapreduce/v2/api/records/impl/pb/CountersPBImpl.java

@@ -6,6 +6,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
+import org.apache.hadoop.mapreduce.v2.api.records.Counter;
 import org.apache.hadoop.mapreduce.v2.api.records.CounterGroup;
 import org.apache.hadoop.mapreduce.v2.api.records.CounterGroup;
 import org.apache.hadoop.mapreduce.v2.api.records.Counters;
 import org.apache.hadoop.mapreduce.v2.api.records.Counters;
 import org.apache.hadoop.mapreduce.v2.proto.MRProtos.CounterGroupProto;
 import org.apache.hadoop.mapreduce.v2.proto.MRProtos.CounterGroupProto;
@@ -20,9 +21,9 @@ public class CountersPBImpl extends ProtoBase<CountersProto> implements Counters
   CountersProto proto = CountersProto.getDefaultInstance();
   CountersProto proto = CountersProto.getDefaultInstance();
   CountersProto.Builder builder = null;
   CountersProto.Builder builder = null;
   boolean viaProto = false;
   boolean viaProto = false;
-  
+
   private Map<String, CounterGroup> counterGroups = null;
   private Map<String, CounterGroup> counterGroups = null;
-  
+
   
   
   public CountersPBImpl() {
   public CountersPBImpl() {
     builder = CountersProto.newBuilder();
     builder = CountersProto.newBuilder();
@@ -72,7 +73,12 @@ public class CountersPBImpl extends ProtoBase<CountersProto> implements Counters
     initCounterGroups();
     initCounterGroups();
     return this.counterGroups.get(key);
     return this.counterGroups.get(key);
   }
   }
-  
+  @Override
+  public Counter getCounter(Enum<?> key) {
+    CounterGroup group = getCounterGroup(key.getDeclaringClass().getName());
+    return group == null ? null : group.getCounter(key.name());
+  }
+ 
   private void initCounterGroups() {
   private void initCounterGroups() {
     if (this.counterGroups != null) {
     if (this.counterGroups != null) {
       return;
       return;