# HG changeset patch # User Matthew Wild # Date 1430225527 -3600 # Node ID 3003d041c15909d31b1c5e9b9964e3e06bd26500 # Parent 9d2b56fd6b472c2e5354f82f7b81f9dced80107d moduleapi: Experimental API for modules to measure the rate+duration of events diff -r 9d2b56fd6b47 -r 3003d041c159 core/moduleapi.lua --- 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;