|
10 | 10 | namespace OC\Session; |
11 | 11 |
|
12 | 12 | use OC\Authentication\Token\IProvider; |
| 13 | +use OC\Diagnostics\TLogSlowOperation; |
13 | 14 | use OCP\Authentication\Exceptions\InvalidTokenException; |
14 | | -use OCP\ILogger; |
15 | 15 | use OCP\Session\Exceptions\SessionNotAvailableException; |
16 | 16 | use Psr\Log\LoggerInterface; |
17 | 17 | use function call_user_func_array; |
18 | | -use function microtime; |
19 | 18 |
|
20 | 19 | /** |
21 | 20 | * Class Internal |
|
25 | 24 | * @package OC\Session |
26 | 25 | */ |
27 | 26 | class Internal extends Session { |
| 27 | + |
| 28 | + use TLogSlowOperation; |
| 29 | + |
28 | 30 | /** |
29 | 31 | * @param string $name |
30 | 32 | * @throws \Exception |
@@ -191,31 +193,17 @@ public function trapError(int $errorNumber, string $errorString) { |
191 | 193 | */ |
192 | 194 | private function invoke(string $functionName, array $parameters = [], bool $silence = false) { |
193 | 195 | try { |
194 | | - $timeBefore = microtime(true); |
195 | | - if ($silence) { |
196 | | - $result = @call_user_func_array($functionName, $parameters); |
197 | | - } else { |
198 | | - $result = call_user_func_array($functionName, $parameters); |
199 | | - } |
200 | | - $timeAfter = microtime(true); |
201 | | - $timeSpent = $timeAfter - $timeBefore; |
202 | | - if ($timeSpent > 0.1) { |
203 | | - $logLevel = match (true) { |
204 | | - $timeSpent > 25 => ILogger::ERROR, |
205 | | - $timeSpent > 10 => ILogger::WARN, |
206 | | - $timeSpent > 0.5 => ILogger::INFO, |
207 | | - default => ILogger::DEBUG, |
208 | | - }; |
209 | | - $this->logger?->log( |
210 | | - $logLevel, |
211 | | - "Slow session operation $functionName detected", |
212 | | - [ |
213 | | - 'parameters' => $parameters, |
214 | | - 'timeSpent' => $timeSpent, |
215 | | - ], |
216 | | - ); |
217 | | - } |
218 | | - return $result; |
| 196 | + return $this->monitorAndLog( |
| 197 | + $this->logger, |
| 198 | + $functionName, |
| 199 | + function () use ($silence, $functionName, $parameters) { |
| 200 | + if ($silence) { |
| 201 | + return @call_user_func_array($functionName, $parameters); |
| 202 | + } else { |
| 203 | + return call_user_func_array($functionName, $parameters); |
| 204 | + } |
| 205 | + } |
| 206 | + ); |
219 | 207 | } catch (\Error $e) { |
220 | 208 | $this->trapError($e->getCode(), $e->getMessage()); |
221 | 209 | } |
|
0 commit comments