webmcp

changeset 41:0bbfee4d4aed

New functions trace.disable() and trace.is_disabled()
author jbe
date Sat Oct 16 17:51:18 2010 +0200 (2010-10-16)
parents ed00b972f40e
children 5ce77ccdd550
files framework/env/trace/__init.lua framework/env/trace/debug.lua framework/env/trace/disable.lua framework/env/trace/enter_action.lua framework/env/trace/enter_config.lua framework/env/trace/enter_filter.lua framework/env/trace/enter_view.lua framework/env/trace/error.lua framework/env/trace/exectime.lua framework/env/trace/execution_return.lua framework/env/trace/forward.lua framework/env/trace/is_disabled.lua framework/env/trace/redirect.lua framework/env/trace/render.lua framework/env/trace/request.lua framework/env/trace/restore_slots.lua framework/env/trace/sql.lua
line diff
     1.1 --- a/framework/env/trace/__init.lua	Sat Oct 16 17:49:11 2010 +0200
     1.2 +++ b/framework/env/trace/__init.lua	Sat Oct 16 17:51:18 2010 +0200
     1.3 @@ -1,2 +1,3 @@
     1.4 +trace._disabled = false
     1.5  trace._tree = { type = "root" }
     1.6  trace._stack = { trace._tree }
     2.1 --- a/framework/env/trace/debug.lua	Sat Oct 16 17:49:11 2010 +0200
     2.2 +++ b/framework/env/trace/debug.lua	Sat Oct 16 17:51:18 2010 +0200
     2.3 @@ -8,10 +8,12 @@
     2.4  --]]--
     2.5  
     2.6  function trace.debug(...)
     2.7 -  local message = ""
     2.8 -  local arg = {...}
     2.9 -  for i= 1,#arg,1 do
    2.10 -    message = message..tostring(arg[i]).." "
    2.11 +  if not trace._disabled then
    2.12 +    local message = ""
    2.13 +    local arg = {...}
    2.14 +    for i= 1,#arg,1 do
    2.15 +      message = message..tostring(arg[i]).." "
    2.16 +    end
    2.17 +    trace._new_entry{ type = "debug", message = message }
    2.18    end
    2.19 -  trace._new_entry{ type = "debug", message = message }
    2.20  end
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/framework/env/trace/disable.lua	Sat Oct 16 17:51:18 2010 +0200
     3.3 @@ -0,0 +1,10 @@
     3.4 +--[[--
     3.5 +trace.disable()
     3.6 +
     3.7 +This function disables the trace system. Re-enabling the trace system is not possible.
     3.8 +
     3.9 +--]]--
    3.10 +
    3.11 +function trace.disable()
    3.12 +  trace._disabled = true
    3.13 +end
     4.1 --- a/framework/env/trace/enter_action.lua	Sat Oct 16 17:49:11 2010 +0200
     4.2 +++ b/framework/env/trace/enter_action.lua	Sat Oct 16 17:51:18 2010 +0200
     4.3 @@ -9,13 +9,15 @@
     4.4  --]]--
     4.5  
     4.6  function trace.enter_action(args)
     4.7 -  local module = args.module
     4.8 -  local action = args.action
     4.9 -  if type(module) ~= "string" then
    4.10 -    error("No module string passed to trace.enter_action{...}.")
    4.11 +  if not trace._disabled then
    4.12 +    local module = args.module
    4.13 +    local action = args.action
    4.14 +    if type(module) ~= "string" then
    4.15 +      error("No module string passed to trace.enter_action{...}.")
    4.16 +    end
    4.17 +    if type(action) ~= "string" then
    4.18 +      error("No action string passed to trace.enter_action{...}.")
    4.19 +    end
    4.20 +    trace._open_section{ type = "action", module = module, action = action }
    4.21    end
    4.22 -  if type(action) ~= "string" then
    4.23 -    error("No action string passed to trace.enter_action{...}.")
    4.24 -  end
    4.25 -  trace._open_section{ type = "action", module = module, action = action }
    4.26  end
     5.1 --- a/framework/env/trace/enter_config.lua	Sat Oct 16 17:49:11 2010 +0200
     5.2 +++ b/framework/env/trace/enter_config.lua	Sat Oct 16 17:51:18 2010 +0200
     5.3 @@ -8,9 +8,11 @@
     5.4  --]]--
     5.5  
     5.6  function trace.enter_config(args)
     5.7 -  local name = args.name
     5.8 -  if type(name) ~= "string" then
     5.9 -    error("No name string passed to trace.enter_config{...}.")
    5.10 +  if not trace._disabled then
    5.11 +    local name = args.name
    5.12 +    if type(name) ~= "string" then
    5.13 +      error("No name string passed to trace.enter_config{...}.")
    5.14 +    end
    5.15 +    trace._open_section{ type = "config", name = name }
    5.16    end
    5.17 -  trace._open_section{ type = "config", name = name }
    5.18  end
     6.1 --- a/framework/env/trace/enter_filter.lua	Sat Oct 16 17:49:11 2010 +0200
     6.2 +++ b/framework/env/trace/enter_filter.lua	Sat Oct 16 17:51:18 2010 +0200
     6.3 @@ -8,9 +8,11 @@
     6.4  --]]--
     6.5  
     6.6  function trace.enter_filter(args)
     6.7 -  local path = args.path
     6.8 -  if type(path) ~= "string" then
     6.9 -    error("No path string passed to trace.enter_filter{...}.")
    6.10 +  if not trace._disabled then
    6.11 +    local path = args.path
    6.12 +    if type(path) ~= "string" then
    6.13 +      error("No path string passed to trace.enter_filter{...}.")
    6.14 +    end
    6.15 +    trace._open_section{ type = "filter", path = path }
    6.16    end
    6.17 -  trace._open_section{ type = "filter", path = path }
    6.18  end
     7.1 --- a/framework/env/trace/enter_view.lua	Sat Oct 16 17:49:11 2010 +0200
     7.2 +++ b/framework/env/trace/enter_view.lua	Sat Oct 16 17:51:18 2010 +0200
     7.3 @@ -9,13 +9,15 @@
     7.4  --]]--
     7.5  
     7.6  function trace.enter_view(args)
     7.7 -  local module = args.module
     7.8 -  local view   = args.view
     7.9 -  if type(module) ~= "string" then
    7.10 -    error("No module passed to trace.enter_view{...}.")
    7.11 +  if not trace._disabled then
    7.12 +    local module = args.module
    7.13 +    local view   = args.view
    7.14 +    if type(module) ~= "string" then
    7.15 +      error("No module passed to trace.enter_view{...}.")
    7.16 +    end
    7.17 +    if type(view) ~= "string" then
    7.18 +      error("No view passed to trace.enter_view{...}.")
    7.19 +    end
    7.20 +    trace._open_section{ type = "view", module = module, view = view }
    7.21    end
    7.22 -  if type(view) ~= "string" then
    7.23 -    error("No view passed to trace.enter_view{...}.")
    7.24 -  end
    7.25 -  trace._open_section{ type = "view", module = module, view = view }
    7.26  end
     8.1 --- a/framework/env/trace/error.lua	Sat Oct 16 17:49:11 2010 +0200
     8.2 +++ b/framework/env/trace/error.lua	Sat Oct 16 17:51:18 2010 +0200
     8.3 @@ -7,8 +7,10 @@
     8.4  --]]--
     8.5  
     8.6  function trace.error(args)
     8.7 -  trace._new_entry { type = "error" }
     8.8 -  local closed_section = trace._close_section()
     8.9 -  closed_section.hard_error = true  -- TODO: not used, maybe remove
    8.10 -  trace._stack = { trace._tree }
    8.11 +  if not trace._disabled then
    8.12 +    trace._new_entry { type = "error" }
    8.13 +    local closed_section = trace._close_section()
    8.14 +    closed_section.hard_error = true  -- TODO: not used, maybe remove
    8.15 +    trace._stack = { trace._tree }
    8.16 +  end
    8.17  end
     9.1 --- a/framework/env/trace/exectime.lua	Sat Oct 16 17:49:11 2010 +0200
     9.2 +++ b/framework/env/trace/exectime.lua	Sat Oct 16 17:51:18 2010 +0200
     9.3 @@ -9,13 +9,15 @@
     9.4  --]]--
     9.5  
     9.6  function trace.exectime(args)
     9.7 -  local real = args.real
     9.8 -  local cpu  = args.cpu
     9.9 -  if type(real) ~= "number" then
    9.10 -    error("Called trace.exectime{...} without numeric 'real' argument.")
    9.11 +  if not trace._disabled then
    9.12 +    local real = args.real
    9.13 +    local cpu  = args.cpu
    9.14 +    if type(real) ~= "number" then
    9.15 +      error("Called trace.exectime{...} without numeric 'real' argument.")
    9.16 +    end
    9.17 +    if type(cpu) ~= "number" then
    9.18 +      error("Called trace.exectime{...} without numeric 'cpu' argument.")
    9.19 +    end
    9.20 +    trace._new_entry{ type = "exectime", real = args.real, cpu = args.cpu }
    9.21    end
    9.22 -  if type(cpu) ~= "number" then
    9.23 -    error("Called trace.exectime{...} without numeric 'cpu' argument.")
    9.24 -  end
    9.25 -  trace._new_entry{ type = "exectime", real = args.real, cpu = args.cpu }
    9.26  end
    10.1 --- a/framework/env/trace/execution_return.lua	Sat Oct 16 17:49:11 2010 +0200
    10.2 +++ b/framework/env/trace/execution_return.lua	Sat Oct 16 17:51:18 2010 +0200
    10.3 @@ -8,13 +8,15 @@
    10.4  --]]--
    10.5  
    10.6  function trace.execution_return(args)
    10.7 -  local status
    10.8 -  if args then
    10.9 -    status = args.status
   10.10 +  if not trace._disabled then
   10.11 +    local status
   10.12 +    if args then
   10.13 +      status = args.status
   10.14 +    end
   10.15 +    if status and type(status) ~= "string" then
   10.16 +      error("Status passed to trace.execution_return{...} is not a string.")
   10.17 +    end
   10.18 +    local closed_section = trace._close_section()
   10.19 +    closed_section.status = status
   10.20    end
   10.21 -  if status and type(status) ~= "string" then
   10.22 -    error("Status passed to trace.execution_return{...} is not a string.")
   10.23 -  end
   10.24 -  local closed_section = trace._close_section()
   10.25 -  closed_section.status = status
   10.26  end
    11.1 --- a/framework/env/trace/forward.lua	Sat Oct 16 17:49:11 2010 +0200
    11.2 +++ b/framework/env/trace/forward.lua	Sat Oct 16 17:51:18 2010 +0200
    11.3 @@ -9,13 +9,15 @@
    11.4  --]]--
    11.5  
    11.6  function trace.forward(args)
    11.7 -  local module = args.module
    11.8 -  local view   = args.view
    11.9 -  if type(module) ~= "string" then
   11.10 -    error("No module string passed to trace.forward{...}.")
   11.11 +  if not trace._disabled then
   11.12 +    local module = args.module
   11.13 +    local view   = args.view
   11.14 +    if type(module) ~= "string" then
   11.15 +      error("No module string passed to trace.forward{...}.")
   11.16 +    end
   11.17 +    if type(view) ~= "string" then
   11.18 +      error("No view string passed to trace.forward{...}.")
   11.19 +    end
   11.20 +    trace._new_entry{ type = "forward", module = module, view = view }
   11.21    end
   11.22 -  if type(view) ~= "string" then
   11.23 -    error("No view string passed to trace.forward{...}.")
   11.24 -  end
   11.25 -  trace._new_entry{ type = "forward", module = module, view = view }
   11.26  end
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/framework/env/trace/is_disabled.lua	Sat Oct 16 17:51:18 2010 +0200
    12.3 @@ -0,0 +1,11 @@
    12.4 +--[[--
    12.5 +disabled =           -- boolean indicating if trace system is disabled
    12.6 +trace.is_disabled()
    12.7 +
    12.8 +This function returns true, if the trace system has been disabled. Otherwise false is returned.
    12.9 +
   12.10 +--]]--
   12.11 +
   12.12 +function trace.is_disabled()
   12.13 +  return trace._disabled
   12.14 +end
    13.1 --- a/framework/env/trace/redirect.lua	Sat Oct 16 17:49:11 2010 +0200
    13.2 +++ b/framework/env/trace/redirect.lua	Sat Oct 16 17:51:18 2010 +0200
    13.3 @@ -9,13 +9,15 @@
    13.4  --]]--
    13.5  
    13.6  function trace.redirect(args)
    13.7 -  local module = args.module
    13.8 -  local view   = args.view
    13.9 -  if type(module) ~= "string" then
   13.10 -    error("No module string passed to trace.redirect{...}.")
   13.11 +  if not trace._disabled then
   13.12 +    local module = args.module
   13.13 +    local view   = args.view
   13.14 +    if type(module) ~= "string" then
   13.15 +      error("No module string passed to trace.redirect{...}.")
   13.16 +    end
   13.17 +    if type(view) ~= "string" then
   13.18 +      error("No view string passed to trace.redirect{...}.")
   13.19 +    end
   13.20 +    trace._new_entry{ type = "redirect", module = module, view = view }
   13.21    end
   13.22 -  if type(view) ~= "string" then
   13.23 -    error("No view string passed to trace.redirect{...}.")
   13.24 -  end
   13.25 -  trace._new_entry{ type = "redirect", module = module, view = view }
   13.26  end
    14.1 --- a/framework/env/trace/render.lua	Sat Oct 16 17:49:11 2010 +0200
    14.2 +++ b/framework/env/trace/render.lua	Sat Oct 16 17:51:18 2010 +0200
    14.3 @@ -6,6 +6,8 @@
    14.4  --]]--
    14.5  
    14.6  function trace.render()
    14.7 -  -- TODO: check if all sections are closed?
    14.8 -  trace._render_sub_tree(trace._tree)
    14.9 +  if not trace._disabled then
   14.10 +    -- TODO: check if all sections are closed?
   14.11 +    trace._render_sub_tree(trace._tree)
   14.12 +  end
   14.13  end
    15.1 --- a/framework/env/trace/request.lua	Sat Oct 16 17:49:11 2010 +0200
    15.2 +++ b/framework/env/trace/request.lua	Sat Oct 16 17:51:18 2010 +0200
    15.3 @@ -10,28 +10,30 @@
    15.4  --]]--
    15.5  
    15.6  function trace.request(args)
    15.7 -  local module       = args.module
    15.8 -  local view         = args.view
    15.9 -  local action       = args.action
   15.10 -  if type(module) ~= "string" then
   15.11 -    error("No module string passed to trace.request{...}.")
   15.12 -  end
   15.13 -  if view and action then
   15.14 -    error("Both view and action passed to trace.request{...}.")
   15.15 -  end
   15.16 -  if not (view or action) then
   15.17 -    error("Neither view nor action passed to trace.request{...}.")
   15.18 +  if not trace._disabled then
   15.19 +    local module       = args.module
   15.20 +    local view         = args.view
   15.21 +    local action       = args.action
   15.22 +    if type(module) ~= "string" then
   15.23 +      error("No module string passed to trace.request{...}.")
   15.24 +    end
   15.25 +    if view and action then
   15.26 +      error("Both view and action passed to trace.request{...}.")
   15.27 +    end
   15.28 +    if not (view or action) then
   15.29 +      error("Neither view nor action passed to trace.request{...}.")
   15.30 +    end
   15.31 +    if view and type(view) ~= "string" then
   15.32 +      error("No view string passed to trace.request{...}.")
   15.33 +    end
   15.34 +    if action and type(action) ~= "string" then
   15.35 +      error("No action string passed to trace.request{...}.")
   15.36 +    end
   15.37 +    trace._new_entry{
   15.38 +      type = "request",
   15.39 +      module       = args.module,
   15.40 +      view         = args.view,
   15.41 +      action       = args.action
   15.42 +    }
   15.43    end
   15.44 -  if view and type(view) ~= "string" then
   15.45 -    error("No view string passed to trace.request{...}.")
   15.46 -  end
   15.47 -  if action and type(action) ~= "string" then
   15.48 -    error("No action string passed to trace.request{...}.")
   15.49 -  end
   15.50 -  trace._new_entry{
   15.51 -    type = "request",
   15.52 -    module       = args.module,
   15.53 -    view         = args.view,
   15.54 -    action       = args.action
   15.55 -  }
   15.56  end
    16.1 --- a/framework/env/trace/restore_slots.lua	Sat Oct 16 17:49:11 2010 +0200
    16.2 +++ b/framework/env/trace/restore_slots.lua	Sat Oct 16 17:51:18 2010 +0200
    16.3 @@ -7,5 +7,7 @@
    16.4  --]]--
    16.5  
    16.6  function trace.restore_slots(args)
    16.7 -  trace._new_entry{ type = "restore_slots" }
    16.8 +  if not trace._disabled then
    16.9 +    trace._new_entry{ type = "restore_slots" }
   16.10 +  end
   16.11  end
    17.1 --- a/framework/env/trace/sql.lua	Sat Oct 16 17:49:11 2010 +0200
    17.2 +++ b/framework/env/trace/sql.lua	Sat Oct 16 17:51:18 2010 +0200
    17.3 @@ -11,17 +11,19 @@
    17.4  -- TODO: automatic use of this function?
    17.5  
    17.6  function trace.sql(args)
    17.7 -  local command = args.command
    17.8 -  local error_position = args.error_position
    17.9 -  if type(command) ~= "string" then
   17.10 -    error("No command string passed to trace.sql{...}.")
   17.11 +  if not trace._disabled then
   17.12 +    local command = args.command
   17.13 +    local error_position = args.error_position
   17.14 +    if type(command) ~= "string" then
   17.15 +      error("No command string passed to trace.sql{...}.")
   17.16 +    end
   17.17 +    if error_position and type(error_position) ~= "number" then
   17.18 +      error("error_position must be a number.")
   17.19 +    end
   17.20 +    trace._new_entry{
   17.21 +      type = "sql",
   17.22 +      command = command,
   17.23 +      error_position = error_position
   17.24 +    }
   17.25    end
   17.26 -  if error_position and type(error_position) ~= "number" then
   17.27 -    error("error_position must be a number.")
   17.28 -  end
   17.29 -  trace._new_entry{
   17.30 -    type = "sql",
   17.31 -    command = command,
   17.32 -    error_position = error_position
   17.33 -  }
   17.34  end

Impressum / About Us