Commit 52b0927f2382fa29729d719c97499d295e9db82e

Authored by Cédric RICARD
1 parent 15bb49b1

Added performances logs for long SQL queries (more than 1 second)

calexium_lib/database/db_utils.anubis
... ... @@ -9,10 +9,30 @@
9 9  
10 10 read tools/basis.anubis
11 11 read system/logger.anubis
  12 +read system/string.anubis
12 13 read data_base/sqlite.anubis
13 14  
14 15 read calexium_lib/net_services_protocols/logger_service.anubis
15 16  
  17 +define String
  18 + __utime_to_string
  19 + (
  20 + UTime t
  21 + ) =
  22 + to_decimal(t.seconds) + "." + zero_pad_n(6, t.microseconds ) + " s".
  23 +
  24 +define One
  25 + __logLongQueries
  26 + (
  27 + UTime t0,
  28 + String sql_query
  29 + ) =
  30 + with t = unow - t0,
  31 + if t.seconds > 0 then
  32 + logTrace("SQL", logMask("sql_profiling"), "[SQL] " + __utime_to_string(t) + " executing [" + sql_query + "]")
  33 + else
  34 + unique.
  35 +
16 36 public define Result(SQLite3Error, One)
17 37 sql_transaction
18 38 (
... ... @@ -21,6 +41,7 @@ public define Result(SQLite3Error, One)
21 41 String message
22 42 ) =
23 43 // logDebug(debug_log, "Entering into transaction [" + message + "].");
  44 + with t0 = unow,
24 45 if db_do_transaction(
25 46 db,
26 47 (One _) |->
... ... @@ -36,10 +57,11 @@ public define Result(SQLite3Error, One)
36 57 {
37 58 error(err_and_result) then
38 59 // logDebug(debug_log, "Exiting from transaction [" + message + "] with error.");
39   - if err_and_result is (err, mb_result) then
40   - error(err),
  60 + __logLongQueries(t0, sql_command);
  61 + if err_and_result is (err, mb_result) then error(err),
41 62 ok(_) then
42 63 // logDebug(debug_log, "Exiting from transaction [" + message + "].");
  64 + __logLongQueries(t0, sql_command);
43 65 ok(unique)
44 66 }.
45 67  
... ... @@ -54,10 +76,15 @@ public define SQLite3QueryResult
54 76 String msg //message to be shown if an error occure
55 77 ) =
56 78 //we try with 30 sec of timeout
  79 + with t0 = unow,
57 80 if sql_query_timeout(db, sql_query, initial_bindings, 60, 100) is
58 81 {
59   - error(sql_error) then logError("DB", db_error(sql_error,msg)); error(sql_error),
60   - ok(headers, cursor, reset) then ok(headers, cursor, reset)
  82 + error(sql_error) then logError("DB", db_error(sql_error,msg));
  83 + __logLongQueries(t0, sql_query);
  84 + error(sql_error),
  85 + ok(headers, cursor, reset) then
  86 + __logLongQueries(t0, sql_query);
  87 + ok(headers, cursor, reset)
61 88 }.
62 89  
63 90 // deprecated. Use one of the previous ones.
... ... @@ -69,10 +96,14 @@ public define Maybe(SQLite3HeadersOrRow -> SQLite3Row)
69 96 String msg //message to be shown if an error occure
70 97 ) =
71 98 //we try with 30 sec of timeout
  99 + with t0 = unow,
