]> git.mxchange.org Git - friendica.git/commitdiff
Generate callstack value from inside Profiler::saveTimestamp
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 27 Jul 2020 04:22:07 +0000 (00:22 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 27 Jul 2020 06:33:05 +0000 (02:33 -0400)
- Save a massive amount of time computing callstacks when profiling is disabled

13 files changed:
src/Content/Text/BBCode.php
src/Content/Text/Markdown.php
src/Core/Addon.php
src/Core/Cache/ProfilerCache.php
src/Core/Renderer.php
src/Core/Theme.php
src/Database/Database.php
src/Factory/SessionFactory.php
src/Network/HTTPRequest.php
src/Object/Image.php
src/Util/Images.php
src/Util/Logger/ProfilerLogger.php
src/Util/Profiler.php

index 1181c8f47bc2a66e4dc4ccedbbb20381e22827c8..cae3e941a75a946172a852ef667f585ca4bcc37d 100644 (file)
@@ -1098,7 +1098,7 @@ class BBCode
                        @curl_exec($ch);
                        $curl_info = @curl_getinfo($ch);
 
-                       DI::profiler()->saveTimestamp($stamp1, "network", System::callstack());
+                       DI::profiler()->saveTimestamp($stamp1, "network");
 
                        if (substr($curl_info['content_type'], 0, 6) == 'image/') {
                                $text = "[url=" . $match[1] . ']' . $match[1] . "[/url]";
@@ -1172,7 +1172,7 @@ class BBCode
                @curl_exec($ch);
                $curl_info = @curl_getinfo($ch);
 
-               DI::profiler()->saveTimestamp($stamp1, "network", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "network");
 
                // if its a link to a picture then embed this picture
                if (substr($curl_info['content_type'], 0, 6) == 'image/') {
@@ -2045,7 +2045,7 @@ class BBCode
                // Now convert HTML to Markdown
                $text = HTML::toMarkdown($text);
 
-               DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "parser");
 
                // Libertree has a problem with escaped hashtags.
                $text = str_replace(['\#'], ['#'], $text);
index 1b3f8ec7102769b229981751bd2df7c03dbbe7b5..45f38e4c5b3896c125587619c5926a7d69e50c2f 100644 (file)
@@ -57,7 +57,7 @@ class Markdown
 
                $html = $MarkdownParser->transform($text);
 
-               DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "parser");
 
                return $html;
        }
index dd229be287a83ebbb15466be1e401d00128ecba4..ee70a66b6e47fd025b9c6e365f708110ffe29a8b 100644 (file)
@@ -256,7 +256,7 @@ class Addon
 
                $stamp1 = microtime(true);
                $f = file_get_contents("addon/$addon/$addon.php");
-               DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "file");
 
                $r = preg_match("|/\*.*\*/|msU", $f, $m);
 
index 1f77db67acb07695f631e17d9ace4e5231b38511..7c4802077ab07d99b1ae9db724854f34425fa109 100644 (file)
@@ -56,7 +56,7 @@ class ProfilerCache implements ICache, IMemoryCache
 
                $return = $this->cache->getAllKeys($prefix);
 
-               $this->profiler->saveTimestamp($time, 'cache', System::callstack());
+               $this->profiler->saveTimestamp($time, 'cache');
 
                return $return;
        }
@@ -70,7 +70,7 @@ class ProfilerCache implements ICache, IMemoryCache
 
                $return = $this->cache->get($key);
 
-               $this->profiler->saveTimestamp($time, 'cache', System::callstack());
+               $this->profiler->saveTimestamp($time, 'cache');
 
                return $return;
        }
@@ -84,7 +84,7 @@ class ProfilerCache implements ICache, IMemoryCache
 
                $return = $this->cache->set($key, $value, $ttl);
 
-               $this->profiler->saveTimestamp($time, 'cache', System::callstack());
+               $this->profiler->saveTimestamp($time, 'cache');
 
                return $return;
        }
@@ -98,7 +98,7 @@ class ProfilerCache implements ICache, IMemoryCache
 
                $return = $this->cache->delete($key);
 
-               $this->profiler->saveTimestamp($time, 'cache', System::callstack());
+               $this->profiler->saveTimestamp($time, 'cache');
 
                return $return;
        }
@@ -112,7 +112,7 @@ class ProfilerCache implements ICache, IMemoryCache
 
                $return = $this->cache->clear($outdated);
 
-               $this->profiler->saveTimestamp($time, 'cache', System::callstack());
+               $this->profiler->saveTimestamp($time, 'cache');
 
                return $return;
        }
