Generate callstack value from inside Profiler::saveTimestamp
- Save a massive amount of time computing callstacks when profiling is disabled
This commit is contained in:
parent
19141b1bcf
commit
afb882048e
13 changed files with 42 additions and 39 deletions
|
@ -1098,7 +1098,7 @@ class BBCode
|
||||||
@curl_exec($ch);
|
@curl_exec($ch);
|
||||||
$curl_info = @curl_getinfo($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/') {
|
if (substr($curl_info['content_type'], 0, 6) == 'image/') {
|
||||||
$text = "[url=" . $match[1] . ']' . $match[1] . "[/url]";
|
$text = "[url=" . $match[1] . ']' . $match[1] . "[/url]";
|
||||||
|
@ -1172,7 +1172,7 @@ class BBCode
|
||||||
@curl_exec($ch);
|
@curl_exec($ch);
|
||||||
$curl_info = @curl_getinfo($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 its a link to a picture then embed this picture
|
||||||
if (substr($curl_info['content_type'], 0, 6) == 'image/') {
|
if (substr($curl_info['content_type'], 0, 6) == 'image/') {
|
||||||
|
@ -2045,7 +2045,7 @@ class BBCode
|
||||||
// Now convert HTML to Markdown
|
// Now convert HTML to Markdown
|
||||||
$text = HTML::toMarkdown($text);
|
$text = HTML::toMarkdown($text);
|
||||||
|
|
||||||
DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack());
|
DI::profiler()->saveTimestamp($stamp1, "parser");
|
||||||
|
|
||||||
// Libertree has a problem with escaped hashtags.
|
// Libertree has a problem with escaped hashtags.
|
||||||
$text = str_replace(['\#'], ['#'], $text);
|
$text = str_replace(['\#'], ['#'], $text);
|
||||||
|
|
|
@ -57,7 +57,7 @@ class Markdown
|
||||||
|
|
||||||
$html = $MarkdownParser->transform($text);
|
$html = $MarkdownParser->transform($text);
|
||||||
|
|
||||||
DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack());
|
DI::profiler()->saveTimestamp($stamp1, "parser");
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,7 +256,7 @@ class Addon
|
||||||
|
|
||||||
$stamp1 = microtime(true);
|
$stamp1 = microtime(true);
|
||||||
$f = file_get_contents("addon/$addon/$addon.php");
|
$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);
|
$r = preg_match("|/\*.*\*/|msU", $f, $m);
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
||||||
|
|
||||||
$return = $this->cache->getAllKeys($prefix);
|
$return = $this->cache->getAllKeys($prefix);
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
$this->profiler->saveTimestamp($time, 'cache');
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
||||||
|
|
||||||
$return = $this->cache->get($key);
|
$return = $this->cache->get($key);
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
$this->profiler->saveTimestamp($time, 'cache');
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
||||||
|
|
||||||
$return = $this->cache->set($key, $value, $ttl);
|
$return = $this->cache->set($key, $value, $ttl);
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
$this->profiler->saveTimestamp($time, 'cache');
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
||||||
|
|
||||||
$return = $this->cache->delete($key);
|
$return = $this->cache->delete($key);
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
$this->profiler->saveTimestamp($time, 'cache');
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
||||||
|
|
||||||
$return = $this->cache->clear($outdated);
|
$return = $this->cache->clear($outdated);
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
$this->profiler->saveTimestamp($time, 'cache');
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
||||||
|
|
||||||
$return = $this->cache->add($key, $value, $ttl);
|
$return = $this->cache->add($key, $value, $ttl);
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
$this->profiler->saveTimestamp($time, 'cache');
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -145,7 +145,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
||||||
|
|
||||||
$return = $this->cache->compareSet($key, $oldValue, $newValue, $ttl);
|
$return = $this->cache->compareSet($key, $oldValue, $newValue, $ttl);
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
$this->profiler->saveTimestamp($time, 'cache');
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -163,7 +163,7 @@ class ProfilerCache implements ICache, IMemoryCache
|
||||||
|
|
||||||
$return = $this->cache->compareDelete($key, $value);
|
$return = $this->cache->compareDelete($key, $value);
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($time, 'cache', System::callstack());
|
$this->profiler->saveTimestamp($time, 'cache');
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -92,7 +92,7 @@ class Renderer
|
||||||
throw new InternalServerErrorException($message);
|
throw new InternalServerErrorException($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
DI::profiler()->saveTimestamp($stamp1, "rendering", System::callstack());
|
DI::profiler()->saveTimestamp($stamp1, "rendering");
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ class Renderer
|
||||||
throw new InternalServerErrorException($message);
|
throw new InternalServerErrorException($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
|
DI::profiler()->saveTimestamp($stamp1, "file");
|
||||||
|
|
||||||
return $template;
|
return $template;
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ class Theme
|
||||||
|
|
||||||
$stamp1 = microtime(true);
|
$stamp1 = microtime(true);
|
||||||
$theme_file = file_get_contents("view/theme/$theme/theme.php");
|
$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);
|
$result = preg_match("|/\*.*\*/|msU", $theme_file, $matches);
|
||||||
|
|
||||||
|
|
|
@ -699,7 +699,7 @@ class Database
|
||||||
$this->errorno = $errorno;
|
$this->errorno = $errorno;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
|
$this->profiler->saveTimestamp($stamp1, 'database');
|
||||||
|
|
||||||
if ($this->configCache->get('system', 'db_log')) {
|
if ($this->configCache->get('system', 'db_log')) {
|
||||||
$stamp2 = microtime(true);
|
$stamp2 = microtime(true);
|
||||||
|
@ -783,7 +783,7 @@ class Database
|
||||||
$this->errorno = $errorno;
|
$this->errorno = $errorno;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($stamp, "database_write", System::callstack());
|
$this->profiler->saveTimestamp($stamp, "database_write");
|
||||||
|
|
||||||
return $retval;
|
return $retval;
|
||||||
}
|
}
|
||||||
|
@ -964,7 +964,7 @@ class Database
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
|
$this->profiler->saveTimestamp($stamp1, 'database');
|
||||||
|
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
@ -1644,7 +1644,7 @@ class Database
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($stamp1, 'database', System::callstack());
|
$this->profiler->saveTimestamp($stamp1, 'database');
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ class SessionFactory
|
||||||
$session = new Session\Native($baseURL, $handler);
|
$session = new Session\Native($baseURL, $handler);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
$profiler->saveTimestamp($stamp1, 'parser', System::callstack());
|
$profiler->saveTimestamp($stamp1, 'parser');
|
||||||
return $session;
|
return $session;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,7 @@ class HTTPRequest implements IHTTPRequest
|
||||||
|
|
||||||
@curl_close($ch);
|
@curl_close($ch);
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($stamp1, 'network', System::callstack());
|
$this->profiler->saveTimestamp($stamp1, 'network');
|
||||||
|
|
||||||
return $curlResponse;
|
return $curlResponse;
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ class HTTPRequest implements IHTTPRequest
|
||||||
|
|
||||||
curl_close($ch);
|
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
|
// Very old versions of Lighttpd don't like the "Expect" header, so we remove it when needed
|
||||||
if ($curlResponse->getReturnCode() == 417) {
|
if ($curlResponse->getReturnCode() == 417) {
|
||||||
|
@ -335,7 +335,7 @@ class HTTPRequest implements IHTTPRequest
|
||||||
$http_code = $curl_info['http_code'];
|
$http_code = $curl_info['http_code'];
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($stamp1, "network", System::callstack());
|
$this->profiler->saveTimestamp($stamp1, "network");
|
||||||
|
|
||||||
if ($http_code == 0) {
|
if ($http_code == 0) {
|
||||||
return $url;
|
return $url;
|
||||||
|
@ -377,7 +377,7 @@ class HTTPRequest implements IHTTPRequest
|
||||||
$body = curl_exec($ch);
|
$body = curl_exec($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
$this->profiler->saveTimestamp($stamp1, "network", System::callstack());
|
$this->profiler->saveTimestamp($stamp1, "network");
|
||||||
|
|
||||||
if (trim($body) == "") {
|
if (trim($body) == "") {
|
||||||
return $url;
|
return $url;
|
||||||
|
|
|
@ -625,7 +625,7 @@ class Image
|
||||||
|
|
||||||
$stamp1 = microtime(true);
|
$stamp1 = microtime(true);
|
||||||
file_put_contents($path, $string);
|
file_put_contents($path, $string);
|
||||||
DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
|
DI::profiler()->saveTimestamp($stamp1, "file");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -200,7 +200,7 @@ class Images
|
||||||
|
|
||||||
$stamp1 = microtime(true);
|
$stamp1 = microtime(true);
|
||||||
file_put_contents($tempfile, $img_str);
|
file_put_contents($tempfile, $img_str);
|
||||||
DI::profiler()->saveTimestamp($stamp1, "file", System::callstack());
|
DI::profiler()->saveTimestamp($stamp1, "file");
|
||||||
|
|
||||||
$data = getimagesize($tempfile);
|
$data = getimagesize($tempfile);
|
||||||
unlink($tempfile);
|
unlink($tempfile);
|
||||||
|
|
|
@ -61,7 +61,7 @@ class ProfilerLogger implements LoggerInterface
|
||||||
{
|
{
|
||||||
$stamp1 = microtime(true);
|
$stamp1 = microtime(true);
|
||||||
$this->logger->emergency($message, $context);
|
$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);
|
$stamp1 = microtime(true);
|
||||||
$this->logger->alert($message, $context);
|
$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);
|
$stamp1 = microtime(true);
|
||||||
$this->logger->critical($message, $context);
|
$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);
|
$stamp1 = microtime(true);
|
||||||
$this->logger->error($message, $context);
|
$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);
|
$stamp1 = microtime(true);
|
||||||
$this->logger->warning($message, $context);
|
$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);
|
$stamp1 = microtime(true);
|
||||||
$this->logger->notice($message, $context);
|
$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);
|
$stamp1 = microtime(true);
|
||||||
$this->logger->info($message, $context);
|
$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);
|
$stamp1 = microtime(true);
|
||||||
$this->logger->debug($message, $context);
|
$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);
|
$stamp1 = microtime(true);
|
||||||
$this->logger->log($level, $message, $context);
|
$this->logger->log($level, $message, $context);
|
||||||
$this->profiler->saveTimestamp($stamp1, 'file', System::callstack());
|
$this->profiler->saveTimestamp($stamp1, 'file');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace Friendica\Util;
|
||||||
|
|
||||||
use Friendica\Core\Config\Cache;
|
use Friendica\Core\Config\Cache;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
|
use Friendica\Core\System;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
@ -88,9 +89,9 @@ class Profiler implements ContainerInterface
|
||||||
* Saves a timestamp for a value - f.e. a call
|
* Saves a timestamp for a value - f.e. a call
|
||||||
* Necessary for profiling Friendica
|
* Necessary for profiling Friendica
|
||||||
*
|
*
|
||||||
* @param int $timestamp the Timestamp
|
* @param int $timestamp the Timestamp
|
||||||
* @param string $value A value to profile
|
* @param string $value A value to profile
|
||||||
* @param string $callstack The callstack of the current profiling data
|
* @param string $callstack A callstack string, generated if absent
|
||||||
*/
|
*/
|
||||||
public function saveTimestamp($timestamp, $value, $callstack = '')
|
public function saveTimestamp($timestamp, $value, $callstack = '')
|
||||||
{
|
{
|
||||||
|
@ -98,6 +99,8 @@ class Profiler implements ContainerInterface
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$callstack = $callstack ?: System::callstack(4, 1);
|
||||||
|
|
||||||
$duration = floatval(microtime(true) - $timestamp);
|
$duration = floatval(microtime(true) - $timestamp);
|
||||||
|
|
||||||
if (!isset($this->performance[$value])) {
|
if (!isset($this->performance[$value])) {
|
||||||
|
|
Loading…
Reference in a new issue