comparison src/luan/modules/http/tools/luan_threads.luan @ 790:4cddfc06a34f

add java_threads and luan_threads
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 04 Sep 2016 20:47:19 -0600
parents
children 0842b9b570f8
comparison
equal deleted inserted replaced
789:e2eb55d86bb2 790:4cddfc06a34f
1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error
3 local assert_table = Luan.assert_table or error()
4 local Io = require "luan:Io.luan"
5 local Time = require "luan:Time.luan"
6 local Http = require "luan:http/Http.luan"
7 java()
8 local Thread = require "java:java.lang.Thread"
9 local LuanException = require "java:luan.LuanException"
10
11
12 return function()
13 Io.stdout = Http.response.text_writer()
14
15 local threads = Thread.getAllStackTraces()
16 local threads = {}
17 for thread, trace in Luan.pairs(Thread.getAllStackTraces()) do
18 threads[#threads+1] = {
19 trace = trace
20 string = thread.toString()
21 state = thread.getState()
22 }
23 end
24 %>
25 <html>
26 <body>
27 <h1>Luan Threads</h1>
28 <p><%=Http.request.header.host%> - <%=Time.format(Time.now())%></p>
29 <%
30 local count = 0
31 for _, thread in Luan.ipairs(threads) do
32 local luan_trace = assert_table(LuanException.justLuan(thread.trace))
33 if #luan_trace > 0 then
34 %>
35 <p><%=thread.string%> <%=thread.state%>
36 <ul>
37 <%
38 for i, el in Luan.ipairs(luan_trace) do
39 local line = LuanException.toString(el);
40 %><li><%=line%></li><%
41 end
42 %>
43 </ul></p>
44 <%
45 count = count + 1
46 end
47 end
48 %>
49 <p><%=count%> threads found</p>
50
51 </body>
52 </html>
53 <%
54 end