Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

profiler enhancements #460

Merged
merged 1 commit into from Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion DataCollector/PropelDataCollector.php
Expand Up @@ -36,7 +36,7 @@ public function __construct(PropelLogger $logger)
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->data = array(
'queries' => $this->buildQueries(),
'queries' => $this->cloneVar($this->buildQueries()),
'querycount' => $this->countQueries(),
);
}
Expand Down
27 changes: 3 additions & 24 deletions Logger/PropelLogger.php
Expand Up @@ -13,6 +13,7 @@
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerTrait;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\VarDumper\Caster\TraceStub;

/**
* @author Kévin Gomez <contact@kevingomez.fr>
Expand Down Expand Up @@ -64,10 +65,9 @@ public function log($level, $message, array $context = array())
}

$add = true;
$stackTrace = $this->getStackTrace();
$trace = debug_backtrace();

if (null !== $this->stopwatch) {
$trace = debug_backtrace();
$method = $trace[3]['function'];

$watch = 'Propel Query '.(count($this->queries)+1);
Expand All @@ -91,7 +91,7 @@ public function log($level, $message, array $context = array())
'connection' => $connection->getName(),
'time' => $event->getDuration() / 1000,
'memory' => $event->getMemory(),
'stackTrace' => $stackTrace,
'trace' => new TraceStub($trace),
);
}

Expand All @@ -102,25 +102,4 @@ public function getQueries()
{
return $this->queries;
}

/**
* Returns the current stack trace.
*
* @return array
*/
private function getStackTrace()
{
$e = new \Exception();
$trace = explode("\n", $e->getTraceAsString());
$trace = array_reverse($trace);
array_shift($trace); // remove {main}
array_pop($trace); // remove call to this method

foreach ($trace as $i => &$value) {
$value = $i + 1 . ')' . substr($value, strpos($value, ' '));
$value = preg_replace('/\((\d+)\)/', ':$1', $value, 1);
}

return $trace;
}
}