hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edwardy...@apache.org
Subject svn commit: r1680725 - in /hama/trunk: core/src/main/java/org/apache/hama/http/HttpServer.java core/src/main/java/org/apache/hama/util/ReflectionUtils.java pom.xml
Date Thu, 21 May 2015 03:21:36 GMT
Author: edwardyoon
Date: Thu May 21 03:21:36 2015
New Revision: 1680725

URL: http://svn.apache.org/r1680725
Log:
HAMA-957: Compilation failure with hadoop 2.7.0

Modified:
    hama/trunk/core/src/main/java/org/apache/hama/http/HttpServer.java
    hama/trunk/core/src/main/java/org/apache/hama/util/ReflectionUtils.java
    hama/trunk/pom.xml

Modified: hama/trunk/core/src/main/java/org/apache/hama/http/HttpServer.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/main/java/org/apache/hama/http/HttpServer.java?rev=1680725&r1=1680724&r2=1680725&view=diff
==============================================================================
--- hama/trunk/core/src/main/java/org/apache/hama/http/HttpServer.java (original)
+++ hama/trunk/core/src/main/java/org/apache/hama/http/HttpServer.java Thu May 21 03:21:36
2015
@@ -36,9 +36,9 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.log.LogLevel;
-import org.apache.hadoop.util.ReflectionUtils;
 import org.apache.hama.bsp.BSPMaster;
 import org.apache.hama.manager.LogView;
+import org.apache.hama.util.ReflectionUtils;
 import org.mortbay.jetty.Connector;
 import org.mortbay.jetty.Handler;
 import org.mortbay.jetty.Server;

Modified: hama/trunk/core/src/main/java/org/apache/hama/util/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/main/java/org/apache/hama/util/ReflectionUtils.java?rev=1680725&r1=1680724&r2=1680725&view=diff
==============================================================================
--- hama/trunk/core/src/main/java/org/apache/hama/util/ReflectionUtils.java (original)
+++ hama/trunk/core/src/main/java/org/apache/hama/util/ReflectionUtils.java Thu May 21 03:21:36
2015
@@ -17,6 +17,11 @@
  */
 package org.apache.hama.util;
 
+import java.io.ByteArrayOutputStream;
+import java.io.PrintWriter;
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
 import java.lang.reflect.Constructor;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -128,4 +133,83 @@ public class ReflectionUtils {
     return result;
   }
 
+  static private ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
+
+  /**
+   * Print all of the thread's information and stack traces.
+   * 
+   * @param stream the stream to
+   * @param title a string title for the stack trace
+   */
+  public synchronized static void printThreadInfo(PrintWriter stream,
+      String title) {
+    final int STACK_DEPTH = 20;
+    boolean contention = threadBean.isThreadContentionMonitoringEnabled();
+    long[] threadIds = threadBean.getAllThreadIds();
+    stream.println("Process Thread Dump: " + title);
+    stream.println(threadIds.length + " active threads");
+    for (long tid : threadIds) {
+      ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH);
+      if (info == null) {
+        stream.println("  Inactive");
+        continue;
+      }
+      stream.println("Thread "
+          + getTaskName(info.getThreadId(), info.getThreadName()) + ":");
+      Thread.State state = info.getThreadState();
+      stream.println("  State: " + state);
+      stream.println("  Blocked count: " + info.getBlockedCount());
+      stream.println("  Waited count: " + info.getWaitedCount());
+      if (contention) {
+        stream.println("  Blocked time: " + info.getBlockedTime());
+        stream.println("  Waited time: " + info.getWaitedTime());
+      }
+      if (state == Thread.State.WAITING) {
+        stream.println("  Waiting on " + info.getLockName());
+      } else if (state == Thread.State.BLOCKED) {
+        stream.println("  Blocked on " + info.getLockName());
+        stream.println("  Blocked by "
+            + getTaskName(info.getLockOwnerId(), info.getLockOwnerName()));
+      }
+      stream.println("  Stack:");
+      for (StackTraceElement frame : info.getStackTrace()) {
+        stream.println("    " + frame.toString());
+      }
+    }
+    stream.flush();
+  }
+
+  private static long previousLogTime = 0;
+
+  /**
+   * Log the current thread stacks at INFO level.
+   * 
+   * @param log the logger that logs the stack trace
+   * @param title a descriptive title for the call stacks
+   * @param minInterval the minimum time from the last
+   */
+  public static void logThreadInfo(Log log, String title, long minInterval) {
+    boolean dumpStack = false;
+    if (log.isInfoEnabled()) {
+      synchronized (ReflectionUtils.class) {
+        long now = System.currentTimeMillis();
+        if (now - previousLogTime >= minInterval * 1000) {
+          previousLogTime = now;
+          dumpStack = true;
+        }
+      }
+      if (dumpStack) {
+        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        printThreadInfo(new PrintWriter(buffer), title);
+        log.info(buffer.toString());
+      }
+    }
+  }
+
+  private static String getTaskName(long id, String name) {
+    if (name == null) {
+      return Long.toString(id);
+    }
+    return id + " (" + name + ")";
+  }
 }

Modified: hama/trunk/pom.xml
URL: http://svn.apache.org/viewvc/hama/trunk/pom.xml?rev=1680725&r1=1680724&r2=1680725&view=diff
==============================================================================
--- hama/trunk/pom.xml (original)
+++ hama/trunk/pom.xml Thu May 21 03:21:36 2015
@@ -156,7 +156,7 @@
     <profile>
       <id>hadoop2</id>
       <properties>
-        <hadoop.version>2.6.0</hadoop.version>
+        <hadoop.version>2.7.0</hadoop.version>
       </properties>
       <activation>
         <activeByDefault>true</activeByDefault>



Mime
View raw message