]> git.mxchange.org Git - friendica.git/commitdiff
Log the execution time
authorMichael <heluecht@pirati.ca>
Tue, 17 May 2022 20:47:23 +0000 (20:47 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 17 May 2022 20:47:23 +0000 (20:47 +0000)
27 files changed:
mod/fbrowser.php
mod/photos.php
mod/pubsub.php
mod/pubsubhubbub.php
mod/share.php
mod/tagger.php
mod/wall_attach.php
mod/wall_upload.php
src/App.php
src/App/Page.php
src/Core/System.php
src/Module/Admin/PhpInfo.php
src/Module/Attach.php
src/Module/Contact/Hovercard.php
src/Module/Debug/ItemBody.php
src/Module/Group.php
src/Module/HTTPException/PageNotFound.php
src/Module/Oembed.php
src/Module/PermissionTooltip.php
src/Module/Photo.php
src/Module/Proxy.php
src/Module/RobotsTxt.php
src/Module/Settings/UserExport.php
src/Module/Theme.php
src/Module/ThemeDetails.php
src/Module/Update/Network.php
src/Util/JsonLD.php

index 1646b19dff606206036ae3b561f333347e226150..4e887c7eb0456a99a31452345ff79775d3d01c63 100644 (file)
@@ -39,10 +39,12 @@ use Friendica\Util\Strings;
 function fbrowser_content(App $a)
 {
        if (!local_user()) {
+               DI::page()->logRuntime();
                exit();
        }
 
        if (DI::args()->getArgc() == 1) {
+               DI::page()->logRuntime();
                exit();
        }
 
index ce6d11340e8d114380455209d220b9eae43e73dd..fa8a434c44a14382e0eaebca3344298145abdc6f 100644 (file)
@@ -158,6 +158,7 @@ function photos_post(App $a)
 
        if (!$can_post) {
                notice(DI::l10n()->t('Permission denied.'));
+               DI::page()->logRuntime();
                exit();
        }
 
@@ -166,6 +167,7 @@ function photos_post(App $a)
        if (!$owner_record) {
                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::page()->logRuntime();
                exit();
        }
 
index e07b15583c8eb5c3926e5b9a811d3234e54295f4..630b68f50428403f013eaaf08c95ffef157a9b0a 100644 (file)
@@ -38,6 +38,7 @@ function hub_return($valid, $body)
        } else {
                throw new \Friendica\Network\HTTPException\NotFoundException();
        }
+       DI::page()->logRuntime();
        exit();
 }
 
index 361cb0a597e1cda7bbfbe8a0bab0f06ab0a53bbe..5300f783d4acdc0944d7ca980b0ae1fb95f5c7ec 100644 (file)
@@ -142,5 +142,6 @@ function pubsubhubbub_init(App $a) {
 
                throw new \Friendica\Network\HTTPException\AcceptedException();
        }
+       DI::page()->logRuntime();
        exit();
 }
index b18655aef88f16561c8da97cf6035e76115a2c9f..dde3864bc4ccf9d4b0fc7623527903633b96ef4e 100644 (file)
@@ -30,6 +30,7 @@ function share_init(App $a) {
        $post_id = ((DI::args()->getArgc() > 1) ? intval(DI::args()->getArgv()[1]) : 0);
 
        if (!$post_id || !local_user()) {
+               DI::page()->logRuntime();
                exit();
        }
 
@@ -38,6 +39,7 @@ function share_init(App $a) {
        $item = Post::selectFirst($fields, ['id' => $post_id]);
 
        if (!DBA::isResult($item) || $item['private'] == Item::PRIVATE) {
+               DI::page()->logRuntime();
                exit();
        }
 
@@ -56,5 +58,6 @@ function share_init(App $a) {
        }
 
        echo $o;
+       DI::page()->logRuntime();
        exit();
 }
index 310e3c6140347851bd3f59ff75186a49d8da1593..4c0af4a53227692da3b079554ad3cf4fd837c7bc 100644 (file)
@@ -167,6 +167,6 @@ EOT;
        $post = Post::selectFirst(['uri-id', 'uid'], ['id' => $post_id]);
 
        Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, $post['uri-id'], $post['uid']);
-
+       DI::page()->logRuntime();
        exit();
 }
