Last active
October 19, 2015 13:09
-
-
Save kares/9138300 to your computer and use it in GitHub Desktop.
Thread dump-ing for JRuby (using MX)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'java' | |
| module ThreadDump | |
| def self.thread_dump(output = nil) | |
| output ||= '' | |
| thread_mbean = java.lang.management.ManagementFactory.getThreadMXBean | |
| thread_ids = thread_mbean.getAllThreadIds # long[] | |
| threads = thread_mbean.getThreadInfo(thread_ids, false, false) # ThreadInfo[] | |
| threads.each do |thread_info| | |
| next if thread_info.nil? # not an active thread | |
| output << '"' << thread_info.getThreadName | |
| output << '" tid=' << thread_info.getThreadId.to_s | |
| output << ' ' << thread_info.getThreadState.toString | |
| if thread_info.getLockName | |
| output << ' on lock=' << thread_info.getLockName | |
| end | |
| output << ' (suspended)' if thread_info.isSuspended | |
| output << ' (running in native)' if thread_info.isInNative | |
| stackTrace = thread_info.getStackTrace # StackTraceElement[] | |
| if stackTrace.length > 0; ste = stackTrace[0] | |
| output << " in #{ste.getClassName}.#{ste.getMethodName}()" | |
| end | |
| output << "\n" | |
| if thread_info.getLockOwnerName | |
| output << "\t owned by " << thread_info.getLockOwnerName | |
| output << " Id=" << thread_info.getLockOwnerId.to_s | |
| output << "\n" | |
| end | |
| for ste in stackTrace | |
| output << "\tat #{ste.toString}\n" | |
| end | |
| end | |
| output | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment