]> git.mxchange.org Git - friendica.git/commitdiff
Several improvements for performance measuring
authorMichael Vogel <icarus@dabo.de>
Sat, 26 Jan 2013 17:35:39 +0000 (18:35 +0100)
committerMichael Vogel <icarus@dabo.de>
Sat, 26 Jan 2013 17:35:39 +0000 (18:35 +0100)
boot.php
include/bbcode.php
include/dba.php
include/items.php
include/network.php
include/plugin.php
include/tags.php
include/text.php
mod/item.php

index b851068f400063a219d31ef3c5958195cf91e4c8..b0e77a71fbf50025dc5a4845e6d533242512ab8c 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -417,6 +417,7 @@ if(! class_exists('App')) {
                        $this->performance["database"] = 0;
                        $this->performance["network"] = 0;
                        $this->performance["rendering"] = 0;
+                       $this->performance["parser"] = 0;
 
                        $this->config = array();
                        $this->page = array();
@@ -725,6 +726,12 @@ if(! class_exists('App')) {
                        return $this->rdelim[$engine];
                }
 
+               function save_timestamp($stamp1, $value) {
+                       $stamp2 = microtime(true);
+                       $duration = (float)($stamp2-$stamp1);
+                       $this->performance[$value] += (float)$duration;
+               }
+
        }
 }
 
index 613c2b7db06eec5787d51d893f7d57a66c144ad4..45213cc3b75f3812020a3c148616fe85943bb204 100644 (file)
@@ -283,6 +283,8 @@ function bb_ShareAttributes($match) {
 
 function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
 
+       $stamp1 = microtime(true);
+
        $a = get_app();
 
        // Hide all [noparse] contained bbtags by spacefying them
@@ -637,6 +639,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
 
        call_hooks('bbcode',$Text);
 
+       $a->save_timestamp($stamp1, "parser");
+
        return $Text;
 }
 
