comparison host/admin/src/private/tools/java_threads.html.luan @ 1996:d5c21ca9703e default tip

move threads to admin
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 04 Jul 2025 11:39:41 -0600
parents 301a6561fb6b
children
comparison
equal deleted inserted replaced
1995:301a6561fb6b 1996:d5c21ca9703e
1 return require("luan:http/tools/Java_threads.luan").respond 1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error
3 local Io = require "luan:Io.luan"
4 local Time = require "luan:Time.luan"
5 local Table = require "luan:Table.luan"
6 local to_table = Table.java_to_table_shallow or error()
7 local Http = require "luan:http/Http.luan"
8 require "java"
9 local Thread = require "java:java.lang.Thread"
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(to_table(Thread.getAllStackTraces())) do
18 threads[#threads+1] = {
19 trace = trace
20 string = thread.toString()
21 state = thread.getState()
22 }
23 end
24 %>
25 <!doctype html>
26 <html lang="en">
27 <body>
28 <h1>Java Threads</h1>
29 <p><%=Http.request.headers["host"]%> - <%=Time.format(Time.now())%></p>
30 <%
31 local count = 0
32 for _, thread in Luan.ipairs(threads) do
33 %>
34 <p><%=thread.string%> <%=thread.state%>
35 <ul>
36 <%
37 local trace = thread.trace
38 for i in Luan.range( 0 , trace.length - 1 ) do
39 local line = trace[i].toString()
40 %><li><%=line%></li><%
41 end
42 %>
43 </ul></p>
44 <%
45 count = count + 1
46 end
47 %>
48 <p><%=count%> threads found</p>
49
50 </body>
51 </html>
52 <%
53 end