Introducing Profiler
This commit is contained in:
parent
12ff467a9b
commit
5e6e1a8025
24 changed files with 370 additions and 262 deletions
|
@ -219,7 +219,7 @@ class Addon extends BaseObject
|
|||
|
||||
$stamp1 = microtime(true);
|
||||
$f = file_get_contents("addon/$addon/$addon.php");
|
||||
$a->saveTimestamp($stamp1, "file");
|
||||
$a->getProfiler()->saveTimestamp($stamp1, "file");
|
||||
|
||||
$r = preg_match("|/\*.*\*/|msU", $f, $m);
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ class Cache extends \Friendica\BaseObject
|
|||
|
||||
$return = self::getDriver()->getAllKeys($prefix);
|
||||
|
||||
self::getApp()->saveTimestamp($time, 'cache');
|
||||
self::getApp()->getProfiler()->saveTimestamp($time, 'cache');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ class Cache extends \Friendica\BaseObject
|
|||
|
||||
$return = self::getDriver()->get($key);
|
||||
|
||||
self::getApp()->saveTimestamp($time, 'cache');
|
||||
self::getApp()->getProfiler()->saveTimestamp($time, 'cache');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ class Cache extends \Friendica\BaseObject
|
|||
|
||||
$return = self::getDriver()->set($key, $value, $duration);
|
||||
|
||||
self::getApp()->saveTimestamp($time, 'cache_write');
|
||||
self::getApp()->getProfiler()->saveTimestamp($time, 'cache_write');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ class Cache extends \Friendica\BaseObject
|
|||
|
||||
$return = self::getDriver()->delete($key);
|
||||
|
||||
self::getApp()->saveTimestamp($time, 'cache_write');
|
||||
self::getApp()->getProfiler()->saveTimestamp($time, 'cache_write');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ HELP;
|
|||
|
||||
$installer->resetChecks();
|
||||
|
||||
if (!$installer->checkDB($a->getConfig(), $db_host, $db_user, $db_pass, $db_data)) {
|
||||
if (!$installer->checkDB($a->getConfig(), $a->getProfiler(), $db_host, $db_user, $db_pass, $db_data)) {
|
||||
$errorMessage = $this->extractErrors($installer->getChecks());
|
||||
throw new RuntimeException($errorMessage);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use Friendica\Database\DBA;
|
|||
use Friendica\Database\DBStructure;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\Profiler;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
/**
|
||||
|
@ -583,6 +584,7 @@ class Installer
|
|||
* Checking the Database connection and if it is available for the current installation
|
||||
*
|
||||
* @param ConfigCache $configCache The configuration cache
|
||||
* @param Profiler $profiler The profiler of this app
|
||||
* @param string $dbhost Hostname/IP of the Friendica Database
|
||||
* @param string $dbuser Username of the Database connection credentials
|
||||
* @param string $dbpass Password of the Database connection credentials
|
||||
|
@ -591,9 +593,9 @@ class Installer
|
|||
* @return bool true if the check was successful, otherwise false
|
||||
* @throws Exception
|
||||
*/
|
||||
public function checkDB(ConfigCache $configCache, $dbhost, $dbuser, $dbpass, $dbdata)
|
||||
public function checkDB(ConfigCache $configCache, Profiler $profiler, $dbhost, $dbuser, $dbpass, $dbdata)
|
||||
{
|
||||
if (!DBA::connect($configCache, $dbhost, $dbuser, $dbpass, $dbdata)) {
|
||||
if (!DBA::connect($configCache, $profiler, $dbhost, $dbuser, $dbpass, $dbdata)) {
|
||||
$this->addCheck(L10n::t('Could not connect to database.'), false, true, '');
|
||||
|
||||
return false;
|
||||
|
|
|
@ -155,7 +155,7 @@ class Logger extends BaseObject
|
|||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->emergency($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
self::getApp()->GetProfiler()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,7 +179,7 @@ class Logger extends BaseObject
|
|||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->alert($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -202,7 +202,7 @@ class Logger extends BaseObject
|
|||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->critical($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -225,7 +225,7 @@ class Logger extends BaseObject
|
|||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->error($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -249,7 +249,7 @@ class Logger extends BaseObject
|
|||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->warning($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -270,7 +270,7 @@ class Logger extends BaseObject
|
|||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->notice($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -293,7 +293,7 @@ class Logger extends BaseObject
|
|||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->info($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -314,7 +314,7 @@ class Logger extends BaseObject
|
|||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->debug($message, $context);
|
||||
self::getApp()->saveTimestamp($stamp1, 'file');
|
||||
self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -334,7 +334,7 @@ class Logger extends BaseObject
|
|||
|
||||
$stamp1 = microtime(true);
|
||||
self::$logger->log($level, $msg);
|
||||
self::getApp()->saveTimestamp($stamp1, "file");
|
||||
self::getApp()->getProfiler()->saveTimestamp($stamp1, "file");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -355,6 +355,6 @@ class Logger extends BaseObject
|
|||
|
||||
$stamp1 = microtime(true);
|
||||
self::$devLogger->log($level, $msg);
|
||||
self::getApp()->saveTimestamp($stamp1, "file");
|
||||
self::getApp()->getProfiler()->saveTimestamp($stamp1, "file");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ class Renderer extends BaseObject
|
|||
exit();
|
||||
}
|
||||
|
||||
$a->saveTimestamp($stamp1, "rendering");
|
||||
$a->getProfiler()->saveTimestamp($stamp1, "rendering");
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ class Renderer extends BaseObject
|
|||
exit();
|
||||
}
|
||||
|
||||
$a->saveTimestamp($stamp1, "file");
|
||||
$a->getProfiler()->saveTimestamp($stamp1, "file");
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class Theme
|
|||
$a = \get_app();
|
||||
$stamp1 = microtime(true);
|
||||
$theme_file = file_get_contents("view/theme/$theme/theme.php");
|
||||
$a->saveTimestamp($stamp1, "file");
|
||||
$a->getProfiler()->saveTimestamp($stamp1, "file");
|
||||
|
||||
$result = preg_match("|/\*.*\*/|msU", $theme_file, $matches);
|
||||
|
||||
|
|
|
@ -380,20 +380,7 @@ class Worker
|
|||
|
||||
// We use the callstack here to analyze the performance of executed worker entries.
|
||||
// For this reason the variables have to be initialized.
|
||||
if (Config::get("system", "profiler")) {
|
||||
$a->performance["start"] = microtime(true);
|
||||
$a->performance["database"] = 0;
|
||||
$a->performance["database_write"] = 0;
|
||||
$a->performance["cache"] = 0;
|
||||
$a->performance["cache_write"] = 0;
|
||||
$a->performance["network"] = 0;
|
||||
$a->performance["file"] = 0;
|
||||
$a->performance["rendering"] = 0;
|
||||
$a->performance["parser"] = 0;
|
||||
$a->performance["marktime"] = 0;
|
||||
$a->performance["markstart"] = microtime(true);
|
||||
$a->callstack = [];
|
||||
}
|
||||
$a->getProfiler()->reset();
|
||||
|
||||
// For better logging create a new process id for every worker call
|
||||
// But preserve the old one for the worker
|
||||
|
@ -452,76 +439,7 @@ class Worker
|
|||
|
||||
Logger::log("Process ".$mypid." - Prio ".$queue["priority"]." - ID ".$queue["id"].": ".$funcname." - done in ".number_format($duration, 4)." seconds. Process PID: ".$new_process_id);
|
||||
|
||||
// Write down the performance values into the log
|
||||
if (Config::get("system", "profiler")) {
|
||||
$duration = microtime(true)-$a->performance["start"];
|
||||
|
||||
$o = '';
|
||||
if (Config::get("rendertime", "callstack")) {
|
||||
if (isset($a->callstack["database"])) {
|
||||
$o .= "\nDatabase Read:\n";
|
||||
foreach ($a->callstack["database"] as $func => $time) {
|
||||
$time = round($time, 3);
|
||||
if ($time > 0) {
|
||||
$o .= $func.": ".$time."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($a->callstack["database_write"])) {
|
||||
$o .= "\nDatabase Write:\n";
|
||||
foreach ($a->callstack["database_write"] as $func => $time) {
|
||||
$time = round($time, 3);
|
||||
if ($time > 0) {
|
||||
$o .= $func.": ".$time."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($a->callstack["dache"])) {
|
||||
$o .= "\nCache Read:\n";
|
||||
foreach ($a->callstack["dache"] as $func => $time) {
|
||||
$time = round($time, 3);
|
||||
if ($time > 0) {
|
||||
$o .= $func.": ".$time."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($a->callstack["dache_write"])) {
|
||||
$o .= "\nCache Write:\n";
|
||||
foreach ($a->callstack["dache_write"] as $func => $time) {
|
||||
$time = round($time, 3);
|
||||
if ($time > 0) {
|
||||
$o .= $func.": ".$time."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($a->callstack["network"])) {
|
||||
$o .= "\nNetwork:\n";
|
||||
foreach ($a->callstack["network"] as $func => $time) {
|
||||
$time = round($time, 3);
|
||||
if ($time > 0) {
|
||||
$o .= $func.": ".$time."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Logger::log(
|
||||
"ID ".$queue["id"].": ".$funcname.": ".sprintf(
|
||||
"DB: %s/%s, Cache: %s/%s, Net: %s, I/O: %s, Other: %s, Total: %s".$o,
|
||||
number_format($a->performance["database"] - $a->performance["database_write"], 2),
|
||||
number_format($a->performance["database_write"], 2),
|
||||
number_format($a->performance["cache"], 2),
|
||||
number_format($a->performance["cache_write"], 2),
|
||||
number_format($a->performance["network"], 2),
|
||||
number_format($a->performance["file"], 2),
|
||||
number_format($duration - ($a->performance["database"]
|
||||
+ $a->performance["cache"] + $a->performance["cache_write"]
|
||||
+ $a->performance["network"] + $a->performance["file"]), 2),
|
||||
number_format($duration, 2)
|
||||
),
|
||||
Logger::DEBUG
|
||||
);
|
||||
}
|
||||
$a->getProfiler()->saveLog("ID " . $queue["id"] . ": " . $funcname);
|
||||
|
||||
$cooldown = Config::get("system", "worker_cooldown", 0);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue