|
@@ -46,6 +46,7 @@ import org.apache.hadoop.io.Writable;
|
|
|
import org.apache.hadoop.io.serializer.Deserializer;
|
|
|
import org.apache.hadoop.io.serializer.SerializationFactory;
|
|
|
import org.apache.hadoop.io.serializer.Serializer;
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
|
/**
|
|
|
* General reflection utils
|
|
@@ -228,6 +229,35 @@ public class ReflectionUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 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(Logger log,
|
|
|
+ String title,
|
|
|
+ long minInterval) {
|
|
|
+ boolean dumpStack = false;
|
|
|
+ if (log.isInfoEnabled()) {
|
|
|
+ synchronized (ReflectionUtils.class) {
|
|
|
+ long now = Time.now();
|
|
|
+ if (now - previousLogTime >= minInterval * 1000) {
|
|
|
+ previousLogTime = now;
|
|
|
+ dumpStack = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (dumpStack) {
|
|
|
+ try {
|
|
|
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
|
|
+ printThreadInfo(new PrintStream(buffer, false, "UTF-8"), title);
|
|
|
+ log.info(buffer.toString(Charset.defaultCharset().name()));
|
|
|
+ } catch (UnsupportedEncodingException ignored) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Return the correctly-typed {@link Class} of the given object.
|
|
|
*
|