TimeCollector & MemoryCollector - Event-level data
moderndeveloperllc opened this issue · 5 comments
@Ocramius It looks like quite a bit of work had been done towards having event-level stats for TimeCollector and MemoryCollector. Pretty much everything but the listener and config options. Do you know why this was halted? The README.dev mentions:
Note: This will most likely be removed due to event manager profiling
improvements.
but nothing more is mentioned anywhere I can see. I could finish off the current work and expand it to attach a universal listener so any user-created triggers would be included.
@moderndeveloperllc instead of building an "universal" listener, simply a collector attached to the Shared EVM would be enough, no?
I believe we are thinking the same thing, I was going to add an EventListener that would check the options to see which event-level collectors had been included and a flag (to be added) to enable it or not.
in Module.php onBootstrap()
:
$em->attachAggregate($sm->get('ZendDeveloperTools\ProfilerListener'));
if ($options->collectEvents() && count($options->getEventCollectors())) {
$em->attachAggregate($sm->get('ZendDeveloperTools\EventListener'));
}
...
'ZendDeveloperTools\EventListener' => function ($sm) {
return new Listener\EventListener($sm, $sm->get('ZendDeveloperTools\Config'));
},
The Listener\EventListener
would be set up like ProfileListener
public function attach(EventManagerInterface $events)
{
$this->listeners[] = $events->attach(
*,
array($this, 'onCollectEvent'),
Profiler::PRIORITY_EVENT_COLLECTOR
);
}
public function onCollectEvent(Event $event)
{
$strict = $this->options->isStrict();
$collectors = $this->options->getEventCollectors();
$report = $this->serviceLocator->get('ZendDeveloperTools\Report');
foreach ($collectors as $name => $collector) {
if ($this->serviceLocator->has($collector)) {
$this->serviceLocator->get($collector)->collectEvent($event->getTarget(), $event->getName());
} else {
$error = sprintf('Unable to fetch or create an instance for %s.', $collector);
if ($strict === true) {
throw new ServiceNotFoundException($error);
} else {
$report->addError($error);
}
}
}
}
I will be the first to admit that I'm not fully up on the intricacies of the EventManager vs the SharedEventManager, so feel free to tell me if I'm way off base.
Actually that attachAggregate needs to be on $sem. I think I get it now, so I will actually write all this and put in a PR when it works.