Remove sprintf with translations
[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 Vvogel <http://pirati.ca/profile/heluecht>
7  *
8  */
9 use Friendica\Core\Addon;
10 use Friendica\Core\Config;
11 use Friendica\Core\L10n;
12
13 function rendertime_install() {
14         Addon::registerHook('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end');
15 }
16
17
18 function rendertime_uninstall() {
19         Addon::unregisterHook('init_1', 'addon/rendertime/rendertime.php', 'rendertime_init_1');
20         Addon::unregisterHook('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end');
21 }
22
23 function rendertime_init_1(&$a) {
24 }
25
26 function rendertime_page_end(&$a, &$o) {
27
28         $duration = microtime(true)-$a->performance["start"];
29
30         $ignored_modules = ["fbrowser"];
31         $ignored = in_array($a->module, $ignored_modules);
32
33         if (is_site_admin() && ($_GET["mode"] != "minimal") && !$a->is_mobile && !$a->is_tablet && !$ignored) {
34                 $o = $o.'<div class="renderinfo">'. L10n::t("Database: %s/%s, Network: %s, Rendering: %s, Session: %s, I/O: %s, Other: %s, Total: %s",
35                         round($a->performance["database"] - $a->performance["database_write"], 3),
36                         round($a->performance["database_write"], 3),
37                         round($a->performance["network"], 2),
38                         round($a->performance["rendering"], 2),
39                         round($a->performance["parser"], 2),
40                         round($a->performance["file"], 2),
41                         round($duration - $a->performance["database"]
42                                         - $a->performance["network"] - $a->performance["rendering"]
43                                         - $a->performance["parser"] - $a->performance["file"], 2),
44                         round($duration, 2)
45                         //round($a->performance["markstart"], 3)
46                         //round($a->performance["plugin"], 3)
47                         )."</div>";
48
49                 if (Config::get("rendertime", "callstack")) {
50                         $o .= "<pre>";
51                         $o .= "\nDatabase Read:\n";
52                         foreach ($a->callstack["database"] AS $func => $time) {
53                                 $time = round($time, 3);
54                                 if ($time > 0)
55                                         $o .= $func.": ".$time."\n";
56                         }
57                         $o .= "\nDatabase Write:\n";
58                         foreach ($a->callstack["database_write"] AS $func => $time) {
59                                 $time = round($time, 3);
60                                 if ($time > 0)
61                                         $o .= $func.": ".$time."\n";
62                         }
63
64                         $o .= "\nNetwork:\n";
65                         foreach ($a->callstack["network"] AS $func => $time) {
66                                 $time = round($time, 3);
67                                 if ($time > 0)
68                                         $o .= $func.": ".$time."\n";
69                         }
70
71                         $o .= "</pre>";
72                 }
73         }
74 }