@@ -127,7 +127,7 @@ class ProfilerCache implements ICache, IMemoryCache
 
                        $return = $this->cache->add($key, $value, $ttl);
 
-                       $this->profiler->saveTimestamp($time, 'cache', System::callstack());
+                       $this->profiler->saveTimestamp($time, 'cache');
 
                        return $return;
                } else {
@@ -145,7 +145,7 @@ class ProfilerCache implements ICache, IMemoryCache
 
                        $return = $this->cache->compareSet($key, $oldValue, $newValue, $ttl);
 
-                       $this->profiler->saveTimestamp($time, 'cache', System::callstack());
+                       $this->profiler->saveTimestamp($time, 'cache');
 
                        return $return;
                } else {
@@ -163,7 +163,7 @@ class ProfilerCache implements ICache, IMemoryCache
 
                        $return = $this->cache->compareDelete($key, $value);
 
-                       $this->profiler->saveTimestamp($time, 'cache', System::callstack());
+                       $this->profiler->saveTimestamp($time, 'cache');
 
                        return $return;
                } else {
index bf4cd390782babaaa28515b14b6348e11845b258..24f00341733530a24d097a1a1bf01f00049bda94 100644 (file)
@@ -92,7 +92,7 @@ class Renderer
                        throw new InternalServerErrorException($message);
                }
 
-               DI::profiler()->saveTimestamp($stamp1, "rendering", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "rendering");
 
                return $output;
        }
@@ -121,7 +121,7 @@ class Renderer
                        throw new InternalServerErrorException($message);
                }
 
-               DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "file");
 
                return $template;
        }
index 03f1dfd9cd45c0de6a9533fcde4458c2008e0058..3548544e95d66cfebda85bc8de4b7f7376d8be63 100644 (file)
@@ -90,7 +90,7 @@ class Theme
 
                $stamp1 = microtime(true);
                $theme_file = file_get_contents("view/theme/$theme/theme.php");
-               DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "file");
 
                $result = preg_match("|/\*.*\*/|msU", $theme_file, $matches);
 
index 5ef481556328cb061d225be9b5f7c4bb551852b0..0b38c24ba336b9ab27308dcdbfddeb2f0cca567e 100644 (file)
@@ -699,7 +699,7 @@ class Database
                        $this->errorno = $errorno;
                }
 
-               $this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'database');
 
                if ($this->configCache->get('system', 'db_log')) {
                        $stamp2   = microtime(true);
@@ -783,7 +783,7 @@ class Database
                        $this->errorno = $errorno;
                }
 
-               $this->profiler->saveTimestamp($stamp, "database_write", System::callstack());
+               $this->profiler->saveTimestamp($stamp, "database_write");
 
                return $retval;
        }
@@ -964,7 +964,7 @@ class Database
                                }
                }
 
-               $this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'database');
 
                return $columns;
        }
@@ -1644,7 +1644,7 @@ class Database
                                break;
                }
 
-               $this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'database');
 
                return $ret;
        }
index f513eef35f797a20c7098382744232593fdf0cc6..116afe18a75d095779edbfccd1c278709867d14a 100644 (file)
@@ -85,7 +85,7 @@ class SessionFactory
                                $session = new Session\Native($baseURL, $handler);
                        }
                } finally {
-                       $profiler->saveTimestamp($stamp1, 'parser', System::callstack());
+                       $profiler->saveTimestamp($stamp1, 'parser');
                        return $session;
                }
        }
index 839586880ca1b9782ddc8090b0b5a2d712d1d352..87177b1a4081fbb5a6d85a11a87d91463e5bdfb0 100644 (file)
@@ -199,7 +199,7 @@ class HTTPRequest implements IHTTPRequest
 
                @curl_close($ch);
 
-               $this->profiler->saveTimestamp($stamp1, 'network', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'network');
 
                return $curlResponse;
        }
@@ -285,7 +285,7 @@ class HTTPRequest implements IHTTPRequest
 
                curl_close($ch);
 
