Log the execution time

This commit is contained in:
Michael 2022-05-17 20:47:23 +00:00
parent 6eb70bea16
commit 4016a576d5
27 changed files with 67 additions and 6 deletions

View File

@ -39,10 +39,12 @@ use Friendica\Util\Strings;
function fbrowser_content(App $a) function fbrowser_content(App $a)
{ {
if (!local_user()) { if (!local_user()) {
DI::page()->logRuntime();
exit(); exit();
} }
if (DI::args()->getArgc() == 1) { if (DI::args()->getArgc() == 1) {
DI::page()->logRuntime();
exit(); exit();
} }

View File

@ -158,6 +158,7 @@ function photos_post(App $a)
if (!$can_post) { if (!$can_post) {
notice(DI::l10n()->t('Permission denied.')); notice(DI::l10n()->t('Permission denied.'));
DI::page()->logRuntime();
exit(); exit();
} }
@ -166,6 +167,7 @@ function photos_post(App $a)
if (!$owner_record) { if (!$owner_record) {
notice(DI::l10n()->t('Contact information unavailable')); notice(DI::l10n()->t('Contact information unavailable'));
DI::logger()->info('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid); DI::logger()->info('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
DI::page()->logRuntime();
exit(); exit();
} }

View File

@ -38,6 +38,7 @@ function hub_return($valid, $body)
} else { } else {
throw new \Friendica\Network\HTTPException\NotFoundException(); throw new \Friendica\Network\HTTPException\NotFoundException();
} }
DI::page()->logRuntime();
exit(); exit();
} }

View File

@ -142,5 +142,6 @@ function pubsubhubbub_init(App $a) {
throw new \Friendica\Network\HTTPException\AcceptedException(); throw new \Friendica\Network\HTTPException\AcceptedException();
} }
DI::page()->logRuntime();
exit(); exit();
} }

View File

@ -30,6 +30,7 @@ function share_init(App $a) {
$post_id = ((DI::args()->getArgc() > 1) ? intval(DI::args()->getArgv()[1]) : 0); $post_id = ((DI::args()->getArgc() > 1) ? intval(DI::args()->getArgv()[1]) : 0);
if (!$post_id || !local_user()) { if (!$post_id || !local_user()) {
DI::page()->logRuntime();
exit(); exit();
} }
@ -38,6 +39,7 @@ function share_init(App $a) {
$item = Post::selectFirst($fields, ['id' => $post_id]); $item = Post::selectFirst($fields, ['id' => $post_id]);
if (!DBA::isResult($item) || $item['private'] == Item::PRIVATE) { if (!DBA::isResult($item) || $item['private'] == Item::PRIVATE) {
DI::page()->logRuntime();
exit(); exit();
} }
@ -56,5 +58,6 @@ function share_init(App $a) {
} }
echo $o; echo $o;
DI::page()->logRuntime();
exit(); exit();
} }

View File

@ -167,6 +167,6 @@ EOT;
$post = Post::selectFirst(['uri-id', 'uid'], ['id' => $post_id]); $post = Post::selectFirst(['uri-id', 'uid'], ['id' => $post_id]);
Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post['uri-id'], $post['uid']); Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post['uri-id'], $post['uid']);
DI::page()->logRuntime();
exit(); exit();
} }

View File

