]> git.mxchange.org Git - friendica-addons.git/blob - rendertime/rendertime.php
Merge pull request #927 from nupplaphil/task/replace_getClass
[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\Core\Hook;
11 use Friendica\Core\L10n;
12 use Friendica\DI;
13
14 function rendertime_install() {
15         Hook::register('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end');
16 }
17
18
19 function rendertime_uninstall() {
20         Hook::unregister('init_1', 'addon/rendertime/rendertime.php', 'rendertime_init_1');
21         Hook::unregister('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end');
22 }
23
24 function rendertime_init_1(&$a) {
25 }
26
27 /**
28  * @param Friendica\App $a
29  * @param string $o
30  */
31 function rendertime_page_end(Friendica\App $a, &$o)
32 {
33
34         $profiler = DI::profiler();
35
36         $duration = microtime(true) - $profiler->get('start');
37
38         $ignored_modules = ["fbrowser"];
39         $ignored = in_array(DI::module()->getName(), $ignored_modules);
40
41         if (is_site_admin() && (($_GET['mode'] ?? '') != 'minimal') && !DI::mode()->isMobile() && !DI::mode()->isMobile() && !$ignored) {
42
43                 $o = $o . '<div class="renderinfo">' . L10n::t("Database: %s/%s, Network: %s, Rendering: %s, Session: %s, I/O: %s, Other: %s, Total: %s",
44                                 round($profiler->get('database') - $profiler->get('database_write'), 3),
45                                 round($profiler->get('database_write'), 3),
46                                 round($profiler->get('network'), 2),
47                                 round($profiler->get('rendering'), 2),
48                                 round($profiler->get('parser'), 2),
49                                 round($profiler->get('file'), 2),
50                                 round($duration - $profiler->get('database')
51                                         - $profiler->get('network') - $profiler->get('rendering')
52                                         - $profiler->get('parser') - $profiler->get('file'), 2),
53                                 round($duration, 2)
54                         //round($profiler->get('markstart'), 3)
55                         //round($profiler->get('plugin'), 3)
56                         ) . '</div>';
57
58                 if ($profiler->isRendertime()) {
59                         $o .= '<pre>';
60                         $o .= $profiler->getRendertimeString();
61                         $o .= '</pre>';
62                 }
63         }
64 }