Mercurial Hosting > luan
changeset 790:4cddfc06a34f
add java_threads and luan_threads
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 04 Sep 2016 20:47:19 -0600 |
parents | e2eb55d86bb2 |
children | ca81307adf7c |
files | src/luan/modules/http/tools/java_threads.luan src/luan/modules/http/tools/luan_threads.luan |
diffstat | 2 files changed, 104 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
diff -r e2eb55d86bb2 -r 4cddfc06a34f src/luan/modules/http/tools/java_threads.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/modules/http/tools/java_threads.luan Sun Sep 04 20:47:19 2016 -0600 @@ -0,0 +1,50 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local Io = require "luan:Io.luan" +local Time = require "luan:Time.luan" +local Http = require "luan:http/Http.luan" +java() +local Thread = require "java:java.lang.Thread" + + +return function() + Io.stdout = Http.response.text_writer() + + local threads = Thread.getAllStackTraces() + local threads = {} + for thread, trace in Luan.pairs(Thread.getAllStackTraces()) do + threads[#threads+1] = { + trace = trace + string = thread.toString() + state = thread.getState() + } + end +%> +<html> + <body> + <h1>Java Threads</h1> + <p><%=Http.request.header.host%> - <%=Time.format(Time.now())%></p> + <% + local count = 0 + for _, thread in Luan.ipairs(threads) do + %> + <p><%=thread.string%> <%=thread.state%> + <ul> + <% + local trace = thread.trace + for i in Luan.range( 0 , trace.length - 1 ) do + local line = trace[i].toString() + %><li><%=line%></li><% + end + %> + </ul></p> + <% + count = count + 1 + end + %> + <p><%=count%> threads found</p> + + </body> +</html> +<% +end
diff -r e2eb55d86bb2 -r 4cddfc06a34f src/luan/modules/http/tools/luan_threads.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/modules/http/tools/luan_threads.luan Sun Sep 04 20:47:19 2016 -0600 @@ -0,0 +1,54 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local assert_table = Luan.assert_table or error() +local Io = require "luan:Io.luan" +local Time = require "luan:Time.luan" +local Http = require "luan:http/Http.luan" +java() +local Thread = require "java:java.lang.Thread" +local LuanException = require "java:luan.LuanException" + + +return function() + Io.stdout = Http.response.text_writer() + + local threads = Thread.getAllStackTraces() + local threads = {} + for thread, trace in Luan.pairs(Thread.getAllStackTraces()) do + threads[#threads+1] = { + trace = trace + string = thread.toString() + state = thread.getState() + } + end +%> +<html> + <body> + <h1>Luan Threads</h1> + <p><%=Http.request.header.host%> - <%=Time.format(Time.now())%></p> + <% + local count = 0 + for _, thread in Luan.ipairs(threads) do + local luan_trace = assert_table(LuanException.justLuan(thread.trace)) + if #luan_trace > 0 then + %> + <p><%=thread.string%> <%=thread.state%> + <ul> + <% + for i, el in Luan.ipairs(luan_trace) do + local line = LuanException.toString(el); + %><li><%=line%></li><% + end + %> + </ul></p> + <% + count = count + 1 + end + end + %> + <p><%=count%> threads found</p> + + </body> +</html> +<% +end