72 100 if sql_query_timeout(db, sql_query, [], 60, 100) is
73 101 {
74   - error(sql_error) then logError("DB", db_error(sql_error,msg));failure,
  102 + error(sql_error) then logError("DB", db_error(sql_error,msg));
  103 + __logLongQueries(t0, sql_query);
  104 + failure,
75 105 ok(headers, cursor, reset) then
  106 + __logLongQueries(t0, sql_query);
76 107 success((SQLite3HeadersOrRow h_or_r) |-> if h_or_r is
77 108 {
78 109 headers then
... ...
calexium_lib/net_services_protocols/logger_service.anubis
... ... @@ -237,35 +237,6 @@ public define Maybe(UDP_Server)
237 237  
238 238 /****************** CLIENT PART *******************/
239 239  
240   -/*
241   - define One
242   - send_log_msg
243   - (
244   - MessageQueue queue,
245   - Message log_msg
246   - )=
247   - with test_msg = message(_CXM_REQUEST_FOR_SERVICE),
248   - forget(add_int32(test_msg, "service", _CXM_LOGGER_SERVICE_ID));
249   - forget(add_int32(test_msg, "version", 1));
250   - queue.add_Message_to_send(test_msg);
251   - if queue.get_next_received_Message(30) is
252   - {
253   - timeout then println("send_log_msg receive timeout"),
254   - closed then println("send_log_msg socket closed"),
255   - msg(msg) then
256   - if find_int32(msg, "STATUS") is
257   - {
258   - failure then println("status not found"),
259   - success(v) then
260   - if v = _CXM_OK then
261   - queue.add_Message_to_send(log_msg);
262   - forget(wait_for_reply(queue, _CXM_LOGGER_LOG, 30))
263   - else
264   - println("requested service started won't start")
265   - }
266   - }.
267   -*/
268   -
269 240 define One
270 241 local_net_logger
271 242 (
... ... @@ -273,22 +244,7 @@ define One
273 244 Message log_message
274 245 )=
275 246 forget(send_message_by_udp(log_message, ip_address((127,0,0,1)), logger_port)).
276   -
277   -/* if find_string(log_message, "LogString") is
278   - {
279   - failure then println("process_log can't find LogString"),
280   - success(log_string) then println(log_string)
281   - }.
282   - if connect( ip_address((127,0,0,1)), 33125) is
283   - {
284   - error(_) then println("can't connect to logger server ["+logger_server+"]");
285   - forget(process_log(fullLogger, log_message)),
286   - ok(conn) then
287   - with queue = create_MessageQueue("net logger sender"),
288   - message_transceiver(conn, queue);
289   - send_log_msg(queue, log_message);
290   - queue.quit(unique)
291   - }.*/
  247 +
292 248  
293 249 define Message
294 250 create_log_msg
... ... @@ -306,6 +262,67 @@ define Message
306 262 forget(add_int32(log_msg, "Thread", virtual_machine_id));
307 263 log_msg
308 264 .
  265 +*/
  266 +
  267 +// HACK Begin of Hacked version
  268 + define String debug_log = "Debug".
  269 + define String config_log = "Config".
  270 + define String incoming_log = "Incoming".
  271 + define String outgoing_log = "Outgoing".
  272 + define String pop3_log = "POP3".
  273 + define String mailing_log = "Mailing".
  274 + define String errors_log = "Errors".
  275 + define String security_log = "Security".
  276 + define String spams_log = "Spams".
  277 + define String api_log = "MF_API".
  278 + define String internal_log = "INTERNAL".
  279 +
  280 +
  281 + define String
  282 + get_log_file
  283 + (
  284 + String log_name
  285 + ) =
  286 + if log_name = debug_log then "debug.log"
  287 + else if log_name = "SendMail" then "debug.log"
  288 + else if log_name = config_log then "config.log"
  289 + else if log_name = incoming_log then "incoming.log"
  290 + else if log_name = outgoing_log then "outgoing.log"
  291 + else if log_name = pop3_log then "pop3.log"
  292 + else if log_name = mailing_log then "mailing.log"
  293 + else if log_name = errors_log then "errors.log"
  294 + else if log_name = "DB" then "errors.log"
  295 + else if log_name = "SQL" then "sql_profiling.log"
  296 + else if log_name = security_log then "security.log"
  297 + else if log_name = spams_log then "spams.log"
  298 + else if log_name = api_log then "api.log"
  299 + else if log_name = internal_log then "internal"
  300 + else "unknown.log".
  301 +
  302 +
  303 + define One
  304 + local_net_logger
  305 + (
  306 + String logger_server,
  307 + One _
  308 + )=
  309 + unique.
  310 +
  311 + define One
  312 + create_log_msg
  313 + (
  314 + String logger_name,
  315 + String log_string,
  316 + Int level
  317 + )=
  318 + with log = createLogger(logger_name, 8, "/var/MailFountain/log/" + get_log_file(logger_name), logTrace, logTrace),
  319 + logLevel = get_LogLevel_from_value(level),
  320 + protect
  321 + doLog(log, log_string, logLevel, virtual_machine_id).
  322 +
  323 +// HACK End of Hacked version
  324 +
  325 +
309 326  
310 327 public define One
311 328 log(
... ... @@ -366,3 +383,15 @@ public define One
366 383 with log_msg = create_log_msg(logger_name, log_string, 6),
367 384 forget(add_string(log_msg, "LogMask", log_mask.mask));
368 385 local_net_logger("127.0.0.1", log_msg).
  386 +
  387 +// HACK hacked version
  388 + public define One
  389 + logTrace(
  390 + String logger_name,
  391 + LogMask log_mask,
  392 + String log_string
  393 + )=
  394 + if log_mask is logMask(mask) then
  395 + if mask = "send_mail" | mask = "smtp" | mask = "sql_profiling" then
  396 + local_net_logger("127.0.0.1", create_log_msg(logger_name, log_string, 6))
  397 + else unique.
... ...