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(App $a)
29 function rendertime_addon_admin(App $a, 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(App $a)
42 DI::config()->set('rendertime', 'callstack', $_POST['callstack'] ?? false);
43 DI::config()->set('rendertime', 'minimal_time', $_POST['minimal_time'] ?? 0);
50 function rendertime_page_end(App $a, string &$o)
52 $profiler = DI::profiler();
54 $duration = microtime(true) - $profiler->get('start');
57 \Friendica\Module\Profile\Photos\Browser::class,
58 \Friendica\Module\Profile\Attachment\Browser::class,
60 $ignored = in_array(DI::router()->getModuleClass(), $ignored_modules);
62 if ($a->isSiteAdmin() && (($_GET['mode'] ?? '') != 'minimal') && !DI::mode()->isMobile() && !DI::mode()->isMobile() && !$ignored) {
64 $o = $o . '<div class="renderinfo">' . DI::l10n()->t("Database: %s/%s, Network: %s, Rendering: %s, Session: %s, I/O: %s, Other: %s, Total: %s",
65 round($profiler->get('database') - $profiler->get('database_write'), 3),
66 round($profiler->get('database_write'), 3),
67 round($profiler->get('network'), 2),
68 round($profiler->get('rendering'), 2),
69 round($profiler->get('session'), 2),
70 round($profiler->get('file'), 2),
71 round($duration - $profiler->get('database')
72 - $profiler->get('network') - $profiler->get('rendering')
73 - $profiler->get('session') - $profiler->get('file'), 2),
75 //round($profiler->get('markstart'), 3)
76 //round($profiler->get('plugin'), 3)
79 $total = microtime(true) - $profiler->get('start');
80 $rest = $total - ($profiler->get('ready') - $profiler->get('start')) - $profiler->get('init') - $profiler->get('content');
81 $o = $o . '<div class="renderinfo">' . DI::l10n()->t("Class-Init: %s, Boot: %s, Init: %s, Content: %s, Other: %s, Total: %s",
82 round($profiler->get('classinit') - $profiler->get('start'), 3),
83 round($profiler->get('ready') - $profiler->get('classinit'), 3),
84 round($profiler->get('init'), 3),
85 round($profiler->get('content'), 3),
90 if ($profiler->isRendertime()) {
92 $o .= $profiler->getRendertimeString(DI::config()->get('rendertime', 'minimal_time', 0));