Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions lib/private/CapabilitiesManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCP\Capabilities\ICapability;
use OCP\Capabilities\IInitialStateExcludedCapability;
use OCP\Capabilities\IPublicCapability;
use OCP\IConfig;
use OCP\ILogger;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -56,26 +57,32 @@ 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);
$timeSpent = $endTime - $startTime;
if ($timeSpent > self::ACCEPTABLE_LOADING_TIME) {
$logLevel = match (true) {
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 16 => ILogger::FATAL,
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 8 => ILogger::ERROR,
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 4 => ILogger::WARN,
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 2 => ILogger::INFO,
default => ILogger::DEBUG,
};
$this->logger->log(
$logLevel,
'Capabilities of {className} took {duration} seconds to generate.',
[
'className' => get_class($c),
'duration' => round($timeSpent, 2),
]
);

// Only check execution time if debug mode is enabled
$debugMode = \OCP\Server::get(IConfig::class)->getSystemValueBool('debug', false);
if ($debugMode) {
$timeSpent = $endTime - $startTime;
if ($timeSpent > self::ACCEPTABLE_LOADING_TIME) {
$logLevel = match (true) {
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 16 => ILogger::FATAL,
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 8 => ILogger::ERROR,
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 4 => ILogger::WARN,
$timeSpent > self::ACCEPTABLE_LOADING_TIME * 2 => ILogger::INFO,
default => ILogger::DEBUG,
};
$this->logger->log(
$logLevel,
'Capabilities of {className} took {duration} seconds to generate.',
[
'className' => get_class($c),
'duration' => round($timeSpent, 2),
]
);
}
}
}
} else {
Expand Down
Loading