4 * Description: Shows the time that was needed to render the current page
6 * Author: Michael Vogel <http://pirati.ca/profile/heluecht>
11 use Friendica\Core\Hook;
12 use Friendica\Core\Renderer;
15 function rendertime_install() {
16 Hook::register('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end');
17 DI::config()->set('system', 'profiler', true);
20 function rendertime_uninstall()
22 DI::config()->delete('system', 'profiler');
25 function rendertime_init_1()
29 function rendertime_addon_admin(string &$o)
31 $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/rendertime/');
33 $o = Renderer::replaceMacros($t, [
34 '$submit' => DI::l10n()->t('Save Settings'),
35 '$callstack' => ['callstack', DI::l10n()->t('Show callstack'), DI::config()->get('rendertime', 'callstack'), DI::l10n()->t('Show detailed performance measures in the callstack. When deactivated, only the summary will be displayed.')],
36 '$minimal_time' => ['minimal_time', DI::l10n()->t('Minimal time'), DI::config()->get('rendertime', 'minimal_time'), DI::l10n()->t('Minimal time that an activity needs to be listed in the callstack.')],
40 function rendertime_addon_admin_post()
42 DI::config()->set('rendertime', 'callstack', $_POST['callstack'] ?? false);
43 DI::config()->set('rendertime', 'minimal_time', $_POST['minimal_time'] ?? 0);
49 function rendertime_page_end(string &$o)
51 $profiler = DI::profiler();
53 $duration = microtime(true) - $profiler->get('start');
56 \Friendica\Module\Media\Photo\Browser::class,
57 \Friendica\Module\Media\Attachment\Browser::class,
59 $ignored = in_array(DI::router()->getModuleClass(), $ignored_modules);
61 if (DI::userSession()->isSiteAdmin() && (($_GET['mode'] ?? '') != 'minimal') && !DI::mode()->isMobile() && !DI::mode()->isMobile() && !$ignored) {
63 $o = $o . '<div class="renderinfo">' . DI::l10n()->t("Database: %s/%s, Network: %s, Rendering: %s, Session: %s, I/O: %s, Other: %s, Total: %s",
64 round($profiler->get('database') - $profiler->get('database_write'), 3),
65 round($profiler->get('database_write'), 3),
66 round($profiler->get('network'), 2),
67 round($profiler->get('rendering'), 2),
68 round($profiler->get('session'), 2),
69 round($profiler->get('file'), 2),
70 round($duration - $profiler->get('database')
71 - $profiler->get('network') - $profiler->get('rendering')
72 - $profiler->get('session') - $profiler->get('file'), 2),
74 //round($profiler->get('markstart'), 3)
75 //round($profiler->get('plugin'), 3)
78 $total = microtime(true) - $profiler->get('start');
79 $rest = $total - ($profiler->get('ready') - $profiler->get('start')) - $profiler->get('init') - $profiler->get('content');
80 $o = $o . '<div class="renderinfo">' . DI::l10n()->t("Class-Init: %s, Boot: %s, Init: %s, Content: %s, Other: %s, Total: %s",
81 round($profiler->get('classinit') - $profiler->get('start'), 3),
82 round($profiler->get('ready') - $profiler->get('classinit'), 3),
83 round($profiler->get('init'), 3),
84 round($profiler->get('content'), 3),
89 if ($profiler->isRendertime()) {
91 $o .= $profiler->getRendertimeString(floatval(DI::config()->get('rendertime', 'minimal_time', 0)));