]> git.mxchange.org Git - friendica-addons.git/blobdiff - rendertime/rendertime.php
Rendertime: We now additionally show the db write time.
[friendica-addons.git] / rendertime / rendertime.php
index 87a32901924263bc0aec33f027ff2a73ff47e4ea..574e6e0951b72087586704e0e618fb582d7b8c6b 100755 (executable)
@@ -10,7 +10,6 @@
  */
 
 function rendertime_install() {
-       register_hook('init_1', 'addon/rendertime/rendertime.php', 'rendertime_init_1');
        register_hook('page_end', 'addon/rendertime/rendertime.php', 'rendertime_page_end');
 }
 
@@ -21,15 +20,51 @@ function rendertime_uninstall() {
 }
 
 function rendertime_init_1(&$a) {
-       global $rendertime_start;
-
-       $rendertime_start = microtime(true);
 }
 
 function rendertime_page_end(&$a, &$o) {
-       global $rendertime_start;
 
-       $duration = round(microtime(true)-$rendertime_start, 3);
+       $duration = microtime(true)-$a->performance["start"];
+
+       if (is_site_admin() AND ($_GET["mode"] != "minimal") AND !$a->is_mobile AND !$a->is_tablet) {
+               $o = $o.'<div class="renderinfo">'.sprintf(t("Database: %s/%s, Network: %s, Rendering: %s, Session: %s, I/O: %s, Other: %s, Total: %s"),
+                                               round($a->performance["database"] - $a->performance["database_write"], 3),
+                                               round($a->performance["database_write"], 3),
+                                               round($a->performance["network"], 2),
+                                               round($a->performance["rendering"], 2),
+                                               round($a->performance["parser"], 2),
+                                               round($a->performance["file"], 2),
+                                               round($duration - $a->performance["database"]
+                                                        - $a->performance["network"] - $a->performance["rendering"]
+                                                        - $a->performance["parser"] - $a->performance["file"], 2),
+                                               round($duration, 2)
+                                               //round($a->performance["markstart"], 3)
+                                               //round($a->performance["plugin"], 3)
+                                               )."</div>";
+
+               if (get_config("rendertime", "callstack")) {
+                       $o .= "<pre>";
+                       $o .= "\nDatabase Read:\n";
+                       foreach ($a->callstack["database"] AS $func => $time) {
+                               $time = round($time, 3);
+                               if ($time > 0)
+                                       $o .= $func.": ".$time."\n";
+                       }
+                       $o .= "\nDatabase Write:\n";
+                       foreach ($a->callstack["database_write"] AS $func => $time) {
+                               $time = round($time, 3);
+                               if ($time > 0)
+                                       $o .= $func.": ".$time."\n";
+                       }
+
+                       $o .= "\nNetwork:\n";
+                       foreach ($a->callstack["network"] AS $func => $time) {
+                               $time = round($time, 3);
+                               if ($time > 0)
+                                       $o .= $func.": ".$time."\n";
+                       }
 
-       $o = $o.'<div class="renderinfo">'.sprintf(t("This page took %s seconds to render"), $duration)."</div>";
+                       $o .= "</pre>";
+               }
+       }
 }