]> git.mxchange.org Git - friendica-addons.git/blob - rendertime/rendertime.php
Rendertime: Optionally show the callstack
[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 function rendertime_install() {
13         register_hook('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end');
14 }
15
16
17 function rendertime_uninstall() {
18         unregister_hook('init_1', 'addon/rendertime/rendertime.php', 'rendertime_init_1');
19         unregister_hook('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end');
20 }
21
22 function rendertime_init_1(&$a) {
23 }
24
25 function rendertime_page_end(&$a, &$o) {
26
27         $duration = microtime(true)-$a->performance["start"];
28
29         if (is_site_admin() AND ($_GET["mode"] != "minimal") AND !$a->is_mobile AND !$a->is_tablet) {
30                 $o = $o.'<div class="renderinfo">'.sprintf(t("Performance: Database: %s, Network: %s, Rendering: %s, Parser: %s, I/O: %s, Other: %s, Total: %s"),
31                                                 round($a->performance["database"], 3),
32                                                 round($a->performance["network"], 3),
33                                                 round($a->performance["rendering"], 3),
34                                                 round($a->performance["parser"], 3),
35                                                 round($a->performance["file"], 3),
36                                                 round($duration - $a->performance["database"] - $a->performance["network"]
37                                                          - $a->performance["rendering"] - $a->performance["parser"]
38                                                          - $a->performance["file"], 3),
39                                                 round($duration, 3)
40                                                 //round($a->performance["markstart"], 3)
41                                                 //round($a->performance["plugin"], 3)
42                                                 )."</div>";
43
44                 if (get_config("rendertime", "callstack")) {
45                         $o .= "<pre>";
46                         $o .= "\nDatabase:\n";
47                         foreach ($a->callstack["database"] AS $func => $time) {
48                                 $time = round($time, 3);
49                                 if ($time > 0)
50                                         $o .= $func.": ".$time."\n";
51                         }
52
53                         $o .= "\nNetwork:\n";
54                         foreach ($a->callstack["network"] AS $func => $time) {
55                                 $time = round($time, 3);
56                                 if ($time > 0)
57                                         $o .= $func.": ".$time."\n";
58                         }
59
60                         $o .= "</pre>";
61                 }
62         }
63 }