4 * Description: Shows the time that was needed to render the current page
6 * Author: Michael Vogel <http://pirati.ca/profile/heluecht>
10 use Friendica\Core\Hook;
11 use Friendica\Core\Renderer;
14 function rendertime_install() {
15 Hook::register('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end');
16 DI::config()->set('system', 'profiler', true);
19 function rendertime_uninstall() {
20 DI::config()->delete('system', 'profiler');
23 function rendertime_init_1(&$a) {
26 function rendertime_addon_admin(&$a, &$o) {
27 $t = Renderer::getMarkupTemplate("admin.tpl", "addon/rendertime/");
29 $o = Renderer::replaceMacros($t, [
30 '$submit' => DI::l10n()->t('Save Settings'),
31 '$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.')],
32 '$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.')],
36 function rendertime_addon_admin_post(&$a) {
37 DI::config()->set('rendertime', 'callstack', $_POST['callstack'] ?? false);
38 DI::config()->set('rendertime', 'minimal_time', $_POST['minimal_time'] ?? 0);
42 * @param Friendica\App $a
45 function rendertime_page_end(Friendica\App $a, &$o)
48 $profiler = DI::profiler();
50 $duration = microtime(true) - $profiler->get('start');
52 $ignored_modules = ["fbrowser"];
53 $ignored = in_array(DI::args()->getModuleName(), $ignored_modules);
55 if ($a->isSiteAdmin() && (($_GET['mode'] ?? '') != 'minimal') && !DI::mode()->isMobile() && !DI::mode()->isMobile() && !$ignored) {
57 $o = $o . '<div class="renderinfo">' . DI::l10n()->t("Database: %s/%s, Network: %s, Rendering: %s, Session: %s, I/O: %s, Other: %s, Total: %s",
58 round($profiler->get('database') - $profiler->get('database_write'), 3),
59 round($profiler->get('database_write'), 3),
60 round($profiler->get('network'), 2),
61 round($profiler->get('rendering'), 2),
62 round($profiler->get('session'), 2),
63 round($profiler->get('file'), 2),
64 round($duration - $profiler->get('database')
65 - $profiler->get('network') - $profiler->get('rendering')
66 - $profiler->get('session') - $profiler->get('file'), 2),
68 //round($profiler->get('markstart'), 3)
69 //round($profiler->get('plugin'), 3)
72 $total = microtime(true) - $profiler->get('start');
73 $rest = $total - ($profiler->get('ready') - $profiler->get('start')) - $profiler->get('init') - $profiler->get('content');
74 $o = $o . '<div class="renderinfo">' . DI::l10n()->t("Class-Init: %s, Boot: %s, Init: %s, Content: %s, Other: %s, Total: %s",
75 round($profiler->get('classinit') - $profiler->get('start'), 3),
76 round($profiler->get('ready') - $profiler->get('classinit'), 3),
77 round($profiler->get('init'), 3),
78 round($profiler->get('content'), 3),
83 if ($profiler->isRendertime()) {
85 $o .= $profiler->getRendertimeString(DI::config()->get('rendertime', 'minimal_time', 0));