index 607d0fe7a394c237b5ff8b179191fcd5dcc001bc..6dfa40b09588da9b58132deb82dddaca7966ec76 100644 (file)
@@ -67,6 +67,7 @@ function wall_attach_post(App $a) {
                        System::jsonExit(['error' => DI::l10n()->t('Permission denied.')]);
                }
                notice(DI::l10n()->t('Permission denied.') . EOL );
+               DI::page()->logRuntime();
                exit();
        }
 
@@ -74,6 +75,7 @@ function wall_attach_post(App $a) {
                if ($r_json) {
                        System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
                }
+               DI::page()->logRuntime();
                exit();
        }
 
@@ -97,6 +99,7 @@ function wall_attach_post(App $a) {
                } else {
                        notice($msg);
                }
+               DI::page()->logRuntime();
                exit();
        }
 
@@ -108,6 +111,7 @@ function wall_attach_post(App $a) {
                } else {
                        echo $msg . EOL;
                }
+               DI::page()->logRuntime();
                exit();
        }
 
@@ -122,6 +126,7 @@ function wall_attach_post(App $a) {
                } else {
                        echo $msg . EOL;
                }
+               DI::page()->logRuntime();
                exit();
        }
 
@@ -132,7 +137,7 @@ function wall_attach_post(App $a) {
        $lf = "\n";
 
        echo  $lf . $lf . '[attachment]' . $newid . '[/attachment]' . $lf;
-
+       DI::page()->logRuntime();
        exit();
        // NOTREACHED
 }
index 79f1dcc41f323c8fa2853e84cb4461432cb07ab8..8b8b1df9a43958da032bebc3cb69526c4158b974 100644 (file)
@@ -89,6 +89,7 @@ function wall_upload_post(App $a, $desktopmode = true)
                        System::jsonExit(['error' => DI::l10n()->t('Permission denied.')]);
                }
                notice(DI::l10n()->t('Permission denied.'));
+               DI::page()->logRuntime();
                exit();
        }
 
@@ -96,6 +97,7 @@ function wall_upload_post(App $a, $desktopmode = true)
                if ($r_json) {
                        System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
                }
+               DI::page()->logRuntime();
                exit();
        }
 
@@ -148,6 +150,7 @@ function wall_upload_post(App $a, $desktopmode = true)
                        System::jsonExit(['error' => DI::l10n()->t('Invalid request.')]);
                }
                notice(DI::l10n()->t('Invalid request.'));
+               DI::page()->logRuntime();
                exit();
        }
 
@@ -167,6 +170,7 @@ function wall_upload_post(App $a, $desktopmode = true)
                } else {
                        echo  $msg. EOL;
                }
+               DI::page()->logRuntime();
                exit();
        }
 
@@ -205,6 +209,7 @@ function wall_upload_post(App $a, $desktopmode = true)
                        } else {
                                echo  $msg. EOL;
                        }
+                       DI::page()->logRuntime();
                        exit();
                }
        }
@@ -229,6 +234,7 @@ function wall_upload_post(App $a, $desktopmode = true)
                } else {
                        echo  $msg. EOL;
                }
+               DI::page()->logRuntime();
                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";
+       DI::page()->logRuntime();
        exit();
        // NOTREACHED
 }
index f7c929820d308640f7b3156d684b58d997417d70..bf5c309ed39910dacf45654aba2163d0a18efce3 100644 (file)
@@ -576,6 +576,7 @@ class App
                $this->profiler->set(microtime(true), 'classinit');
 
                $moduleName = $this->args->getModuleName();
+               $page->setLogging($moduleName, $this->args->getMethod());
 
                try {
                        // Missing DB connection: ERROR
@@ -712,6 +713,7 @@ class App
                        $this->profiler->set(microtime(true) - $timestamp, 'content');
                        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->logRuntime();
                        } else {
                                $page->exit($response);
                        }
index 14f0101ef07eb6f49d0207ec7620274c917a62c7..8986d4aa91c11c6c7668998c4d88e03702966ddb 100644 (file)
@@ -30,6 +30,7 @@ use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
 use Friendica\Core\Hook;
 use Friendica\Core\L10n;
+use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
 use Friendica\Core\Theme;
