TEZ-3940. Reduce time to convert TaskFinishedEvent to string (Jonathan Eagles via...
authorJason Lowe <jlowe@apache.org>
Thu, 24 May 2018 13:44:03 +0000 (08:44 -0500)
committerJason Lowe <jlowe@apache.org>
Thu, 24 May 2018 13:44:03 +0000 (08:44 -0500)
tez-dag/src/main/java/org/apache/tez/dag/history/events/TaskAttemptFinishedEvent.java
tez-dag/src/main/java/org/apache/tez/dag/history/events/TaskFinishedEvent.java

index 96dc099..1859649 100644 (file)
@@ -25,6 +25,8 @@ import java.util.List;
 import com.google.protobuf.CodedInputStream;
 import com.google.protobuf.CodedOutputStream;
 import org.apache.tez.common.TezConverterUtils;
+import org.apache.tez.common.counters.CounterGroup;
+import org.apache.tez.common.counters.TezCounter;
 import org.apache.tez.runtime.api.TaskFailureType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -241,27 +243,68 @@ public class TaskAttemptFinishedEvent implements HistoryEvent {
 
   @Override
   public String toString() {
-    String counterStr = "";
+    StringBuilder sb = new StringBuilder();
+    sb.append("vertexName=");
+    sb.append(vertexName);
+    sb.append(", taskAttemptId=");
+    sb.append(taskAttemptId);
+    sb.append(", creationTime=");
+    sb.append(creationTime);
+    sb.append(", allocationTime=");
+    sb.append(allocationTime);
+    sb.append(", startTime=");
+    sb.append(startTime);
+    sb.append(", finishTime=");
+    sb.append(finishTime);
+    sb.append(", timeTaken=");
+    sb.append(finishTime - startTime);
+    sb.append(", status=");
+    sb.append(state.name());
+
+    if (taskFailureType != null) {
+      sb.append(", taskFailureType=");
+      sb.append(taskFailureType);
+    }
+    if (error != null) {
+      sb.append(", errorEnum=");
+      sb.append(error);
+    }
+    if (diagnostics != null) {
+      sb.append(", diagnostics=");
+      sb.append(diagnostics);
+    }
+    if (containerId != null) {
+      sb.append(", containerId=");
+      sb.append(containerId);
+    }
+    if (nodeId != null) {
+      sb.append(", nodeId=");
+      sb.append(nodeId);
+    }
+    if (nodeHttpAddress != null) {
+      sb.append(", nodeHttpAddress=");
+      sb.append(nodeHttpAddress);
+    }
+
     if (state != TaskAttemptState.SUCCEEDED) {
-      counterStr = ", counters=" + ( tezCounters == null ? "null" :
-        tezCounters.toString()
-        .replaceAll("\\n", ", ").replaceAll("\\s+", " "));
+      sb.append(", counters=");
+      if (tezCounters == null) {
+        sb.append("null");
+      } else {
+        sb.append("Counters: ");
+        sb.append(tezCounters.countCounters());
+        for (CounterGroup group : tezCounters) {
+          sb.append(", ");
+          sb.append(group.getDisplayName());
+          for (TezCounter counter : group) {
+            sb.append(", ");
+            sb.append(counter.getDisplayName()).append("=")
+                .append(counter.getValue());
+          }
+        }
+      }
     }
-    return "vertexName=" + vertexName
-        + ", taskAttemptId=" + taskAttemptId
-        + ", creationTime=" + creationTime
-        + ", allocationTime=" + allocationTime
-        + ", startTime=" + startTime
-        + ", finishTime=" + finishTime
-        + ", timeTaken=" + (finishTime - startTime)
-        + ", status=" + state.name()
-        + (taskFailureType != null ? ", taskFailureType=" + taskFailureType : "")
-        + (error != null ? ", errorEnum=" + error.name() : "")
-        + (diagnostics != null ? ", diagnostics=" + diagnostics : "")
-        + (containerId != null ? ", containerId=" + containerId.toString() : "")
-        + (nodeId != null ? ", nodeId=" + nodeId.toString() : "")
-        + (nodeHttpAddress != null ? ", nodeHttpAddress=" + nodeHttpAddress : "")
-        + counterStr;
+    return sb.toString();
   }
 
   public TezTaskAttemptID getTaskAttemptID() {
index 6befa1a..dd7afdf 100644 (file)
@@ -22,6 +22,8 @@ import java.io.IOException;
 
 import com.google.protobuf.CodedInputStream;
 import com.google.protobuf.CodedOutputStream;
+import org.apache.tez.common.counters.CounterGroup;
+import org.apache.tez.common.counters.TezCounter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.tez.common.counters.TezCounters;
@@ -122,18 +124,40 @@ public class TaskFinishedEvent implements HistoryEvent {
 
   @Override
   public String toString() {
-    return "vertexName=" + vertexName
-        + ", taskId=" + taskID
-        + ", startTime=" + startTime
-        + ", finishTime=" + finishTime
-        + ", timeTaken=" + (finishTime - startTime)
-        + ", status=" + state.name()
-        + ", successfulAttemptID=" + (successfulAttemptID == null ? "null" :
-            successfulAttemptID.toString())
-        + ", diagnostics=" + diagnostics
-        + ", counters=" + ( tezCounters == null ? "null" :
-          tezCounters.toString()
-            .replaceAll("\\n", ", ").replaceAll("\\s+", " "));
+    StringBuilder sb = new StringBuilder();
+    sb.append("vertexName=");
+    sb.append(vertexName);
+    sb.append(", taskId=");
+    sb.append(taskID);
+    sb.append(", startTime=");
+    sb.append(startTime);
+    sb.append(", finishTime=");
+    sb.append(finishTime);
+    sb.append(", timeTaken=");
+    sb.append(finishTime - startTime);
+    sb.append(", status=");
+    sb.append(state.name());
+    sb.append(", successfulAttemptID=");
+    sb.append(successfulAttemptID);
+    sb.append(", diagnostics=");
+    sb.append(diagnostics);
+    sb.append(", counters=");
+    if (tezCounters == null) {
+      sb.append("null");
+    } else {
+      sb.append("Counters: ");
+      sb.append(tezCounters.countCounters());
+      for (CounterGroup group : tezCounters) {
+        sb.append(", ");
+        sb.append(group.getDisplayName());
+        for (TezCounter counter : group) {
+          sb.append(", ");
+          sb.append(counter.getDisplayName()).append("=")
+              .append(counter.getValue());
+        }
+      }
+    }
+    return sb.toString();
   }
 
   public TezTaskID getTaskID() {