webmcp

view framework/env/__init.lua @ 302:04b648660f9a

Time triple (cpu/db/total) for trace system
author jbe
date Sun Mar 22 20:06:26 2015 +0100 (2015-03-22)
parents 1fbdccf4f8e9
children 1c3ba14bd679
line source
1 -- string localization function
2 function _(text, replacements)
3 local text = locale._get_translation_table()[text] or text
4 if replacements then
5 return (
6 string.gsub(
7 text,
8 "#{(.-)}",
9 function (placeholder)
10 return replacements[placeholder]
11 end
12 )
13 )
14 else
15 return text
16 end
17 end
19 --[[--
20 cloned_table = -- newly generated table
21 table.new(
22 table_or_nil -- keys of a given table will be copied to the new table
23 )
25 If a table is given, then a cloned table is returned.
26 If nil is given, then a new empty table is returned.
28 --]]--
29 function table.new(tbl)
30 local new_tbl = {}
31 if tbl then
32 for key, value in pairs(tbl) do
33 new_tbl[key] = value
34 end
35 end
36 return new_tbl
37 end
38 --//--
40 -- load libraries (except "multirand", which must be loaded after forking)
41 extos = require 'extos'
42 nihil = require 'nihil'
43 mondelefant = require 'mondelefant'
44 atom = require 'atom'
45 json = require 'json'
46 require 'mondelefant_atom_connector'
47 -- NOTE: "multirand" library is loaded in mcp.lua after forking
49 -- setup mondelefant
50 mondelefant.connection_prototype.error_objects = true
51 function mondelefant.connection_prototype:sql_tracer(command)
52 if trace.is_disabled() then
53 return
54 end
55 local start_time = extos.monotonic_hires_time()
56 return function(error_info)
57 trace.sql{
58 command = command,
59 execution_time = extos.monotonic_hires_time() - start_time,
60 error_position = error_info and error_info.position or nil
61 }
62 end
63 end
65 --[[--
66 config -- table to store application configuration
68 'config' is a global table, which can be modified by a config file of an application to modify the behaviour of that application.
69 --]]--
70 config = {}
71 --//--

Impressum / About Us