Browse Source

Refactor dynamic App::getProfiler() to static DI::profiler()

pull/8019/head
nupplaPhil 2 years ago
parent
commit
181529f3df
No known key found for this signature in database GPG Key ID: D8365C3D36B77D90
  1. 2
      include/api.php
  2. 10
      src/App.php
  3. 6
      src/Content/Text/BBCode.php
  4. 2
      src/Content/Text/Markdown.php
  5. 2
      src/Core/Addon.php
  6. 4
      src/Core/Renderer.php
  7. 3
      src/Core/Theme.php
  8. 4
      src/Core/Worker.php
  9. 3
      src/DI.php
  10. 5
      src/Object/Image.php
  11. 2
      src/Util/Images.php
  12. 9
      src/Util/Network.php

2
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) {
/*

10
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
*

6
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);

2
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;
}

2
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);

4
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;
}

3
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);

4
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);

3
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 */

5
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());
}
/**

2
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);

9
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;

Loading…
Cancel
Save