Improved performance of LoggerDataCollector

This commit is contained in:
Javier Eguiluz 2019-01-03 15:55:15 +01:00 committed by Fabien Potencier
parent 3860d685f4
commit 3b8d6d19ec

View File

@ -66,7 +66,9 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
if (null !== $this->logger) { if (null !== $this->logger) {
$containerDeprecationLogs = $this->getContainerDeprecationLogs(); $containerDeprecationLogs = $this->getContainerDeprecationLogs();
$this->data = $this->computeErrorsCount($containerDeprecationLogs); $this->data = $this->computeErrorsCount($containerDeprecationLogs);
$this->data['compiler_logs'] = $this->getContainerCompilerLogs(); // get compiler logs later (only when they are needed) to improve performance
$this->data['compiler_logs'] = array();
$this->data['compiler_logs_filepath'] = $this->containerPathPrefix.'Compiler.log';
$this->data['logs'] = $this->sanitizeLogs(array_merge($this->logger->getLogs($this->currentRequest), $containerDeprecationLogs)); $this->data['logs'] = $this->sanitizeLogs(array_merge($this->logger->getLogs($this->currentRequest), $containerDeprecationLogs));
$this->data = $this->cloneVar($this->data); $this->data = $this->cloneVar($this->data);
} }
@ -110,7 +112,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
public function getCompilerLogs() public function getCompilerLogs()
{ {
return isset($this->data['compiler_logs']) ? $this->data['compiler_logs'] : array(); return $this->cloneVar($this->getContainerCompilerLogs($this->data['compiler_logs_filepath'] ?? null));
} }
/** /**
@ -143,14 +145,14 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
return $logs; return $logs;
} }
private function getContainerCompilerLogs() private function getContainerCompilerLogs(?string $compilerLogsFilepath = null): array
{ {
if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Compiler.log')) { if (!file_exists($compilerLogsFilepath)) {
return array(); return array();
} }
$logs = array(); $logs = array();
foreach (file($file, FILE_IGNORE_NEW_LINES) as $log) { foreach (file($compilerLogsFilepath, FILE_IGNORE_NEW_LINES) as $log) {
$log = explode(': ', $log, 2); $log = explode(': ', $log, 2);
if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) { if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) {
$log = array('Unknown Compiler Pass', implode(': ', $log)); $log = array('Unknown Compiler Pass', implode(': ', $log));