|
@@ -32,6 +32,7 @@ class ProfilerListener
|
|
|
protected $onlyMasterRequests;
|
|
|
protected $exception;
|
|
|
protected $children;
|
|
|
+ protected $requests;
|
|
|
|
|
|
/**
|
|
|
* Constructor.
|
|
@@ -47,7 +48,7 @@ class ProfilerListener
|
|
|
$this->matcher = $matcher;
|
|
|
$this->onlyException = (Boolean) $onlyException;
|
|
|
$this->onlyMasterRequests = (Boolean) $onlyMasterRequests;
|
|
|
- $this->children = array();
|
|
|
+ $this->children = new \SplObjectStorage();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -64,6 +65,11 @@ class ProfilerListener
|
|
|
$this->exception = $event->getException();
|
|
|
}
|
|
|
|
|
|
+ public function onKernelRequest(GetResponseEvent $event)
|
|
|
+ {
|
|
|
+ $this->requests[] = $event->getRequest();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Handles the onKernelResponse event.
|
|
|
*
|
|
@@ -87,18 +93,35 @@ class ProfilerListener
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if ($profile = $this->profiler->collect($event->getRequest(), $event->getResponse(), $exception)) {
|
|
|
- if ($master) {
|
|
|
- foreach ($this->children as $child) {
|
|
|
- $child->setParent($profile);
|
|
|
- $profile->addChild($child);
|
|
|
- $this->profiler->saveProfile($child);
|
|
|
- }
|
|
|
- $this->profiler->saveProfile($profile);
|
|
|
- $this->children = array();
|
|
|
+ if (!$profile = $this->profiler->collect($event->getRequest(), $event->getResponse(), $exception)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ array_pop($this->requests);
|
|
|
+
|
|
|
+ // keep the profile as the child of its parent
|
|
|
+ if (!$master) {
|
|
|
+ $parent = $this->requests[count($this->requests) - 1];
|
|
|
+ if (!isset($this->children[$parent])) {
|
|
|
+ $profiles = array($profile);
|
|
|
} else {
|
|
|
- $this->children[] = $profile;
|
|
|
+ $profiles = $this->children[$parent];
|
|
|
+ $profiles[] = $profile;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->children[$parent] = $profiles;
|
|
|
+ }
|
|
|
+
|
|
|
+ // store the profile and its children
|
|
|
+ if (isset($this->children[$event->getRequest()])) {
|
|
|
+ foreach ($this->children[$event->getRequest()] as $child) {
|
|
|
+ $child->setParent($profile);
|
|
|
+ $profile->addChild($child);
|
|
|
+ $this->profiler->saveProfile($child);
|
|
|
}
|
|
|
+ $this->children[$event->getRequest()] = array();
|
|
|
}
|
|
|
+
|
|
|
+ $this->profiler->saveProfile($profile);
|
|
|
}
|
|
|
}
|