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