# HG changeset patch # User jbe # Date 1287244278 -7200 # Node ID 0bbfee4d4aeddd78d76c33d094dba0356324e880 # Parent ed00b972f40edb30707fffbb0a6ee8174f5a2236 New functions trace.disable() and trace.is_disabled() diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/__init.lua --- a/framework/env/trace/__init.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/__init.lua Sat Oct 16 17:51:18 2010 +0200 @@ -1,2 +1,3 @@ +trace._disabled = false trace._tree = { type = "root" } trace._stack = { trace._tree } diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/debug.lua --- a/framework/env/trace/debug.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/debug.lua Sat Oct 16 17:51:18 2010 +0200 @@ -8,10 +8,12 @@ --]]-- function trace.debug(...) - local message = "" - local arg = {...} - for i= 1,#arg,1 do - message = message..tostring(arg[i]).." " + if not trace._disabled then + local message = "" + local arg = {...} + for i= 1,#arg,1 do + message = message..tostring(arg[i]).." " + end + trace._new_entry{ type = "debug", message = message } end - trace._new_entry{ type = "debug", message = message } end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/disable.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/framework/env/trace/disable.lua Sat Oct 16 17:51:18 2010 +0200 @@ -0,0 +1,10 @@ +--[[-- +trace.disable() + +This function disables the trace system. Re-enabling the trace system is not possible. + +--]]-- + +function trace.disable() + trace._disabled = true +end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/enter_action.lua --- a/framework/env/trace/enter_action.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/enter_action.lua Sat Oct 16 17:51:18 2010 +0200 @@ -9,13 +9,15 @@ --]]-- function trace.enter_action(args) - local module = args.module - local action = args.action - if type(module) ~= "string" then - error("No module string passed to trace.enter_action{...}.") + if not trace._disabled then + local module = args.module + local action = args.action + if type(module) ~= "string" then + error("No module string passed to trace.enter_action{...}.") + end + if type(action) ~= "string" then + error("No action string passed to trace.enter_action{...}.") + end + trace._open_section{ type = "action", module = module, action = action } end - if type(action) ~= "string" then - error("No action string passed to trace.enter_action{...}.") - end - trace._open_section{ type = "action", module = module, action = action } end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/enter_config.lua --- a/framework/env/trace/enter_config.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/enter_config.lua Sat Oct 16 17:51:18 2010 +0200 @@ -8,9 +8,11 @@ --]]-- function trace.enter_config(args) - local name = args.name - if type(name) ~= "string" then - error("No name string passed to trace.enter_config{...}.") + if not trace._disabled then + local name = args.name + if type(name) ~= "string" then + error("No name string passed to trace.enter_config{...}.") + end + trace._open_section{ type = "config", name = name } end - trace._open_section{ type = "config", name = name } end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/enter_filter.lua --- a/framework/env/trace/enter_filter.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/enter_filter.lua Sat Oct 16 17:51:18 2010 +0200 @@ -8,9 +8,11 @@ --]]-- function trace.enter_filter(args) - local path = args.path - if type(path) ~= "string" then - error("No path string passed to trace.enter_filter{...}.") + if not trace._disabled then + local path = args.path + if type(path) ~= "string" then + error("No path string passed to trace.enter_filter{...}.") + end + trace._open_section{ type = "filter", path = path } end - trace._open_section{ type = "filter", path = path } end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/enter_view.lua --- a/framework/env/trace/enter_view.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/enter_view.lua Sat Oct 16 17:51:18 2010 +0200 @@ -9,13 +9,15 @@ --]]-- function trace.enter_view(args) - local module = args.module - local view = args.view - if type(module) ~= "string" then - error("No module passed to trace.enter_view{...}.") + if not trace._disabled then + local module = args.module + local view = args.view + if type(module) ~= "string" then + error("No module passed to trace.enter_view{...}.") + end + if type(view) ~= "string" then + error("No view passed to trace.enter_view{...}.") + end + trace._open_section{ type = "view", module = module, view = view } end - if type(view) ~= "string" then - error("No view passed to trace.enter_view{...}.") - end - trace._open_section{ type = "view", module = module, view = view } end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/error.lua --- a/framework/env/trace/error.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/error.lua Sat Oct 16 17:51:18 2010 +0200 @@ -7,8 +7,10 @@ --]]-- function trace.error(args) - trace._new_entry { type = "error" } - local closed_section = trace._close_section() - closed_section.hard_error = true -- TODO: not used, maybe remove - trace._stack = { trace._tree } + if not trace._disabled then + trace._new_entry { type = "error" } + local closed_section = trace._close_section() + closed_section.hard_error = true -- TODO: not used, maybe remove + trace._stack = { trace._tree } + end end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/exectime.lua --- a/framework/env/trace/exectime.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/exectime.lua Sat Oct 16 17:51:18 2010 +0200 @@ -9,13 +9,15 @@ --]]-- function trace.exectime(args) - local real = args.real - local cpu = args.cpu - if type(real) ~= "number" then - error("Called trace.exectime{...} without numeric 'real' argument.") + if not trace._disabled then + local real = args.real + local cpu = args.cpu + if type(real) ~= "number" then + error("Called trace.exectime{...} without numeric 'real' argument.") + end + if type(cpu) ~= "number" then + error("Called trace.exectime{...} without numeric 'cpu' argument.") + end + trace._new_entry{ type = "exectime", real = args.real, cpu = args.cpu } end - if type(cpu) ~= "number" then - error("Called trace.exectime{...} without numeric 'cpu' argument.") - end - trace._new_entry{ type = "exectime", real = args.real, cpu = args.cpu } end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/execution_return.lua --- a/framework/env/trace/execution_return.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/execution_return.lua Sat Oct 16 17:51:18 2010 +0200 @@ -8,13 +8,15 @@ --]]-- function trace.execution_return(args) - local status - if args then - status = args.status + if not trace._disabled then + local status + if args then + status = args.status + end + if status and type(status) ~= "string" then + error("Status passed to trace.execution_return{...} is not a string.") + end + local closed_section = trace._close_section() + closed_section.status = status end - if status and type(status) ~= "string" then - error("Status passed to trace.execution_return{...} is not a string.") - end - local closed_section = trace._close_section() - closed_section.status = status end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/forward.lua --- a/framework/env/trace/forward.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/forward.lua Sat Oct 16 17:51:18 2010 +0200 @@ -9,13 +9,15 @@ --]]-- function trace.forward(args) - local module = args.module - local view = args.view - if type(module) ~= "string" then - error("No module string passed to trace.forward{...}.") + if not trace._disabled then + local module = args.module + local view = args.view + if type(module) ~= "string" then + error("No module string passed to trace.forward{...}.") + end + if type(view) ~= "string" then + error("No view string passed to trace.forward{...}.") + end + trace._new_entry{ type = "forward", module = module, view = view } end - if type(view) ~= "string" then - error("No view string passed to trace.forward{...}.") - end - trace._new_entry{ type = "forward", module = module, view = view } end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/is_disabled.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/framework/env/trace/is_disabled.lua Sat Oct 16 17:51:18 2010 +0200 @@ -0,0 +1,11 @@ +--[[-- +disabled = -- boolean indicating if trace system is disabled +trace.is_disabled() + +This function returns true, if the trace system has been disabled. Otherwise false is returned. + +--]]-- + +function trace.is_disabled() + return trace._disabled +end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/redirect.lua --- a/framework/env/trace/redirect.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/redirect.lua Sat Oct 16 17:51:18 2010 +0200 @@ -9,13 +9,15 @@ --]]-- function trace.redirect(args) - local module = args.module - local view = args.view - if type(module) ~= "string" then - error("No module string passed to trace.redirect{...}.") + if not trace._disabled then + local module = args.module + local view = args.view + if type(module) ~= "string" then + error("No module string passed to trace.redirect{...}.") + end + if type(view) ~= "string" then + error("No view string passed to trace.redirect{...}.") + end + trace._new_entry{ type = "redirect", module = module, view = view } end - if type(view) ~= "string" then - error("No view string passed to trace.redirect{...}.") - end - trace._new_entry{ type = "redirect", module = module, view = view } end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/render.lua --- a/framework/env/trace/render.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/render.lua Sat Oct 16 17:51:18 2010 +0200 @@ -6,6 +6,8 @@ --]]-- function trace.render() - -- TODO: check if all sections are closed? - trace._render_sub_tree(trace._tree) + if not trace._disabled then + -- TODO: check if all sections are closed? + trace._render_sub_tree(trace._tree) + end end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/request.lua --- a/framework/env/trace/request.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/request.lua Sat Oct 16 17:51:18 2010 +0200 @@ -10,28 +10,30 @@ --]]-- function trace.request(args) - local module = args.module - local view = args.view - local action = args.action - if type(module) ~= "string" then - error("No module string passed to trace.request{...}.") - end - if view and action then - error("Both view and action passed to trace.request{...}.") - end - if not (view or action) then - error("Neither view nor action passed to trace.request{...}.") + if not trace._disabled then + local module = args.module + local view = args.view + local action = args.action + if type(module) ~= "string" then + error("No module string passed to trace.request{...}.") + end + if view and action then + error("Both view and action passed to trace.request{...}.") + end + if not (view or action) then + error("Neither view nor action passed to trace.request{...}.") + end + if view and type(view) ~= "string" then + error("No view string passed to trace.request{...}.") + end + if action and type(action) ~= "string" then + error("No action string passed to trace.request{...}.") + end + trace._new_entry{ + type = "request", + module = args.module, + view = args.view, + action = args.action + } end - if view and type(view) ~= "string" then - error("No view string passed to trace.request{...}.") - end - if action and type(action) ~= "string" then - error("No action string passed to trace.request{...}.") - end - trace._new_entry{ - type = "request", - module = args.module, - view = args.view, - action = args.action - } end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/restore_slots.lua --- a/framework/env/trace/restore_slots.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/restore_slots.lua Sat Oct 16 17:51:18 2010 +0200 @@ -7,5 +7,7 @@ --]]-- function trace.restore_slots(args) - trace._new_entry{ type = "restore_slots" } + if not trace._disabled then + trace._new_entry{ type = "restore_slots" } + end end diff -r ed00b972f40e -r 0bbfee4d4aed framework/env/trace/sql.lua --- a/framework/env/trace/sql.lua Sat Oct 16 17:49:11 2010 +0200 +++ b/framework/env/trace/sql.lua Sat Oct 16 17:51:18 2010 +0200 @@ -11,17 +11,19 @@ -- TODO: automatic use of this function? function trace.sql(args) - local command = args.command - local error_position = args.error_position - if type(command) ~= "string" then - error("No command string passed to trace.sql{...}.") + if not trace._disabled then + local command = args.command + local error_position = args.error_position + if type(command) ~= "string" then + error("No command string passed to trace.sql{...}.") + end + if error_position and type(error_position) ~= "number" then + error("error_position must be a number.") + end + trace._new_entry{ + type = "sql", + command = command, + error_position = error_position + } end - if error_position and type(error_position) ~= "number" then - error("error_position must be a number.") - end - trace._new_entry{ - type = "sql", - command = command, - error_position = error_position - } end