]> git.mxchange.org Git - friendica-addons.git/blob - rendertime/rendertime.php
[rendertime] Adapt ignored_modules
[friendica-addons.git] / rendertime / rendertime.php
1 <?php
2 /**
3  * Name: rendertime
4  * Description: Shows the time that was needed to render the current page
5  * Version: 0.1
6  * Author: Michael Vogel <http://pirati.ca/profile/heluecht>
7  *
8  */
9
10 use Friendica\App;
11 use Friendica\Core\Hook;
12 use Friendica\Core\Renderer;
13 use Friendica\DI;
14
15 function rendertime_install() {
16         Hook::register('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end');
17         DI::config()->set('system', 'profiler', true);
18 }
19
20 function rendertime_uninstall()
21 {
22         DI::config()->delete('system', 'profiler');
23 }
24
25 function rendertime_init_1(App $a)
26 {
27 }
28
29 function rendertime_addon_admin(App $a, string &$o)
30 {
31         $t = Renderer::getMarkupTemplate('admin.tpl', 'addon/rendertime/');
32
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.')],
37         ]);
38 }
39
40 function rendertime_addon_admin_post(App $a)
41 {
42         DI::config()->set('rendertime', 'callstack', $_POST['callstack'] ?? false);
43         DI::config()->set('rendertime', 'minimal_time', $_POST['minimal_time'] ?? 0);
44 }
45
46 /**
47  * @param App $a
48  * @param string $o
49  */
50 function rendertime_page_end(App $a, string &$o)
51 {
52         $profiler = DI::profiler();
53
54         $duration = microtime(true) - $profiler->get('start');
55
56         $ignored_modules = [
57                 \Friendica\Module\Profile\Photos\Browser::class,
58                 \Friendica\Module\Profile\Attachment\Browser::class,
59         ];
60         $ignored = in_array(DI::router()->getModuleClass(), $ignored_modules);
61
62         if ($a->isSiteAdmin() && (($_GET['mode'] ?? '') != 'minimal') && !DI::mode()->isMobile() && !DI::mode()->isMobile() && !$ignored) {
63
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),
74                                 round($duration, 2)
75                         //round($profiler->get('markstart'), 3)
76                         //round($profiler->get('plugin'), 3)
77                         ) . '</div>';
78
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),
86                                 round($rest, 3),
87                                 round($total, 3)
88                                 ) . '</div>';
89
90                 if ($profiler->isRendertime()) {
91                         $o .= '<pre>';
92                         $o .= $profiler->getRendertimeString(DI::config()->get('rendertime', 'minimal_time', 0));
93                         $o .= '</pre>';
94                 }
95         }
96 }