@@ -78,14 +79,31 @@ class Page implements ArrayAccess
         */
        private $basePath;
 
+       private $timestamp  = 0;
+       private $moduleName = '';
+       private $method     = '';
+
        /**
         * @param string $basepath The Page basepath
         */
        public function __construct(string $basepath)
        {
+               $this->timestamp = microtime(true);
                $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
         *
@@ -401,6 +419,7 @@ class Page implements ArrayAccess
                }
 
                echo $response->getBody();
+               $this->logRuntime();
        }
 
        /**
@@ -421,6 +440,9 @@ class Page implements ArrayAccess
        {
                $moduleName = $args->getModuleName();
 
+               $this->moduleName = $moduleName;
+               $this->method     = $args->getMethod();
+
                /* Create the page content.
                 * Calls all hooks which are including content operations
                 *
index 66b6b25a501e16245019c8a8f0bde0885dac56fe..7b0a887cdff60ccc837c6e27deb1adc86821b34b 100644 (file)
@@ -448,7 +448,7 @@ class System
                        case 307:
                                throw new TemporaryRedirectException();
                }
-
+               DI::page()->logRuntime();
                exit();
        }
 
@@ -522,6 +522,7 @@ class System
                echo str_replace("\t", "       ", $o);
                echo "</section>";
                echo "</body></html>\r\n";
+               DI::page()->logRuntime();
                exit();
        }
 
index 0177424f3d49f7153821f27aa727638ac5430fba..732753b5938fbc4fe87feb0e7fc6debd0904c826 100644 (file)
@@ -30,6 +30,7 @@ class PhpInfo extends BaseAdmin
                self::checkAdminAccess();
 
                phpinfo();
+               DI::page()->logRuntime();
                exit();
        }
 }
index 60d1015b0aeb68295b05c2f9830973af958157bd..fc7ba74d5948ba1582ea8474434a5a94cf43c3af 100644 (file)
@@ -72,6 +72,7 @@ class Attach extends BaseModule
                }
 
                echo $data;
+               DI::page()->logRuntime();
                exit();
                // NOTREACHED
        }
index cd03e2533a158d229863a7a8ca8c76fb6cd17f1d..2bf6f63ed271eade063ec38cf2d4cb5c86d9f804 100644 (file)
@@ -107,6 +107,7 @@ class Hovercard extends BaseModule
                ]);
 
                echo $o;
+               DI::page()->logRuntime();
                exit();
        }
 }
index 55abc894ed736d263bb0399ea41fb58ec98e635b..e066e7656a028c0fd00b035e1d2d7283bc2a961c 100644 (file)
@@ -48,6 +48,7 @@ class ItemBody extends BaseModule
                if (!empty($item)) {
                        if (DI::mode()->isAjax()) {
                                echo str_replace("\n", '<br />', $item['body']);
+                               DI::page()->logRuntime();
                                exit();
                        } else {
                                return str_replace("\n", '<br />', $item['body']);
index 3cd8166f1fadc2a37275b27b39787c29fc7ef917..4825debd02942ca58504895a123885ab2113fd66 100644 (file)
@@ -360,6 +360,7 @@ class Group extends BaseModule
                if ($change) {
                        $tpl = Renderer::getMarkupTemplate('groupeditor.tpl');
                        echo Renderer::replaceMacros($tpl, $context);
+                       DI::page()->logRuntime();
                        exit();
                }
 
index a73757d828975d7c00ddf69a5cb7dd29d5f16973..ba34df8544db7780cb2eca9688fcac0f170a4b82 100644 (file)
@@ -47,6 +47,7 @@ class PageNotFound extends BaseModule
                $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.
                if (!empty($queryString) && preg_match('/{[0-9]}/', $queryString) !== 0) {
+                       DI::page()->logRuntime();
                        exit();
                }
 
index 81c858cba3023f959a786e1488caa55fa61cb283..49b479204299b59eed3993f66e1752aff1670bd6 100644 (file)
@@ -43,6 +43,7 @@ class Oembed extends BaseModule
                if (DI::args()->getArgv()[1] == 'b2h') {
                        $url = ["", trim(hex2bin($_REQUEST['url']))];
                        echo Content\OEmbed::replaceCallback($url);
+                       DI::page()->logRuntime();
                        exit();
                }
 
@@ -50,6 +51,7 @@ class Oembed extends BaseModule
                if (DI::args()->getArgv()[1] == 'h2b') {
                        $text = trim(hex2bin($_REQUEST['text']));
                        echo Content\OEmbed::HTML2BBCode($text);
+                       DI::page()->logRuntime();
                        exit();
                }
 
@@ -68,6 +70,7 @@ class Oembed extends BaseModule
                        echo $j->html;
                        echo '</body></html>';
                }
+               DI::page()->logRuntime();
                exit();
        }
 }
index ff0bae1bc44f43fa0df2dd1c777c226e55dff6ae..edc839a38e052da3e637fa7fe858b4a114f63840 100644 (file)
@@ -164,7 +164,7 @@ class PermissionTooltip extends \Friendica\BaseModule
                } else {
                        echo $o . $receivers;
                }
-
+               DI::page()->logRuntime();
                exit();
        }
 
index 9e56301b44196ead4d03889d2fbf7742f77df27b..d050188aacceac3a49008aed6f51056d5c2e0bb6 100644 (file)
@@ -224,6 +224,7 @@ class Photo extends BaseModule
                                'output' => number_format($output, 3), 'rest' => number_format($rest, 3)]);
                }
 
+               DI::page()->logRuntime();
                exit();
        }
 
index 3ef3117d691bf465efd4faf1564203bf3f48cdf4..0af49762e9d572d440ab847ff7cc69b6f417c5f0 100644 (file)
@@ -202,6 +202,7 @@ class Proxy extends BaseModule
                header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (31536000)) . ' GMT');
                header('Cache-Control: max-age=31536000');
                echo $img->asString();
+               DI::page()->logRuntime();
                exit();
        }
 }
index 1fcf1269edf72de6acd90c982a1a957fb6c4462d..e4b1af7abe80110bdd9c9f0a8f878d40ba44ef49 100644 (file)
@@ -44,6 +44,7 @@ class RobotsTxt extends BaseModule
                foreach ($allDisalloweds as $disallowed) {
                        echo 'Disallow: ' . $disallowed . PHP_EOL;
                }
+               DI::page()->logRuntime();
                exit();
        }
 }
index 1d47df4fd3d6b3b79a6e02febd4add097cf0d3e2..6af321a0b7d3dee49512fd20066470c29aba1e6b 100644 (file)
@@ -112,7 +112,7 @@ class UserExport extends BaseSettings
                                        self::exportContactsAsCSV(local_user());
                                        break;
                        }
-
+                       DI::page()->logRuntime();
                        exit();
                }
        }
index 66c9d06f076bad857b4a3279bb16e708cd961478..8d14d82dadbaf3862f64f5abf49e44b971034cbd 100644 (file)
@@ -45,7 +45,7 @@ class Theme extends BaseModule
                if (file_exists("view/theme/$theme/style.php")) {
                        require_once "view/theme/$theme/style.php";
                }
-
+               DI::page()->logRuntime();
                exit();
        }
 }
index 6398a00c99704af5b5cfe5b52ccea382fb07ca6e..1bd45913a65b08f9f9b4c1c54bb35ec4f8cef63f 100644 (file)
@@ -48,6 +48,7 @@ class ThemeDetails extends BaseModule
                                'credits' => $credits,
                        ]);
                }
+               DI::page()->logRuntime();
                exit();
        }
 }
index 330cba2d3ed8a265d66d06393d8757f0e2c97072..2b71d23c4e4c9ea7973afe71aaef772f9df046fc 100644 (file)
@@ -31,6 +31,7 @@ class Network extends NetworkModule
        protected function rawContent(array $request = [])
        {
                if (!isset($_GET['p']) || !isset($_GET['item'])) {
+                       DI::page()->logRuntime();
                        exit();
                }
 
index cf1e058a1478711535a950c5cb63bfe2f1c7f0f6..c2271565c273bdd48e2dc0d256594822f5b6cdce 100644 (file)
@@ -69,6 +69,7 @@ class JsonLD
 
                if ($recursion > 5) {
                        Logger::error('jsonld bomb detected at: ' . $url);
+                       DI::page()->logRuntime();
                        exit();
                }