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