index dd7f56bfd9025f77c07d234148c3b8edff53be91..50354b7f49ebaad028dc2042f335ce35ce78d76a 100644 (file)
@@ -23,6 +23,9 @@ class dba {
        public  $error = false;
 
        function __construct($server,$user,$pass,$db,$install = false) {
+               global $a;
+
+               $stamp1 = microtime(true);
 
                $server = trim($server);
                $user = trim($user);
@@ -64,6 +67,8 @@ class dba {
                        if(! $install)
                                system_unavailable();
                }
+
+               $a->save_timestamp($stamp1, "network");
        }
 
        public function getdb() {
@@ -87,7 +92,6 @@ class dba {
 
                $stamp2 = microtime(true);
                $duration = (float)($stamp2-$stamp1);
-               $a->performance["database"] += (float)$duration;
 
                if(x($a->config,'system') && x($a->config['system'],'db_log')) {
                        if (($duration > $a->config["system"]["db_loglimit"])) {
@@ -164,6 +168,7 @@ class dba {
                        }
                }
 
+               $a->save_timestamp($stamp1, "database");
 
                if($this->debug)
                        logger('dba: ' . printable(print_r($r, true)));
index 54b392b3860f8c482adeadea6d67aa56df12c956..1a50ac204af9bf234b995cb4006aeaf761c9be7d 100755 (executable)
@@ -1159,7 +1159,9 @@ function item_store($arr,$force_parent = false) {
 
        if (($cachefile != '') AND !file_exists($cachefile)) {
                $s = prepare_text($arr['body']);
+               $stamp1 = microtime(true);
                file_put_contents($cachefile, $s);
+               $a->save_timestamp($stamp1, "file");
                logger('item_store: put item '.$current_post.' into cachefile '.$cachefile);
        }
 
index 10590f8bf4fcef8d2ea4a4b71310a3553dfba7b7..400c1386be69a2779dd59894962037460bab79ee 100644 (file)
@@ -104,9 +104,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
        $a->set_curl_headers($header);
        @curl_close($ch);
 
-       $stamp2 = microtime(true);
-       $duration = (float)($stamp2-$stamp1);
-       $a->performance["network"] += (float)$duration;
+       $a->save_timestamp($stamp1, "network");
 
        return($body);
 }}
@@ -201,9 +199,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
 
        curl_close($ch);
 
-       $stamp2 = microtime(true);
-       $duration = (float)($stamp2-$stamp1);
-       $a->performance["network"] += (float)$duration;
+       $a->save_timestamp($stamp1, "network");
 
        return($body);
 }}
@@ -851,8 +847,11 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
                        $i = fetch_url($scaled);
 
                        $cachefile = get_cachefile(hash("md5", $scaled));
-                       if ($cachefile != '')
+                       if ($cachefile != '') {
+                               $stamp1 = microtime(true);
                                file_put_contents($cachefile, $i);
+                               $a->save_timestamp($stamp1, "file");
+                       }
 
                        // guess mimetype from headers or filename
                        $type = guess_image_type($mtch[1],true);
index db3224f29658ff2a1fe1ca8e302388ab77e353b3..a6928793d4061d118c392536eee7f3ec6f1b6f12 100644 (file)
@@ -201,12 +201,15 @@ function get_plugin_info($plugin){
                'author' => array(),
                'version' => ""
        );
-       
+
        if (!is_file("addon/$plugin/$plugin.php")) return $info;
-       
+
+       $stamp1 = microtime(true);
        $f = file_get_contents("addon/$plugin/$plugin.php");
+       $a->save_timestamp($stamp1, "file");
+
        $r = preg_match("|/\*.*\*/|msU", $f, $m);
-       
+
        if ($r){
                $ll = explode("\n", $m[0]);
                foreach( $ll as $l ) {
@@ -266,11 +269,13 @@ function get_theme_info($theme){
                $info['unsupported'] = true;
 
        if (!is_file("view/theme/$theme/theme.php")) return $info;
-       
+
+       $stamp1 = microtime(true);
        $f = file_get_contents("view/theme/$theme/theme.php");
+       $a->save_timestamp($stamp1, "file");
+
        $r = preg_match("|/\*.*\*/|msU", $f, $m);
-       
-       
+
        if ($r){
                $ll = explode("\n", $m[0]);
                foreach( $ll as $l ) {
index b02adc3d83f85918c2601c891fa66bf80564b197..c81a752d544ce2bb66947391982b41b47a9b8cb6 100644 (file)
@@ -46,7 +46,9 @@ function create_tags_from_item($itemid) {
 
        if (($cachefile != '') AND !file_exists($cachefile)) {
                $s = prepare_text($message['body']);
+               $stamp1 = microtime(true);
                file_put_contents($cachefile, $s);
+               $a->save_timestamp($stamp1, "file");
                logger('create_tags_from_item: put item '.$message["id"].' into cachefile '.$cachefile);
        }
 
index 8f0b07bc93f012118f5a04dc80789e52929748b9..83639ce85cde0eeaa58317b9e79ebc373b05001a 100644 (file)
@@ -428,15 +428,26 @@ function load_view_file($s) {
                $lang = 'en';
        $b = basename($s);
        $d = dirname($s);
-       if(file_exists("$d/$lang/$b"))
-               return file_get_contents("$d/$lang/$b");
+       if(file_exists("$d/$lang/$b")) {
+               $stamp1 = microtime(true);
+               $content = file_get_contents("$d/$lang/$b");
+               $a->save_timestamp($stamp1, "file");
+               return $content;
+       }
 
        $theme = current_theme();
 
-       if(file_exists("$d/theme/$theme/$b"))
-               return file_get_contents("$d/theme/$theme/$b");
+       if(file_exists("$d/theme/$theme/$b")) {
+               $stamp1 = microtime(true);
+               $content = file_get_contents("$d/theme/$theme/$b");
+               $a->save_timestamp($stamp1, "file");
+               return $content;
+       }
 
-       return file_get_contents($s);
+       $stamp1 = microtime(true);
+       $content = file_get_contents($s);
+       $a->save_timestamp($stamp1, "file");
+       return $content;
 }}
 
 if(! function_exists('get_intltext_template')) {
@@ -451,12 +462,22 @@ function get_intltext_template($s) {
        if(! isset($lang))
                $lang = 'en';
 
-       if(file_exists("view/$lang$engine/$s"))
-               return file_get_contents("view/$lang$engine/$s");
-       elseif(file_exists("view/en$engine/$s"))
-               return file_get_contents("view/en$engine/$s");
-       else
-               return file_get_contents("view$engine/$s");
+       if(file_exists("view/$lang$engine/$s")) {
+               $stamp1 = microtime(true);
+               $content = file_get_contents("view/$lang$engine/$s");
+               $a->save_timestamp($stamp1, "file");
+               return $content;
+       } elseif(file_exists("view/en$engine/$s")) {
+               $stamp1 = microtime(true);
+               $content = file_get_contents("view/en$engine/$s");
+               $a->save_timestamp($stamp1, "file");
+               return $content;
+       } else {
+               $stamp1 = microtime(true);
+               $content = file_get_contents("view$engine/$s");
+               $a->save_timestamp($stamp1, "file");
+               return $content;
+       }
 }}
 
 if(! function_exists('get_markup_template')) {
@@ -470,21 +491,19 @@ function get_markup_template($s, $root = '') {
 
                $template = new FriendicaSmarty();
                $template->filename = $template_file;
-
-               $stamp2 = microtime(true);
-               $duration = (float)($stamp2-$stamp1);
-               $a->performance["rendering"] += (float)$duration;
+               $a->save_timestamp($stamp1, "rendering");
 
                return $template;
        }
        else {
                $template_file = get_template_file($a, $s, $root);
+               $a->save_timestamp($stamp1, "rendering");
 
-               $stamp2 = microtime(true);
-               $duration = (float)($stamp2-$stamp1);
-               $a->performance["rendering"] += (float)$duration;
+               $stamp1 = microtime(true);
+               $content = file_get_contents($template_file);
+               $a->save_timestamp($stamp1, "file");
+               return $content;
 
-               return file_get_contents($template_file);
        }
 }}
 
@@ -541,8 +560,10 @@ function logger($msg,$level = 0) {
 
        if((! $debugging) || (! $logfile) || ($level > $loglevel))
                return;
-       
+
+       $stamp1 = microtime(true);
        @file_put_contents($logfile, datetime_convert() . ':' . session_id() . ' ' . $msg . "\n", FILE_APPEND);
+       $a->save_timestamp($stamp1, "file");
        return;
 }}
 
@@ -1029,11 +1050,15 @@ function prepare_body($item,$attach = false) {
        $cachefile = get_cachefile($item["guid"]."-".hash("md5", $item['body']));
 
        if (($cachefile != '')) {
-               if (file_exists($cachefile))
+               if (file_exists($cachefile)) {
+                       $stamp1 = microtime(true);
                        $s = file_get_contents($cachefile);
-               else {
+                       $a->save_timestamp($stamp1, "file");
+               } else {
                        $s = prepare_text($item['body']);
+                       $stamp1 = microtime(true);
                        file_put_contents($cachefile, $s);
+                       $a->save_timestamp($stamp1, "file");
                        logger('prepare_body: put item '.$item["id"].' into cachefile '.$cachefile);
                }
        } else
index 452ec8a36de917d90b8f18b194895793239782b6..926fbbf5255a9fc188e41b71bfdedc8ca613a092 100644 (file)
@@ -762,7 +762,9 @@ function item_post(&$a) {
 
                if (($cachefile != '') AND !file_exists($cachefile)) {
                        $s = prepare_text($datarray['body']);
+                       $stamp1 = microtime(true);
                        file_put_contents($cachefile, $s);
+                       $a->save_timestamp($stamp1, "file");
                        logger('mod_item: put item '.$r[0]['id'].' into cachefile '.$cachefile);
                }