Comparison

core/moduleapi.lua @ 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
parent 6556:74253c7beb9c
child 6640:859e9af53aa1
comparison
equal deleted inserted replaced
6638:9d2b56fd6b47 6639:3003d041c159
373 373
374 function api:measure(name, type) 374 function api:measure(name, type)
375 return measure(type, "/"..self.host.."/mod_"..self.name.."/"..name); 375 return measure(type, "/"..self.host.."/mod_"..self.name.."/"..name);
376 end 376 end
377 377
378 function api:measure_object_event(events_object, event_name, stat_name)
379 local m = self:measure(stat_name or event_name, "duration");
380 local function handler(handlers, event_name, event_data)
381 local finished = m();
382 local ret = handlers(event_name, event_data);
383 finished();
384 return ret;
385 end
386 return self:hook_object_event(events_object, event_name, handler);
387 end
388
389 function api:measure_event(event_name, stat_name)
390 return self:hook_object_event((hosts[self.host] or prosody).events.wrappers, event_name, handler);
391 end
392
393 function api:measure_global_event(event_name, stat_name)
394 return self:hook_object_event(prosody.events.wrappers, event_name, handler);
395 end
396
378 function api.init(mm) 397 function api.init(mm)
379 modulemanager = mm; 398 modulemanager = mm;
380 return api; 399 return api;
381 end 400 end
382 401