Generate callstack value from inside Profiler::saveTimestamp

- Save a massive amount of time computing callstacks when profiling is disabled
This commit is contained in:
Hypolite Petovan 2020-07-27 00:22:07 -04:00
parent 19141b1bcf
commit afb882048e
13 changed files with 42 additions and 39 deletions

View 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);

View 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;
}

View 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);

View 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 {

View 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;
}

View 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);

View 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;
}

View 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;
}
}

View 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;

View 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");
}
/**

View 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);

View 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');
}
}

View 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])) {