annotate mod_log_events_by_cpu_usage/mod_log_events_by_cpu_usage.lua @ 4651:8231774f5bfd

mod_cloud_notify_encrypted: Ensure body substring remains valid UTF-8 The `body:sub()` call risks splitting the string in the middle of a multi-byte UTF-8 sequence. This should have been caught by util.stanza validation, but that would have caused some havoc, at the very least causing the notification to not be sent. There have been no reports of this happening. Likely because this module isn't widely deployed among users with languages that use many longer UTF-8 sequences. The util.encodings.utf8.valid() function is O(n) where only the last sequence really needs to be checked, but it's in C and expected to be fast.
author Kim Alvefur <zash@zash.se>
date Sun, 22 Aug 2021 13:22:59 +0200
parents c0bc97c0ba61
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3615
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 module:set_global();
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
3616
c0bc97c0ba61 mod_log_events_by_cpu_usage: Log events where more than a certain amount of CPU time was spent
Kim Alvefur <zash@zash.se>
parents: 3615
diff changeset
3 local treshold = module:get_option_number("log_cpu_threshold", 0.01);
3615
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 function event_wrapper(handlers, event_name, event_data)
3616
c0bc97c0ba61 mod_log_events_by_cpu_usage: Log events where more than a certain amount of CPU time was spent
Kim Alvefur <zash@zash.se>
parents: 3615
diff changeset
6 local cpu_before = os.clock();
3615
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local ret = handlers(event_name, event_data);
3616
c0bc97c0ba61 mod_log_events_by_cpu_usage: Log events where more than a certain amount of CPU time was spent
Kim Alvefur <zash@zash.se>
parents: 3615
diff changeset
8 local cpu_after = os.clock();
c0bc97c0ba61 mod_log_events_by_cpu_usage: Log events where more than a certain amount of CPU time was spent
Kim Alvefur <zash@zash.se>
parents: 3615
diff changeset
9 if (cpu_after - cpu_before) > treshold then
c0bc97c0ba61 mod_log_events_by_cpu_usage: Log events where more than a certain amount of CPU time was spent
Kim Alvefur <zash@zash.se>
parents: 3615
diff changeset
10 module:log("warn", "%g seconds of CPU usage while processing event '%s'", (cpu_after - cpu_before), event_name);
3615
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 end
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 return ret;
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 end
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local http_events = require "net.http.server"._events;
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 module:wrap_object_event(http_events, false, event_wrapper);
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 module:wrap_event(false, event_wrapper);
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 function module.add_host(module)
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 module:wrap_event(false, event_wrapper);
5fe34e5f9829 mod_log_events_by_memory: Log events where Lua memory usage increased
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 end