Use short form array syntax everywhere
[friendica-addons.git] / rendertime / rendertime.php
1 <?php
2
3
4 /**
5  * Name: rendertime
6  * Description: Shows the time that was needed to render the current page
7  * Version: 0.1
8  * Author: Michael Vvogel <http://pirati.ca/profile/heluecht>
9  *
10  */
11
12 use Friendica\Core\Config;
13
14 function rendertime_install() {
15         register_hook('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end');
16 }
17
18
19 function rendertime_uninstall() {
20         unregister_hook('init_1', 'addon/rendertime/rendertime.php', 'rendertime_init_1');
21         unregister_hook('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end');
22 }
23
24 function rendertime_init_1(&$a) {
25 }
26
27 function rendertime_page_end(&$a, &$o) {
28
29         $duration = microtime(true)-$a->performance["start"];
30
31         $ignored_modules = ["fbrowser"];
32         $ignored = in_array($a->module, $ignored_modules);
33
34         if (is_site_admin() && ($_GET["mode"] != "minimal") && !$a->is_mobile && !$a->is_tablet && !$ignored) {
35                 $o = $o.'<div class="renderinfo">'.sprintf(t("Database: %s/%s, Network: %s, Rendering: %s, Session: %s, I/O: %s, Other: %s, Total: %s"),
36                                                 round($a->performance["database"] - $a->performance["database_write"], 3),
37                                                 round($a->performance["database_write"], 3),
38                                                 round($a->performance["network"], 2),
39                                                 round($a->performance["rendering"], 2),
40                                                 round($a->performance["parser"], 2),
41                                                 round($a->performance["file"], 2),
42                                                 round($duration - $a->performance["database"]
43                                                          - $a->performance["network"] - $a->performance["rendering"]
44                                                          - $a->performance["parser"] - $a->performance["file"], 2),
45                                                 round($duration, 2)
46                                                 //round($a->performance["markstart"], 3)
47                                                 //round($a->performance["plugin"], 3)
48                                                 )."</div>";
49
50                 if (Config::get("rendertime", "callstack")) {
51                         $o .= "<pre>";
52                         $o .= "\nDatabase Read:\n";
53                         foreach ($a->callstack["database"] AS $func => $time) {
54                                 $time = round($time, 3);
55                                 if ($time > 0)
56                                         $o .= $func.": ".$time."\n";
57                         }
58                         $o .= "\nDatabase Write:\n";
59                         foreach ($a->callstack["database_write"] AS $func => $time) {
60                                 $time = round($time, 3);
61                                 if ($time > 0)
62                                         $o .= $func.": ".$time."\n";
63                         }
64
65                         $o .= "\nNetwork:\n";
66                         foreach ($a->callstack["network"] AS $func => $time) {
67                                 $time = round($time, 3);
68                                 if ($time > 0)
69                                         $o .= $func.": ".$time."\n";
70                         }
71
72                         $o .= "</pre>";
73                 }
74         }
75 }