Software /
code /
prosody
Changeset
6639:3003d041c159
moduleapi: Experimental API for modules to measure the rate+duration of events
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 28 Apr 2015 13:52:07 +0100 |
parents | 6638:9d2b56fd6b47 |
children | 6640:859e9af53aa1 |
files | core/moduleapi.lua |
diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/core/moduleapi.lua Tue Apr 28 13:42:59 2015 +0100 +++ b/core/moduleapi.lua Tue Apr 28 13:52:07 2015 +0100 @@ -375,6 +375,25 @@ 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;