]> git.mxchange.org Git - friendica-addons.git/blob - rendertime/rendertime.php
Rendertime: Ignorelist for page where rendertime doesn't look good.
[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         $ignored_modules = array("fbrowser");
30         $ignored = in_array($a->module, $ignored_modules);
31
32         if (is_site_admin() AND ($_GET["mode"] != "minimal") AND !$a->is_mobile AND !$a->is_tablet AND !$ignored) {
33                 $o = $o.'<div class="renderinfo">'.sprintf(t("Database: %s, Network: %s, Rendering: %s, Session: %s, I/O: %s, Other: %s, Total: %s"),
34                                                 round($a->performance["database"], 3),
35                                                 round($a->performance["network"], 3),
36                                                 round($a->performance["rendering"], 3),
37                                                 round($a->performance["parser"], 3),
38                                                 round($a->performance["file"], 3),
39                                                 round($duration - $a->performance["database"] - $a->performance["network"]
40                                                          - $a->performance["rendering"] - $a->performance["parser"]
41                                                          - $a->performance["file"], 3),
42                                                 round($duration, 3)
43                                                 //round($a->performance["markstart"], 3)
44                                                 //round($a->performance["plugin"], 3)
45                                                 )."</div>";
46
47                 if (get_config("rendertime", "callstack")) {
48                         $o .= "<pre>";
49                         $o .= "\nDatabase:\n";
50                         foreach ($a->callstack["database"] AS $func => $time) {
51                                 $time = round($time, 3);
52                                 if ($time > 0)
53                                         $o .= $func.": ".$time."\n";
54                         }
55
56                         $o .= "\nNetwork:\n";
57                         foreach ($a->callstack["network"] AS $func => $time) {
58                                 $time = round($time, 3);
59                                 if ($time > 0)
60                                         $o .= $func.": ".$time."\n";
61                         }
62
63                         $o .= "</pre>";
64                 }
65         }
66 }