aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2015-04-28 13:52:07 +0100
committerMatthew Wild <mwild1@gmail.com>2015-04-28 13:52:07 +0100
commitdca21b3a3d62ec68759d9065a685e51b54514b1f (patch)
tree36d58298b45be6cefb89cf5ea94ec63d14f589f0 /core
parent720368bbebdb5ce7b31efe5aec4ae6e12cde623b (diff)
downloadprosody-dca21b3a3d62ec68759d9065a685e51b54514b1f.tar.gz
prosody-dca21b3a3d62ec68759d9065a685e51b54514b1f.zip
moduleapi: Experimental API for modules to measure the rate+duration of events
Diffstat (limited to 'core')
-rw-r--r--core/moduleapi.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index e32c116a..71e19e01 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -375,6 +375,25 @@ function api:measure(name, type)
return measure(type, "/"..self.host.."/mod_"..self.name.."/"..name);
end
+function api:measure_object_event(events_object, event_name, stat_name)
+ local m = self:measure(stat_name or event_name, "duration");
+ local function handler(handlers, event_name, event_data)
+ local finished = m();
+ local ret = handlers(event_name, event_data);
+ finished();
+ return ret;
+ end
+ return self:hook_object_event(events_object, event_name, handler);
+end
+
+function api:measure_event(event_name, stat_name)
+ return self:hook_object_event((hosts[self.host] or prosody).events.wrappers, event_name, handler);
+end
+
+function api:measure_global_event(event_name, stat_name)
+ return self:hook_object_event(prosody.events.wrappers, event_name, handler);
+end
+
function api.init(mm)
modulemanager = mm;
return api;