Skip to content

Commit

Permalink
perf(capabilities): Log capabilities providers that are slow
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jun 20, 2024
1 parent c251e8f commit d1aeeda
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/private/CapabilitiesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ public function getCapabilities(bool $public = false, bool $initialState = false
// that we would otherwise inject to every page load
continue;
}
$startTime = microtime(true);
$capabilities = array_replace_recursive($capabilities, $c->getCapabilities());
$endTime = microtime(true);
$duration = $endTime - $startTime;
if ($duration > 0.3) {
$this->logger->warning('Capabilities of {className} took {duration} seconds to generate.', [
'className' => get_class($c),
'duration' => round($duration, 2),
]);
}
}
} else {
throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface');
Expand Down

0 comments on commit d1aeeda

Please sign in to comment.