zuston commented on a change in pull request #18158:
URL: https://github.com/apache/flink/pull/18158#discussion_r775853926



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/rest/messages/taskmanager/ThreadDumpInfo.java
##########
@@ -106,5 +112,87 @@ public boolean equals(Object o) {
         public int hashCode() {
             return Objects.hash(threadName, stringifiedThreadInfo);
         }
+
+        /**
+         * Custom stringify format of JVM thread info to bypass the MAX_FRAMES 
= 8 limitation.
+         *
+         * <p>This method is based on
+         * 
https://github.com/openjdk/jdk/blob/master/src/java.management/share/classes/java/lang/management/ThreadInfo.java#L597
+         */
+        @VisibleForTesting
+        protected static String stringifyThreadInfo(
+                java.lang.management.ThreadInfo threadInfo, int maxDepth) {
+            StringBuilder sb =
+                    new StringBuilder(
+                            "\""
+                                    + threadInfo.getThreadName()
+                                    + "\""
+                                    + " Id="
+                                    + threadInfo.getThreadId()
+                                    + " "
+                                    + threadInfo.getThreadState());
+            if (threadInfo.getLockName() != null) {
+                sb.append(" on " + threadInfo.getLockName());
+            }
+            if (threadInfo.getLockOwnerName() != null) {
+                sb.append(
+                        " owned by \""
+                                + threadInfo.getLockOwnerName()
+                                + "\" Id="
+                                + threadInfo.getLockOwnerId());
+            }
+            if (threadInfo.isSuspended()) {
+                sb.append(" (suspended)");
+            }
+            if (threadInfo.isInNative()) {
+                sb.append(" (in native)");
+            }
+            sb.append('\n');
+            int i = 0;
+            StackTraceElement[] stackTraceElements = 
threadInfo.getStackTrace();
+            for (; i < stackTraceElements.length && i < maxDepth; i++) {
+                StackTraceElement ste = stackTraceElements[i];
+                sb.append("\tat " + ste.toString());
+                sb.append('\n');
+                if (i == 0 && threadInfo.getLockInfo() != null) {
+                    Thread.State ts = threadInfo.getThreadState();
+                    switch (ts) {
+                        case BLOCKED:
+                            sb.append("\t-  blocked on " + 
threadInfo.getLockInfo());
+                            sb.append('\n');
+                            break;
+                        case WAITING:
+                        case TIMED_WAITING:
+                            sb.append("\t-  waiting on " + 
threadInfo.getLockInfo());
+                            sb.append('\n');
+                            break;
+                        default:
+                    }
+                }
+
+                for (MonitorInfo mi : threadInfo.getLockedMonitors()) {
+                    if (mi.getLockedStackDepth() == i) {
+                        sb.append("\t-  locked " + mi);
+                        sb.append('\n');
+                    }
+                }
+            }
+            if (i < threadInfo.getStackTrace().length) {
+                sb.append("\t...");
+                sb.append('\n');
+            }
+
+            LockInfo[] locks = threadInfo.getLockedSynchronizers();
+            if (locks.length > 0) {
+                sb.append("\n\tNumber of locked synchronizers = " + 
locks.length);
+                sb.append('\n');
+                for (LockInfo li : locks) {
+                    sb.append("\t- " + li);
+                    sb.append('\n');
+                }
+            }
+            sb.append('\n');
+            return sb.toString();

Review comment:
       Got it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to