diff --git a/include/api.php b/include/api.php index 12f5dcb8ab..d2b41f988d 100644 --- a/include/api.php +++ b/include/api.php @@ -328,7 +328,7 @@ function api_call(App $a) Logger::info(API_LOG_PREFIX . 'username {username}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username'], 'duration' => round($duration, 2)]); - $a->getProfiler()->saveLog(DI::logger(), API_LOG_PREFIX . 'performance'); + DI::profiler()->saveLog(DI::logger(), API_LOG_PREFIX . 'performance'); if (false === $return) { /* diff --git a/src/App.php b/src/App.php index ac0f45f9b5..6c88c6c947 100644 --- a/src/App.php +++ b/src/App.php @@ -155,16 +155,6 @@ class App return $this->config->getCache()->get('system', 'basepath'); } - /** - * The profiler of this app - * - * @return Profiler - */ - public function getProfiler() - { - return $this->profiler; - } - /** * Returns the Mode of the Application * diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 2619dc92cc..f7ca6efd97 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1104,7 +1104,7 @@ class BBCode @curl_exec($ch); $curl_info = @curl_getinfo($ch); - $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "network", System::callstack()); if (substr($curl_info['content_type'], 0, 6) == 'image/') { $text = "[url=" . $match[1] . ']' . $match[1] . "[/url]"; @@ -1178,7 +1178,7 @@ class BBCode @curl_exec($ch); $curl_info = @curl_getinfo($ch); - $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "network", System::callstack()); // if its a link to a picture then embed this picture if (substr($curl_info['content_type'], 0, 6) == 'image/') { @@ -2061,7 +2061,7 @@ class BBCode // Now convert HTML to Markdown $text = HTML::toMarkdown($text); - $a->getProfiler()->saveTimestamp($stamp1, "parser", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack()); // Libertree has a problem with escaped hashtags. $text = str_replace(['\#'], ['#'], $text); diff --git a/src/Content/Text/Markdown.php b/src/Content/Text/Markdown.php index 004f01beed..8d363675fc 100644 --- a/src/Content/Text/Markdown.php +++ b/src/Content/Text/Markdown.php @@ -43,7 +43,7 @@ class Markdown $html = $MarkdownParser->transform($text); - DI::app()->getProfiler()->saveTimestamp($stamp1, "parser", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack()); return $html; } diff --git a/src/Core/Addon.php b/src/Core/Addon.php index 59e1ec7b96..252acd31f0 100644 --- a/src/Core/Addon.php +++ b/src/Core/Addon.php @@ -286,7 +286,7 @@ class Addon $stamp1 = microtime(true); $f = file_get_contents("addon/$addon/$addon.php"); - $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "file", System::callstack()); $r = preg_match("|/\*.*\*/|msU", $f, $m); diff --git a/src/Core/Renderer.php b/src/Core/Renderer.php index c687a67283..8366d0db80 100644 --- a/src/Core/Renderer.php +++ b/src/Core/Renderer.php @@ -75,7 +75,7 @@ class Renderer exit(); } - $a->getProfiler()->saveTimestamp($stamp1, "rendering", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "rendering", System::callstack()); return $output; } @@ -102,7 +102,7 @@ class Renderer exit(); } - $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "file", System::callstack()); return $template; } diff --git a/src/Core/Theme.php b/src/Core/Theme.php index dea3e20e64..a4dfe2f9fa 100644 --- a/src/Core/Theme.php +++ b/src/Core/Theme.php @@ -73,10 +73,9 @@ class Theme return $info; } - $a = \get_app(); $stamp1 = microtime(true); $theme_file = file_get_contents("view/theme/$theme/theme.php"); - $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "file", System::callstack()); $result = preg_match("|/\*.*\*/|msU", $theme_file, $matches); diff --git a/src/Core/Worker.php b/src/Core/Worker.php index d4a90dd196..fc30ce12d5 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -386,7 +386,7 @@ class Worker // We use the callstack here to analyze the performance of executed worker entries. // For this reason the variables have to be initialized. - $a->getProfiler()->reset(); + DI::profiler()->reset(); $a->queue = $queue; @@ -443,7 +443,7 @@ class Worker Logger::info('Process done.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' => round($duration, 3)]); - $a->getProfiler()->saveLog(DI::logger(), "ID " . $queue["id"] . ": " . $funcname); + DI::profiler()->saveLog(DI::logger(), "ID " . $queue["id"] . ": " . $funcname); $cooldown = Config::get("system", "worker_cooldown", 0); diff --git a/src/DI.php b/src/DI.php index 6b86bddb56..89b638d226 100644 --- a/src/DI.php +++ b/src/DI.php @@ -17,6 +17,7 @@ use Friendica\Content; use Friendica\Util\DateTimeFormat; use Friendica\Util\FileSystem; use Friendica\Util\Logger\WorkerLogger; +use Friendica\Util\Profiler; use Psr\Log\LoggerInterface; /** @@ -39,6 +40,7 @@ use Psr\Log\LoggerInterface; * @method static LoggerInterface logger() * @method static LoggerInterface devLogger() * @method static LoggerInterface workerLogger() + * @method static Profiler profiler() * @method static ISession session() * @method static App\Authentication auth() * @method static App\Arguments args() @@ -79,6 +81,7 @@ class DI 'session' => ISession::class, 'dba' => Database::class, 'fs' => FileSystem::class, + 'profiler' => Profiler::class, ]; /** @var Dice */ diff --git a/src/Object/Image.php b/src/Object/Image.php index 972b48359f..e25afd5e90 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -8,6 +8,7 @@ namespace Friendica\Object; use Exception; use Friendica\Core\Config; use Friendica\Core\System; +use Friendica\DI; use Friendica\Util\Images; use Imagick; use ImagickPixel; @@ -607,11 +608,9 @@ class Image $string = $this->asString(); - $a = \get_app(); - $stamp1 = microtime(true); file_put_contents($path, $string); - $a->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "file", System::callstack()); } /** diff --git a/src/Util/Images.php b/src/Util/Images.php index 7f31dd4383..e19304bba1 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -165,7 +165,7 @@ class Images $stamp1 = microtime(true); file_put_contents($tempfile, $img_str); - DI::app()->getProfiler()->saveTimestamp($stamp1, "file", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "file", System::callstack()); $data = getimagesize($tempfile); unlink($tempfile); diff --git a/src/Util/Network.php b/src/Util/Network.php index f222dc22df..b19c8af504 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -10,6 +10,7 @@ use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\System; +use Friendica\DI; use Friendica\Network\CurlResult; class Network @@ -233,7 +234,7 @@ class Network @curl_close($ch); - $a->getProfiler()->saveTimestamp($stamp1, 'network', System::callstack()); + DI::profiler()->saveTimestamp($stamp1, 'network', System::callstack()); return $curlResponse; } @@ -325,7 +326,7 @@ class Network curl_close($ch); - $a->getProfiler()->saveTimestamp($stamp1, 'network', System::callstack()); + DI::profiler()->saveTimestamp($stamp1, 'network', System::callstack()); // Very old versions of Lighttpd don't like the "Expect" header, so we remove it when needed if ($curlResponse->getReturnCode() == 417) { @@ -654,7 +655,7 @@ class Network $http_code = $curl_info['http_code']; curl_close($ch); - $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "network", System::callstack()); if ($http_code == 0) { return $url; @@ -696,7 +697,7 @@ class Network $body = curl_exec($ch); curl_close($ch); - $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack()); + DI::profiler()->saveTimestamp($stamp1, "network", System::callstack()); if (trim($body) == "") { return $url;