[MemoryDataCollector] Stop being optimistic about memory usage
Take into account the memory used in the kernel.terminate listeners
This commit is contained in:
parent
e621b6f169
commit
4c0c588a68
@ -21,14 +21,17 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
*/
|
*/
|
||||||
class MemoryDataCollector extends DataCollector
|
class MemoryDataCollector extends DataCollector
|
||||||
{
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->data = array('memory' => 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function collect(Request $request, Response $response, \Exception $exception = null)
|
public function collect(Request $request, Response $response, \Exception $exception = null)
|
||||||
{
|
{
|
||||||
$this->data = array(
|
$this->updateMemoryUsage();
|
||||||
'memory' => memory_get_peak_usage(true),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,6 +44,14 @@ class MemoryDataCollector extends DataCollector
|
|||||||
return $this->data['memory'];
|
return $this->data['memory'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the memory usage data.
|
||||||
|
*/
|
||||||
|
public function updateMemoryUsage()
|
||||||
|
{
|
||||||
|
$this->data['memory'] = memory_get_peak_usage(true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -204,7 +204,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, TraceableEve
|
|||||||
$skipped = false;
|
$skipped = false;
|
||||||
|
|
||||||
foreach ($skippedListeners as $skippedListener) {
|
foreach ($skippedListeners as $skippedListener) {
|
||||||
$skippedListener = $this->unwrapListener($skippedListener, $eventName);
|
$skippedListener = $this->unwrapListener($skippedListener);
|
||||||
|
|
||||||
if ($skipped) {
|
if ($skipped) {
|
||||||
$info = $this->getListenerInfo($skippedListener, $eventName);
|
$info = $this->getListenerInfo($skippedListener, $eventName);
|
||||||
@ -254,7 +254,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, TraceableEve
|
|||||||
*/
|
*/
|
||||||
private function getListenerInfo($listener, $eventName)
|
private function getListenerInfo($listener, $eventName)
|
||||||
{
|
{
|
||||||
$listener = $this->unwrapListener($listener, $eventName);
|
$listener = $this->unwrapListener($listener);
|
||||||
|
|
||||||
$info = array(
|
$info = array(
|
||||||
'event' => $eventName,
|
'event' => $eventName,
|
||||||
@ -329,9 +329,25 @@ class TraceableEventDispatcher implements EventDispatcherInterface, TraceableEve
|
|||||||
*/
|
*/
|
||||||
private function saveInfoInProfile(Profile $profile, $updateChildren)
|
private function saveInfoInProfile(Profile $profile, $updateChildren)
|
||||||
{
|
{
|
||||||
$profile->getCollector('time')->setEvents($this->stopwatch->getSectionEvents($profile->getToken()));
|
try {
|
||||||
$profile->getCollector('events')->setCalledListeners($this->getCalledListeners());
|
$collector = $profile->getCollector('memory');
|
||||||
$profile->getCollector('events')->setNotCalledListeners($this->getNotCalledListeners());
|
$collector->updateMemoryUsage();
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$collector = $profile->getCollector('time');
|
||||||
|
$collector->setEvents($this->stopwatch->getSectionEvents($profile->getToken()));
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$collector = $profile->getCollector('events');
|
||||||
|
$collector->setCalledListeners($this->getCalledListeners());
|
||||||
|
$collector->setNotCalledListeners($this->getNotCalledListeners());
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
}
|
||||||
|
|
||||||
$this->profiler->saveProfile($profile);
|
$this->profiler->saveProfile($profile);
|
||||||
|
|
||||||
if ($updateChildren) {
|
if ($updateChildren) {
|
||||||
@ -341,19 +357,6 @@ class TraceableEventDispatcher implements EventDispatcherInterface, TraceableEve
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getListenerAsString($listener)
|
|
||||||
{
|
|
||||||
if (is_string($listener)) {
|
|
||||||
return '[string] '.$listener;
|
|
||||||
} elseif (is_array($listener)) {
|
|
||||||
return '[array] '.(is_object($listener[0]) ? get_class($listener[0]) : $listener[0]).'::'.$listener[1];
|
|
||||||
} elseif (is_object($listener)) {
|
|
||||||
return '[object] '.get_class($listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
return '[?] '.var_export($listener, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function preDispatch($eventName, Event $event)
|
private function preDispatch($eventName, Event $event)
|
||||||
{
|
{
|
||||||
// wrap all listeners before they are called
|
// wrap all listeners before they are called
|
||||||
@ -437,7 +440,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, TraceableEve
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private function unwrapListener($listener, $eventName)
|
private function unwrapListener($listener)
|
||||||
{
|
{
|
||||||
// get the original listener
|
// get the original listener
|
||||||
if (is_object($listener) && isset($this->wrappedListeners[$this->id][$listener])) {
|
if (is_object($listener) && isset($this->wrappedListeners[$this->id][$listener])) {
|
||||||
|
Reference in New Issue
Block a user