Skip to content

Commit

Permalink
Merge pull request #37 from ryden54/hotfix/memory-leak-without-profiler
Browse files Browse the repository at this point in the history
memory-leak-without-profiler
  • Loading branch information
evaisse authored Sep 30, 2021
2 parents 26e789c + e1a497e commit 648bb44
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 18 additions & 1 deletion DataCollector/ProfilerDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
*/
class ProfilerDataCollector extends DataCollector implements EventSubscriberInterface
{

/** @var bool */
protected $debug;

/**
* List of emitted requests
Expand All @@ -56,6 +57,13 @@ class ProfilerDataCollector extends DataCollector implements EventSubscriberInte
*/
protected $stopwatch;

/**
* @param bool $debug
*/
public function __construct(bool $debug)
{
$this->debug = $debug;
}

/**
* (non-PHPdoc)
Expand Down Expand Up @@ -155,6 +163,9 @@ public function normalizeCalls()

public function onPrepare(RequestEvent $event)
{
if (!$this->debug) {
return;
}
$request = $event->getRequest();

$eventName = "#" . count($this->calls) . ' ' . $request->getMethod() . ' ' . $request->getUri();
Expand Down Expand Up @@ -193,6 +204,9 @@ public function getRequestKey($request)

public function onError(ExceptionEvent $event)
{
if (!$this->debug) {
return;
}
$key = $this->getRequestKey($event->getRequest());

$this->errors++;
Expand All @@ -208,6 +222,9 @@ public function onError(ExceptionEvent $event)

public function onSuccess(ResponseEvent $event)
{
if (!$this->debug) {
return;
}
$key = $this->getRequestKey($event->getRequest());

$this->calls[$key] = array_merge($this->calls[$key], array(
Expand Down
2 changes: 2 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ services:
simple_http.profiler.data_collector:
class: evaisse\SimpleHttpBundle\DataCollector\ProfilerDataCollector
public: true
arguments:
$debug: '%kernel.debug%'
calls:
- [ setStopWatch, [ "@debug.stopwatch" ] ]
tags:
Expand Down

0 comments on commit 648bb44

Please sign in to comment.