@ -67,6 +67,7 @@ function wall_attach_post(App $a) {
System::jsonExit(['error' => DI::l10n()->t('Permission denied.')]); System::jsonExit(['error' => DI::l10n()->t('Permission denied.')]);
} }
notice(DI::l10n()->t('Permission denied.') . EOL ); notice(DI::l10n()->t('Permission denied.') . EOL );
DI::page()->logRuntime();
exit(); exit();
} }
@ -74,6 +75,7 @@ function wall_attach_post(App $a) {
if ($r_json) { if ($r_json) {
System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]); System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
} }
DI::page()->logRuntime();
exit(); exit();
} }
@ -97,6 +99,7 @@ function wall_attach_post(App $a) {
} else { } else {
notice($msg); notice($msg);
} }
DI::page()->logRuntime();
exit(); exit();
} }
@ -108,6 +111,7 @@ function wall_attach_post(App $a) {
} else { } else {
echo $msg . EOL; echo $msg . EOL;
} }
DI::page()->logRuntime();
exit(); exit();
} }
@ -122,6 +126,7 @@ function wall_attach_post(App $a) {
} else { } else {
echo $msg . EOL; echo $msg . EOL;
} }
DI::page()->logRuntime();
exit(); exit();
} }
@ -132,7 +137,7 @@ function wall_attach_post(App $a) {
$lf = "\n"; $lf = "\n";
echo $lf . $lf . '[attachment]' . $newid . '[/attachment]' . $lf; echo $lf . $lf . '[attachment]' . $newid . '[/attachment]' . $lf;
DI::page()->logRuntime();
exit(); exit();
// NOTREACHED // NOTREACHED
} }

View File

@ -89,6 +89,7 @@ function wall_upload_post(App $a, $desktopmode = true)
System::jsonExit(['error' => DI::l10n()->t('Permission denied.')]); System::jsonExit(['error' => DI::l10n()->t('Permission denied.')]);
} }
notice(DI::l10n()->t('Permission denied.')); notice(DI::l10n()->t('Permission denied.'));
DI::page()->logRuntime();
exit(); exit();
} }
@ -96,6 +97,7 @@ function wall_upload_post(App $a, $desktopmode = true)
if ($r_json) { if ($r_json) {
System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]); System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
} }
DI::page()->logRuntime();
exit(); exit();
} }
@ -148,6 +150,7 @@ function wall_upload_post(App $a, $desktopmode = true)
System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]); System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
} }
notice(DI::l10n()->t('Invalid request.')); notice(DI::l10n()->t('Invalid request.'));
DI::page()->logRuntime();
exit(); exit();
} }
@ -167,6 +170,7 @@ function wall_upload_post(App $a, $desktopmode = true)
} else { } else {
echo $msg. EOL; echo $msg. EOL;
} }
DI::page()->logRuntime();
exit(); exit();
} }
@ -205,6 +209,7 @@ function wall_upload_post(App $a, $desktopmode = true)
} else { } else {
echo $msg. EOL; echo $msg. EOL;
} }
DI::page()->logRuntime();
exit(); exit();
} }
} }
@ -229,6 +234,7 @@ function wall_upload_post(App $a, $desktopmode = true)
} else { } else {
echo $msg. EOL; echo $msg. EOL;
} }
DI::page()->logRuntime();
exit(); exit();
} }
@ -281,6 +287,7 @@ function wall_upload_post(App $a, $desktopmode = true)
} }
echo "\n\n" . '[url=' . DI::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $resource_id . '][img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$Image->getExt()."[/img][/url]\n\n"; echo "\n\n" . '[url=' . DI::baseUrl() . '/photos/' . $page_owner_nick . '/image/' . $resource_id . '][img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$Image->getExt()."[/img][/url]\n\n";
DI::page()->logRuntime();
exit(); exit();
// NOTREACHED // NOTREACHED
} }

View File

@ -576,6 +576,7 @@ class App
$this->profiler->set(microtime(true), 'classinit'); $this->profiler->set(microtime(true), 'classinit');
$moduleName = $this->args->getModuleName(); $moduleName = $this->args->getModuleName();
$page->setLogging($moduleName, $this->args->getMethod());
try { try {
// Missing DB connection: ERROR // Missing DB connection: ERROR
@ -712,6 +713,7 @@ class App
$this->profiler->set(microtime(true) - $timestamp, 'content'); $this->profiler->set(microtime(true) - $timestamp, 'content');
if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) { if ($response->getHeaderLine(ICanCreateResponses::X_HEADER) === ICanCreateResponses::TYPE_HTML) {
$page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig); $page->run($this, $this->baseURL, $this->args, $this->mode, $response, $this->l10n, $this->profiler, $this->config, $pconfig);
$page->logRuntime();
} else { } else {
$page->exit($response); $page->exit($response);
} }

