webmcp

view framework/env/trace/_render_sub_tree.lua @ 223:32ec28229bb5

Finished removing all references to cgi module (except demo-app); Removed partial loading mechanism
author jbe
date Fri Feb 27 21:49:00 2015 +0100 (2015-02-27)
parents 0de41d8e2cf8
children 1fbdccf4f8e9
line source
1 local function open(class)
2 slot.put('<li class="trace_' .. class .. '">')
3 end
4 local function open_head(node)
5 slot.put('<div class="trace_head">')
6 if node.start_hires_time and node.stop_hires_time then
7 local total_duration = node.stop_hires_time - node.start_hires_time
8 local child_duration = 0
9 for i, child in ipairs(node) do
10 if child.start_hires_time and child.stop_hires_time then
11 child_duration = child_duration + child.stop_hires_time - child.start_hires_time
12 end
13 end
14 local duration = total_duration - child_duration
15 local start_text = math.floor(node.start_hires_time * 10000 + 0.5) / 10
16 local total_duration_text = math.floor(total_duration * 10000 + 0.5) / 10
17 local child_duration_text = math.floor(child_duration * 10000 + 0.5) / 10
18 local duration_text = math.floor(duration * 10000 + 0.5) / 10
19 slot.put('<div class="time">')
20 slot.put('<span class="start_label">start:</span>')
21 slot.put(" ")
22 slot.put('<span class="start">' .. start_text .. 'ms</span>')
23 slot.put(" | ")
24 slot.put('<span class="duration_label">this:</span>')
25 slot.put(" ")
26 slot.put('<span class="duration">' .. duration_text .. 'ms</span>')
27 slot.put(" | ")
28 slot.put('<span class="child_duration_label">children:</span>')
29 slot.put(" ")
30 slot.put('<span class="child_duration">' .. child_duration_text .. 'ms</span>')
31 slot.put(" | ")
32 slot.put('<span class="total_duration_label">total:</span>')
33 slot.put(" ")
34 slot.put('<span class="total_duration">' .. total_duration_text .. 'ms</span>')
35 slot.put('</div>')
36 end
37 end
38 local function close_head()
39 slot.put('</div>')
40 end
41 local function close()
42 slot.put('</li>')
43 end
44 function trace._render_sub_tree(node)
45 local function render_children(tail)
46 if #node > 0 then
47 slot.put('<ul class="trace_list">')
48 for idx, child in ipairs(node) do
49 trace._render_sub_tree(child)
50 end
51 if tail then
52 slot.put(tail)
53 end
54 slot.put("</ul>")
55 end
56 end
57 local function close_with_children()
58 close_head()
59 render_children()
60 close()
61 end
62 local node_type = node.type
63 if node_type == "root" then
64 render_children()
65 elseif node_type == "debug" then
66 open("debug")
67 slot.put(encode.html(node.message))
68 close()
69 elseif node_type == "debug_table" then
70 open("debug")
71 slot.put("<table>")
72 if type(node.message) == "table" then
73 for k, v in pairs(node.message) do
74 slot.put("<tr><td>", encode.html(tostring(k)), "</td><td>", encode.html(tostring(v)), "</td></tr>")
75 end
76 slot.put("</table>")
77 else
78 slot.put("debug_table: not of table type")
79 end
80 close()
81 elseif node_type == "traceback" then
82 open("debug")
83 slot.put('<pre>')
84 slot.put(encode.html(node.message))
85 slot.put('</pre>')
86 close()
87 elseif node_type == "request" then
88 open("request")
89 open_head(node)
90 slot.put("REQUESTED")
91 if node.view then
92 slot.put(" VIEW")
93 elseif node.action then
94 slot.put(" ACTION")
95 end
96 slot.put(
97 ": ",
98 encode.html(node.module),
99 "/",
100 encode.html(node.view or node.action)
101 )
102 close_with_children()
103 elseif node_type == "config" then
104 open("config")
105 open_head(node)
106 slot.put('Configuration "', encode.html(node.name), '"')
107 close_with_children()
108 elseif node_type == "filter" then
109 open("filter")
110 open_head(node)
111 slot.put(encode.html(node.path))
112 close_with_children()
113 elseif node_type == "view" then
114 open("view")
115 open_head(node)
116 slot.put(
117 "EXECUTE VIEW: ",
118 encode.html(node.module),
119 "/",
120 encode.html(node.view)
121 )
122 close_with_children()
123 elseif node_type == "action" then
124 if
125 node.status and (
126 node.status == "ok" or
127 string.find(node.status, "^ok_")
128 )
129 then
130 open("action_success")
131 elseif
132 node.status and (
133 node.status == "error" or
134 string.find(node.status, "^error_")
135 )
136 then
137 open("action_softfail")
138 else
139 open("action_neutral")
140 end
141 open_head(node)
142 slot.put(
143 "EXECUTE ACTION: ",
144 encode.html(node.module),
145 "/",
146 encode.html(node.action)
147 )
148 close_head()
149 if node.status == "softfail" then
150 render_children(
151 '<li class="trace_action_status">Status code: "' ..
152 encode.html(node.failure_code) ..
153 '"</li>'
154 )
155 else
156 render_children()
157 end
158 close()
159 elseif node_type == "redirect" then
160 open("redirect")
161 open_head(node)
162 slot.put("303 REDIRECT TO VIEW: ", encode.html(node.module), "/", encode.html(node.view))
163 close_with_children()
164 elseif node_type == "forward" then
165 open("forward")
166 open_head(node)
167 slot.put("INTERNAL FORWARD TO VIEW: ", encode.html(node.module), "/", encode.html(node.view))
168 close_with_children()
169 --[[
170 elseif node_type == "exectime" then
171 open("exectime")
172 open_head(node)
173 slot.put(
174 "Finished after " ..
175 string.format("%.1f", extos.monotonic_hires_time() * 1000) ..
176 ' ms (' ..
177 string.format("%.1f", os.clock() * 1000) ..
178 ' ms CPU)'
179 )
180 close_with_children()
181 --]]
182 elseif node_type == "sql" then
183 open("sql")
184 if node.error_position then
185 -- error position starts counting with 1
186 local part1 = string.sub(node.command, 1, node.error_position - 1)
187 --local part2 = string.sub(node.command, node.error_position - 1, node.error_position + 1)
188 local part2 = string.sub(node.command, node.error_position)
189 slot.put(encode.html(part1))
190 slot.put('<span class="trace_error_position">&rArr;</span>')
191 slot.put(encode.html(part2))
192 --slot.put('</span>')
193 --slot.put(encode.html(part3))
194 else
195 slot.put(encode.html(node.command))
196 end
197 close();
198 elseif node_type == "error" then
199 open("error")
200 open_head(node)
201 slot.put("UNEXPECTED ERROR")
202 close_head()
203 close()
204 end
205 end

Impressum / About Us