-               $this->profiler->saveTimestamp($stamp1, 'network', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'network');
 
                // Very old versions of Lighttpd don't like the "Expect" header, so we remove it when needed
                if ($curlResponse->getReturnCode() == 417) {
@@ -335,7 +335,7 @@ class HTTPRequest implements IHTTPRequest
                $http_code = $curl_info['http_code'];
                curl_close($ch);
 
-               $this->profiler->saveTimestamp($stamp1, "network", System::callstack());
+               $this->profiler->saveTimestamp($stamp1, "network");
 
                if ($http_code == 0) {
                        return $url;
@@ -377,7 +377,7 @@ class HTTPRequest implements IHTTPRequest
                $body = curl_exec($ch);
                curl_close($ch);
 
-               $this->profiler->saveTimestamp($stamp1, "network", System::callstack());
+               $this->profiler->saveTimestamp($stamp1, "network");
 
                if (trim($body) == "") {
                        return $url;
index 8787db05283cdeb6bb6759e545de4e6bbe96867a..b69682ca6140bf301572ebf1cade688a4a49b66c 100644 (file)
@@ -625,7 +625,7 @@ class Image
 
                $stamp1 = microtime(true);
                file_put_contents($path, $string);
-               DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
+               DI::profiler()->saveTimestamp($stamp1, "file");
        }
 
        /**
index ef171873f2f9d4ca5666e694b4cc97c8cd1ff5ee..f39b0db00dc235a643475159e562724bc4c0c0b6 100644 (file)
@@ -200,7 +200,7 @@ class Images
 
                                $stamp1 = microtime(true);
                                file_put_contents($tempfile, $img_str);
-                               DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
+                               DI::profiler()->saveTimestamp($stamp1, "file");
 
                                $data = getimagesize($tempfile);
                                unlink($tempfile);
index 2f194095283f216dfdc41048cafc863b40fe4ffc..e0f18b2851ed69f6fbba62cea6a1e5025781176d 100644 (file)
@@ -61,7 +61,7 @@ class ProfilerLogger implements LoggerInterface
        {
                $stamp1 = microtime(true);
                $this->logger->emergency($message, $context);
-               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'file');
        }
 
        /**
@@ -71,7 +71,7 @@ class ProfilerLogger implements LoggerInterface
        {
                $stamp1 = microtime(true);
                $this->logger->alert($message, $context);
-               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'file');
        }
 
        /**
@@ -81,7 +81,7 @@ class ProfilerLogger implements LoggerInterface
        {
                $stamp1 = microtime(true);
                $this->logger->critical($message, $context);
-               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'file');
        }
 
        /**
@@ -91,7 +91,7 @@ class ProfilerLogger implements LoggerInterface
        {
                $stamp1 = microtime(true);
                $this->logger->error($message, $context);
-               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'file');
        }
 
        /**
@@ -101,7 +101,7 @@ class ProfilerLogger implements LoggerInterface
        {
                $stamp1 = microtime(true);
                $this->logger->warning($message, $context);
-               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'file');
        }
 
        /**
@@ -111,7 +111,7 @@ class ProfilerLogger implements LoggerInterface
        {
                $stamp1 = microtime(true);
                $this->logger->notice($message, $context);
-               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'file');
        }
 
        /**
@@ -121,7 +121,7 @@ class ProfilerLogger implements LoggerInterface
        {
                $stamp1 = microtime(true);
                $this->logger->info($message, $context);
-               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'file');
        }
 
        /**
@@ -131,7 +131,7 @@ class ProfilerLogger implements LoggerInterface
        {
                $stamp1 = microtime(true);
                $this->logger->debug($message, $context);
-               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'file');
        }
 
        /**
@@ -141,6 +141,6 @@ class ProfilerLogger implements LoggerInterface
        {
                $stamp1 = microtime(true);
                $this->logger->log($level, $message, $context);
-               $this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
+               $this->profiler->saveTimestamp($stamp1, 'file');
        }
 }
index 240273bde3ce319594cbe4c6a4adc7de6dcada33..db3e1bb97825f38f4d48cab62170377e54dc4f6b 100644 (file)
@@ -23,6 +23,7 @@ namespace Friendica\Util;
 
 use Friendica\Core\Config\Cache;
 use Friendica\Core\Config\IConfig;
+use Friendica\Core\System;
 use Psr\Container\ContainerExceptionInterface;
 use Psr\Container\ContainerInterface;
 use Psr\Container\NotFoundExceptionInterface;
@@ -88,9 +89,9 @@ class Profiler implements ContainerInterface
         * Saves a timestamp for a value - f.e. a call
         * Necessary for profiling Friendica
         *
-        * @param int $timestamp the Timestamp
-        * @param string $value A value to profile
-        * @param string $callstack The callstack of the current profiling data
+        * @param int    $timestamp the Timestamp
+        * @param string $value     A value to profile
+        * @param string $callstack A callstack string, generated if absent
         */
        public function saveTimestamp($timestamp, $value, $callstack = '')
        {
@@ -98,6 +99,8 @@ class Profiler implements ContainerInterface
                        return;
                }
 
+               $callstack = $callstack ?: System::callstack(4, 1);
+
                $duration = floatval(microtime(true) - $timestamp);
 
                if (!isset($this->performance[$value])) {