View File

@ -30,6 +30,7 @@ use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Core\Theme; use Friendica\Core\Theme;
@ -78,14 +79,31 @@ class Page implements ArrayAccess
*/ */
private $basePath; private $basePath;
private $timestamp = 0;
private $moduleName = '';
private $method = '';
/** /**
* @param string $basepath The Page basepath * @param string $basepath The Page basepath
*/ */
public function __construct(string $basepath) public function __construct(string $basepath)
{ {
$this->timestamp = microtime(true);
$this->basePath = $basepath; $this->basePath = $basepath;
} }
public function setLogging(string $moduleName, string $method)
{
$this->moduleName = $moduleName;
$this->method = $method;
}
public function logRuntime()
{
$runtime = number_format(microtime(true) - $this->timestamp, 3);
Logger::debug('Runtime', ['method' => $this->method, 'module' => $this->moduleName, 'runtime' => $runtime]);
}
/** /**
* Whether a offset exists * Whether a offset exists
* *
@ -401,6 +419,7 @@ class Page implements ArrayAccess
} }
echo $response->getBody(); echo $response->getBody();
$this->logRuntime();
} }
/** /**
@ -421,6 +440,9 @@ class Page implements ArrayAccess
{ {
$moduleName = $args->getModuleName(); $moduleName = $args->getModuleName();
$this->moduleName = $moduleName;
$this->method = $args->getMethod();
/* Create the page content. /* Create the page content.
* Calls all hooks which are including content operations * Calls all hooks which are including content operations
* *

View File

@ -448,7 +448,7 @@ class System
case 307: case 307:
throw new TemporaryRedirectException(); throw new TemporaryRedirectException();
} }
DI::page()->logRuntime();
exit(); exit();
} }
@ -522,6 +522,7 @@ class System
echo str_replace("\t", " ", $o); echo str_replace("\t", " ", $o);
echo "</section>"; echo "</section>";
echo "</body></html>\r\n"; echo "</body></html>\r\n";
DI::page()->logRuntime();
exit(); exit();
} }

View File

@ -30,6 +30,7 @@ class PhpInfo extends BaseAdmin
self::checkAdminAccess(); self::checkAdminAccess();
phpinfo(); phpinfo();
DI::page()->logRuntime();
exit(); exit();
} }
} }

View File

@ -72,6 +72,7 @@ class Attach extends BaseModule
} }
echo $data; echo $data;
DI::page()->logRuntime();
exit(); exit();
// NOTREACHED // NOTREACHED
} }

View File

@ -107,6 +107,7 @@ class Hovercard extends BaseModule
]); ]);
echo $o; echo $o;
DI::page()->logRuntime();
exit(); exit();
} }
} }

View File

@ -48,6 +48,7 @@ class ItemBody extends BaseModule
if (!empty($item)) { if (!empty($item)) {
if (DI::mode()->isAjax()) { if (DI::mode()->isAjax()) {
echo str_replace("\n", '<br />', $item['body']); echo str_replace("\n", '<br />', $item['body']);
DI::page()->logRuntime();
exit(); exit();
} else { } else {
return str_replace("\n", '<br />', $item['body']); return str_replace("\n", '<br />', $item['body']);

View File

@ -360,6 +360,7 @@ class Group extends BaseModule
if ($change) { if ($change) {
$tpl = Renderer::getMarkupTemplate('groupeditor.tpl'); $tpl = Renderer::getMarkupTemplate('groupeditor.tpl');
echo Renderer::replaceMacros($tpl, $context); echo Renderer::replaceMacros($tpl, $context);
DI::page()->logRuntime();
exit(); exit();
} }

View File

@ -47,6 +47,7 @@ class PageNotFound extends BaseModule
$queryString = $this->server['QUERY_STRING']; $queryString = $this->server['QUERY_STRING'];
// Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit. // Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit.
if (!empty($queryString) && preg_match('/{[0-9]}/', $queryString) !== 0) { if (!empty($queryString) && preg_match('/{[0-9]}/', $queryString) !== 0) {
DI::page()->logRuntime();
exit(); exit();
} }

View File

@ -43,6 +43,7 @@ class Oembed extends BaseModule
if (DI::args()->getArgv()[1] == 'b2h') { if (DI::args()->getArgv()[1] == 'b2h') {
$url = ["", trim(hex2bin($_REQUEST['url']))]; $url = ["", trim(hex2bin($_REQUEST['url']))];
echo Content\OEmbed::replaceCallback($url); echo Content\OEmbed::replaceCallback($url);
DI::page()->logRuntime();
exit(); exit();
} }
@ -50,6 +51,7 @@ class Oembed extends BaseModule
if (DI::args()->getArgv()[1] == 'h2b') { if (DI::args()->getArgv()[1] == 'h2b') {
$text = trim(hex2bin($_REQUEST['text'])); $text = trim(hex2bin($_REQUEST['text']));
echo Content\OEmbed::HTML2BBCode($text); echo Content\OEmbed::HTML2BBCode($text);
DI::page()->logRuntime();
exit(); exit();
} }
@ -68,6 +70,7 @@ class Oembed extends BaseModule
echo $j->html; echo $j->html;
echo '</body></html>'; echo '</body></html>';
} }
DI::page()->logRuntime();
exit(); exit();
} }
} }

View File

@ -164,7 +164,7 @@ class PermissionTooltip extends \Friendica\BaseModule
} else { } else {
echo $o . $receivers; echo $o . $receivers;
} }
DI::page()->logRuntime();
exit(); exit();
} }

View File

@ -224,6 +224,7 @@ class Photo extends BaseModule
'output' => number_format($output, 3), 'rest' => number_format($rest, 3)]); 'output' => number_format($output, 3), 'rest' => number_format($rest, 3)]);
} }
DI::page()->logRuntime();
exit(); exit();
} }

View File

@ -202,6 +202,7 @@ class Proxy extends BaseModule
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (31536000)) . ' GMT'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (31536000)) . ' GMT');
header('Cache-Control: max-age=31536000'); header('Cache-Control: max-age=31536000');
echo $img->asString(); echo $img->asString();
DI::page()->logRuntime();
exit(); exit();
} }
} }

View File

@ -44,6 +44,7 @@ class RobotsTxt extends BaseModule
foreach ($allDisalloweds as $disallowed) { foreach ($allDisalloweds as $disallowed) {
echo 'Disallow: ' . $disallowed . PHP_EOL; echo 'Disallow: ' . $disallowed . PHP_EOL;
} }
DI::page()->logRuntime();
exit(); exit();
} }
} }

View File

@ -112,7 +112,7 @@ class UserExport extends BaseSettings
self::exportContactsAsCSV(local_user()); self::exportContactsAsCSV(local_user());
break; break;
} }
DI::page()->logRuntime();
exit(); exit();
} }
} }

View File

@ -45,7 +45,7 @@ class Theme extends BaseModule
if (file_exists("view/theme/$theme/style.php")) { if (file_exists("view/theme/$theme/style.php")) {
require_once "view/theme/$theme/style.php"; require_once "view/theme/$theme/style.php";
} }
DI::page()->logRuntime();
exit(); exit();
} }
} }

View File

@ -48,6 +48,7 @@ class ThemeDetails extends BaseModule
'credits' => $credits, 'credits' => $credits,
]); ]);
} }
DI::page()->logRuntime();
exit(); exit();
} }
} }

View File

@ -31,6 +31,7 @@ class Network extends NetworkModule
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
if (!isset($_GET['p']) || !isset($_GET['item'])) { if (!isset($_GET['p']) || !isset($_GET['item'])) {
DI::page()->logRuntime();
exit(); exit();
} }

View File

@ -69,6 +69,7 @@ class JsonLD
if ($recursion > 5) { if ($recursion > 5) {
Logger::error('jsonld bomb detected at: ' . $url); Logger::error('jsonld bomb detected at: ' . $url);
DI::page()->logRuntime();
exit(); exit();
} }