jbe@299: local function format_time(real_time, proc_time) jbe@299: if proc_time then jbe@301: return string.format("%.1f ms (%.1f ms)", real_time * 1000, proc_time * 1000) jbe@299: else jbe@299: return string.format("%.1f ms", real_time * 1000) jbe@299: end jbe@295: end jbe@295: jbe/bsw@0: local function open(class) jbe/bsw@0: slot.put('
  • ') jbe/bsw@0: end bsw@115: local function open_head(node) jbe/bsw@0: slot.put('
    ') jbe@299: if node.start_real_time and node.stop_real_time then jbe@299: local total_real_time = node.stop_real_time - node.start_real_time jbe@299: local total_proc_time = node.stop_proc_time - node.start_proc_time jbe@299: local child_real_time = 0 jbe@299: local child_proc_time = 0 bsw@115: for i, child in ipairs(node) do jbe@299: if child.start_real_time then jbe@299: child_real_time = child_real_time + child.stop_real_time - child.start_real_time jbe@299: child_proc_time = child_proc_time + child.stop_proc_time - child.start_proc_time bsw@115: end bsw@115: end jbe@299: local real_time = total_real_time - child_real_time jbe@299: local proc_time = total_proc_time - child_proc_time jbe@299: slot.put( jbe@299: '
    ', jbe@299: 'this:', jbe@299: ' ', jbe@299: '', format_time(real_time, proc_time), '', jbe@299: ' | ', jbe@299: 'children:', jbe@299: ' ', jbe@299: '', format_time(child_real_time, child_proc_time), '', jbe@299: ' | ', jbe@299: 'total:', jbe@299: ' ', jbe@299: '', format_time(total_real_time, total_proc_time), '', jbe@299: '
    ' jbe@299: ) bsw@115: end jbe/bsw@0: end jbe/bsw@0: local function close_head() jbe/bsw@0: slot.put('
    ') jbe/bsw@0: end jbe/bsw@0: local function close() jbe/bsw@0: slot.put('
  • ') jbe/bsw@0: end jbe/bsw@0: function trace._render_sub_tree(node) jbe/bsw@0: local function render_children(tail) jbe/bsw@0: if #node > 0 then jbe/bsw@0: slot.put('") jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@0: local function close_with_children() jbe/bsw@0: close_head() jbe/bsw@0: render_children() jbe/bsw@0: close() jbe/bsw@0: end jbe/bsw@0: local node_type = node.type jbe/bsw@0: if node_type == "root" then jbe/bsw@0: render_children() jbe/bsw@0: elseif node_type == "debug" then jbe/bsw@0: open("debug") jbe/bsw@0: slot.put(encode.html(node.message)) jbe/bsw@0: close() poelzi@31: elseif node_type == "debug_table" then poelzi@31: open("debug") poelzi@31: slot.put("") poelzi@31: if type(node.message) == "table" then poelzi@31: for k, v in pairs(node.message) do jbe@45: slot.put("") poelzi@31: end poelzi@31: slot.put("
    ", encode.html(tostring(k)), "", encode.html(tostring(v)), "
    ") poelzi@31: else poelzi@31: slot.put("debug_table: not of table type") poelzi@31: end poelzi@31: close() poelzi@29: elseif node_type == "traceback" then poelzi@29: open("debug") poelzi@29: slot.put('
    ')
    poelzi@29:     slot.put(encode.html(node.message))
    poelzi@29:     slot.put('
    ') poelzi@29: close() jbe/bsw@0: elseif node_type == "request" then jbe/bsw@0: open("request") bsw@115: open_head(node) jbe/bsw@0: slot.put("REQUESTED") jbe/bsw@0: if node.view then jbe/bsw@0: slot.put(" VIEW") jbe/bsw@0: elseif node.action then jbe/bsw@0: slot.put(" ACTION") jbe/bsw@0: end jbe/bsw@0: slot.put( jbe/bsw@0: ": ", jbe/bsw@0: encode.html(node.module), jbe/bsw@0: "/", jbe/bsw@0: encode.html(node.view or node.action) jbe/bsw@0: ) jbe/bsw@0: close_with_children() jbe/bsw@0: elseif node_type == "config" then jbe/bsw@0: open("config") bsw@115: open_head(node) jbe/bsw@0: slot.put('Configuration "', encode.html(node.name), '"') jbe/bsw@0: close_with_children() jbe/bsw@0: elseif node_type == "filter" then jbe/bsw@0: open("filter") bsw@115: open_head(node) jbe/bsw@0: slot.put(encode.html(node.path)) jbe/bsw@0: close_with_children() jbe/bsw@0: elseif node_type == "view" then jbe/bsw@0: open("view") bsw@115: open_head(node) jbe/bsw@0: slot.put( jbe/bsw@0: "EXECUTE VIEW: ", jbe/bsw@0: encode.html(node.module), jbe/bsw@0: "/", jbe/bsw@0: encode.html(node.view) jbe/bsw@0: ) jbe/bsw@0: close_with_children() jbe/bsw@0: elseif node_type == "action" then jbe/bsw@0: if jbe/bsw@0: node.status and ( jbe/bsw@0: node.status == "ok" or jbe/bsw@0: string.find(node.status, "^ok_") jbe/bsw@0: ) jbe/bsw@0: then jbe/bsw@0: open("action_success") jbe/bsw@0: elseif jbe/bsw@0: node.status and ( jbe/bsw@0: node.status == "error" or jbe/bsw@0: string.find(node.status, "^error_") jbe/bsw@0: ) jbe/bsw@0: then jbe/bsw@0: open("action_softfail") jbe/bsw@0: else jbe/bsw@0: open("action_neutral") jbe/bsw@0: end bsw@115: open_head(node) jbe/bsw@0: slot.put( jbe/bsw@0: "EXECUTE ACTION: ", jbe/bsw@0: encode.html(node.module), jbe/bsw@0: "/", jbe/bsw@0: encode.html(node.action) jbe/bsw@0: ) jbe/bsw@0: close_head() jbe/bsw@0: if node.status == "softfail" then jbe/bsw@0: render_children( jbe/bsw@0: '
  • Status code: "' .. jbe/bsw@0: encode.html(node.failure_code) .. jbe/bsw@0: '"
  • ' jbe/bsw@0: ) jbe/bsw@0: else jbe/bsw@0: render_children() jbe/bsw@0: end jbe/bsw@0: close() jbe/bsw@0: elseif node_type == "redirect" then jbe/bsw@0: open("redirect") bsw@115: open_head(node) jbe/bsw@0: slot.put("303 REDIRECT TO VIEW: ", encode.html(node.module), "/", encode.html(node.view)) jbe/bsw@0: close_with_children() jbe/bsw@0: elseif node_type == "forward" then jbe/bsw@0: open("forward") bsw@115: open_head(node) jbe/bsw@0: slot.put("INTERNAL FORWARD TO VIEW: ", encode.html(node.module), "/", encode.html(node.view)) jbe/bsw@0: close_with_children() jbe@223: --[[ jbe/bsw@0: elseif node_type == "exectime" then jbe/bsw@0: open("exectime") bsw@115: open_head(node) jbe/bsw@0: slot.put( jbe/bsw@0: "Finished after " .. jbe@65: string.format("%.1f", extos.monotonic_hires_time() * 1000) .. jbe/bsw@0: ' ms (' .. jbe/bsw@0: string.format("%.1f", os.clock() * 1000) .. jbe/bsw@0: ' ms CPU)' jbe/bsw@0: ) jbe/bsw@0: close_with_children() jbe@223: --]] jbe/bsw@0: elseif node_type == "sql" then jbe/bsw@0: open("sql") jbe/bsw@0: if node.error_position then jbe/bsw@0: -- error position starts counting with 1 jbe/bsw@0: local part1 = string.sub(node.command, 1, node.error_position - 1) jbe/bsw@0: local part2 = string.sub(node.command, node.error_position) jbe/bsw@0: slot.put(encode.html(part1)) jbe/bsw@0: slot.put('') jbe/bsw@0: slot.put(encode.html(part2)) jbe/bsw@0: else jbe/bsw@0: slot.put(encode.html(node.command)) jbe/bsw@0: end jbe@296: slot.put(" (execution time: ", format_time(node.execution_time), ")") jbe/bsw@0: close(); jbe/bsw@0: elseif node_type == "error" then jbe/bsw@0: open("error") bsw@115: open_head(node) jbe/bsw@0: slot.put("UNEXPECTED ERROR") jbe/bsw@0: close_head() jbe/bsw@0: close() jbe/bsw@0: end jbe/bsw@0: end