Mercurial Hosting > luan
diff src/luan/modules/http/tools/luan_threads.html.luan @ 1218:a50803fde972
http/tools cleanup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 20 Mar 2018 16:24:59 -0600 |
parents | src/luan/modules/http/tools/luan_threads.luan@5dbb552075ff |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/modules/http/tools/luan_threads.html.luan Tue Mar 20 16:24:59 2018 -0600 @@ -0,0 +1,55 @@ +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" +local LuanException = require "java:luan.LuanException" +local JavaLuan = require "java:luan.Luan" + + +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 +%> +<!doctype html> +<html> + <body> + <h1>Luan Threads</h1> + <p><%=Http.request.headers["host"]%> - <%=Time.format(Time.now())%></p> + <% + local count = 0 + for _, thread in Luan.ipairs(threads) do + local luan_trace = JavaLuan.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