Browse Source

Introducing Profiler

tags/2019.03^2
Philipp Holzer 5 months ago
parent
commit
5e6e1a8025
No account linked to committer's email address

+ 2
- 1
bin/auth_ejabberd.php View File

@@ -58,8 +58,9 @@ $basedir = BasePath::create(dirname(__DIR__), $_SERVER);
58 58
 $configLoader = new Config\ConfigCacheLoader($basedir);
59 59
 $config = Factory\ConfigFactory::createCache($configLoader);
60 60
 $logger = Factory\LoggerFactory::create('auth_ejabberd', $config);
61
+$profiler = Factory\ProfilerFactory::create($config);
61 62
 
62
-$a = new App($config, $logger);
63
+$a = new App($config, $logger, $profiler);
63 64
 
64 65
 if ($a->getMode()->isNormal()) {
65 66
 	$oAuth = new ExAuth();

+ 2
- 1
bin/console.php View File

@@ -11,8 +11,9 @@ $basedir = BasePath::create(dirname(__DIR__), $_SERVER);
11 11
 $configLoader = new Config\ConfigCacheLoader($basedir);
12 12
 $config = Factory\ConfigFactory::createCache($configLoader);
13 13
 $logger = Factory\LoggerFactory::create('console', $config);
14
+$profiler = Factory\ProfilerFactory::create($config);
14 15
 
15
-$a = new Friendica\App($config, $logger);
16
+$a = new Friendica\App($config, $logger, $profiler);
16 17
 \Friendica\BaseObject::setApp($a);
17 18
 
18 19
 (new Friendica\Core\Console($argv))->execute();

+ 2
- 1
bin/daemon.php View File

@@ -37,8 +37,9 @@ $basedir = BasePath::create(dirname(__DIR__), $_SERVER);
37 37
 $configLoader = new Config\ConfigCacheLoader($basedir);
38 38
 $config = Factory\ConfigFactory::createCache($configLoader);
39 39
 $logger = Factory\LoggerFactory::create('daemon', $config);
40
+$profiler = Factory\ProfilerFactory::create($config);
40 41
 
41
-$a = new App($config, $logger);
42
+$a = new App($config, $logger, $profiler);
42 43
 
43 44
 if ($a->getMode()->isInstall()) {
44 45
 	die("Friendica isn't properly installed yet.\n");

+ 2
- 1
bin/worker.php View File

@@ -35,8 +35,9 @@ $basedir = BasePath::create(dirname(__DIR__), $_SERVER);
35 35
 $configLoader = new Config\ConfigCacheLoader($basedir);
36 36
 $config = Factory\ConfigFactory::createCache($configLoader);
37 37
 $logger = Factory\LoggerFactory::create('worker', $config);
38
+$profiler = Factory\ProfilerFactory::create($config);
38 39
 
39
-$a = new App($config, $logger);
40
+$a = new App($config, $logger, $profiler);
40 41
 
41 42
 // Check the database structure and possibly fixes it
42 43
 Update::check($a->getBasePath(), true);

+ 1
- 63
include/api.php View File

@@ -326,69 +326,7 @@ function api_call(App $a)
326 326
 
327 327
 				Logger::info(API_LOG_PREFIX . 'username {username}', ['module' => 'api', 'action' => 'call', 'username' => $a->user['username'], 'duration' => round($duration, 2)]);
328 328
 
329
-				if (Config::get("system", "profiler")) {
330
-					$duration = microtime(true)-$a->performance["start"];
331
-
332
-					/// @TODO round() really everywhere?
333
-					Logger::debug(
334
-						API_LOG_PREFIX . 'performance',
335
-						[
336
-							'module' => 'api',
337
-							'action' => 'call',
338
-							'database_read' => round($a->performance["database"] - $a->performance["database_write"], 3),
339
-							'database_write' => round($a->performance["database_write"], 3),
340
-							'cache_read' => round($a->performance["cache"], 3),
341
-							'cache_write' => round($a->performance["cache_write"], 3),
342
-							'network_io' => round($a->performance["network"], 2),
343
-							'file_io' => round($a->performance["file"], 2),
344
-							'other_io' => round($duration - ($a->performance["database"]
345
-									+ $a->performance["cache"] + $a->performance["cache_write"]
346
-									+ $a->performance["network"] + $a->performance["file"]), 2),
347
-							'total' => round($duration, 2)
348
-						]
349
-					);
350
-
351
-					if (Config::get("rendertime", "callstack")) {
352
-						$o = "Database Read:\n";
353
-						foreach ($a->callstack["database"] as $func => $time) {
354
-							$time = round($time, 3);
355
-							if ($time > 0) {
356
-								$o .= $func . ": " . $time . "\n";
357
-							}
358
-						}
359
-						$o .= "\nDatabase Write:\n";
360
-						foreach ($a->callstack["database_write"] as $func => $time) {
361
-							$time = round($time, 3);
362
-							if ($time > 0) {
363
-								$o .= $func . ": " . $time . "\n";
364
-							}
365
-						}
366
-
367
-						$o = "Cache Read:\n";
368
-						foreach ($a->callstack["cache"] as $func => $time) {
369
-							$time = round($time, 3);
370
-							if ($time > 0) {
371
-								$o .= $func . ": " . $time . "\n";
372
-							}
373
-						}
374
-						$o .= "\nCache Write:\n";
375
-						foreach ($a->callstack["cache_write"] as $func => $time) {
376
-							$time = round($time, 3);
377
-							if ($time > 0) {
378
-								$o .= $func . ": " . $time . "\n";
379
-							}
380
-						}
381
-
382
-						$o .= "\nNetwork:\n";
383
-						foreach ($a->callstack["network"] as $func => $time) {
384
-							$time = round($time, 3);
385
-							if ($time > 0) {
386
-								$o .= $func . ": " . $time . "\n";
387
-							}
388
-						}
389
-						Logger::debug(API_LOG_PREFIX . $o, ['module' => 'api', 'action' => 'call']);
390
-					}
391
-				}
329
+				$a->getProfiler()->saveLog(API_LOG_PREFIX . 'performance');
392 330
 
393 331
 				if (false === $return) {
394 332
 					/*

+ 2
- 1
index.php View File

@@ -19,9 +19,10 @@ $basedir = BasePath::create(__DIR__, $_SERVER);
19 19
 $configLoader = new Config\ConfigCacheLoader($basedir);
20 20
 $config = Factory\ConfigFactory::createCache($configLoader);
21 21
 $logger = Factory\LoggerFactory::create('index', $config);
22
+$profiler = Factory\ProfilerFactory::create($config);
22 23
 
23 24
 // We assume that the index.php is called by a frontend process
24 25
 // The value is set to "true" by default in App
25
-$a = new App($config, $logger, false);
26
+$a = new App($config, $logger, $profiler, false);
26 27
 
27 28
 $a->runFrontend();

+ 23
- 61
src/App.php View File

@@ -13,6 +13,7 @@ use Friendica\Core\Config\ConfigCacheLoader;
13 13
 use Friendica\Database\DBA;
14 14
 use Friendica\Factory\ConfigFactory;
15 15
 use Friendica\Network\HTTPException\InternalServerErrorException;
16
+use Friendica\Util\Profiler;
16 17
 use Psr\Log\LoggerInterface;
17 18
 
18 19
 /**
@@ -53,8 +54,6 @@ class App
53 54
 	public $identities;
54 55
 	public $is_mobile = false;
55 56
 	public $is_tablet = false;
56
-	public $performance = [];
57
-	public $callstack = [];
58 57
 	public $theme_info = [];
59 58
 	public $category;
60 59
 	// Allow themes to control internal parameters
@@ -119,6 +118,11 @@ class App
119 118
 	 */
120 119
 	private $config;
121 120
 
121
+	/**
122
+	 * @var Profiler The profiler of this app
123
+	 */
124
+	private $profiler;
125
+
122 126
 	/**
123 127
 	 * Returns the current config cache of this node
124 128
 	 *
@@ -139,6 +143,16 @@ class App
139 143
 		return $this->basePath;
140 144
 	}
141 145
 
146
+	/**
147
+	 * The profiler of this app
148
+	 *
149
+	 * @return Profiler
150
+	 */
151
+	public function getProfiler()
152
+	{
153
+		return $this->profiler;
154
+	}
155
+
142 156
 	/**
143 157
 	 * Register a stylesheet file path to be included in the <head> tag of every page.
144 158
 	 * Inclusion is done in App->initHead().
@@ -183,14 +197,16 @@ class App
183 197
 	 *
184 198
 	 * @param ConfigCache      $config    The Cached Config
185 199
 	 * @param LoggerInterface  $logger    Logger of this application
200
+	 * @param Profiler         $profiler  The profiler of this application
186 201
 	 * @param bool             $isBackend Whether it is used for backend or frontend (Default true=backend)
187 202
 	 *
188 203
 	 * @throws Exception if the Basepath is not usable
189 204
 	 */
190
-	public function __construct(ConfigCache $config, LoggerInterface $logger, $isBackend = true)
205
+	public function __construct(ConfigCache $config, LoggerInterface $logger, Profiler $profiler, $isBackend = true)
191 206
 	{
192 207
 		$this->config   = $config;
193 208
 		$this->logger   = $logger;
209
+		$this->profiler = $profiler;
194 210
 		$this->basePath = $this->config->get('system', 'basepath');
195 211
 
196 212
 		if (!Core\System::isDirectoryUsable($this->basePath, false)) {
@@ -203,26 +219,7 @@ class App
203 219
 		$this->checkBackend($isBackend);
204 220
 		$this->checkFriendicaApp();
205 221
 
206
-		$this->performance['start'] = microtime(true);
207
-		$this->performance['database'] = 0;
208
-		$this->performance['database_write'] = 0;
209
-		$this->performance['cache'] = 0;
210
-		$this->performance['cache_write'] = 0;
211
-		$this->performance['network'] = 0;
212
-		$this->performance['file'] = 0;
213
-		$this->performance['rendering'] = 0;
214
-		$this->performance['parser'] = 0;
215
-		$this->performance['marktime'] = 0;
216
-		$this->performance['markstart'] = microtime(true);
217
-
218
-		$this->callstack['database'] = [];
219
-		$this->callstack['database_write'] = [];
220
-		$this->callstack['cache'] = [];
221
-		$this->callstack['cache_write'] = [];
222
-		$this->callstack['network'] = [];
223
-		$this->callstack['file'] = [];
224
-		$this->callstack['rendering'] = [];
225
-		$this->callstack['parser'] = [];
222
+		$this->profiler->reset();
226 223
 
227 224
 		$this->mode = new App\Mode($this->basePath);
228 225
 
@@ -489,14 +486,14 @@ class App
489 486
 
490 487
 		$stamp1 = microtime(true);
491 488
 
492
-		if (DBA::connect($this->config, $db_host, $db_user, $db_pass, $db_data, $charset)) {
489
+		if (DBA::connect($this->config, $this->profiler, $db_host, $db_user, $db_pass, $db_data, $charset)) {
493 490
 			// Loads DB_UPDATE_VERSION constant
494 491
 			Database\DBStructure::definition($this->basePath, false);
495 492
 		}
496 493
 
497 494
 		unset($db_host, $db_user, $db_pass, $db_data, $charset);
498 495
 
499
-		$this->saveTimestamp($stamp1, 'network');
496
+		$this->profiler->saveTimestamp($stamp1, 'network');
500 497
 	}
501 498
 
502 499
 	public function getScheme()
@@ -742,41 +739,6 @@ class App
742 739
 		}
743 740
 	}
744 741
 
745
-	/**
746
-	 * Saves a timestamp for a value - f.e. a call
747
-	 * Necessary for profiling Friendica
748
-	 *
749
-	 * @param int $timestamp the Timestamp
750
-	 * @param string $value A value to profile
751
-	 */
752
-	public function saveTimestamp($timestamp, $value)
753
-	{
754
-		$profiler = $this->config->get('system', 'profiler');
755
-
756
-		if (!isset($profiler) || !$profiler) {
757
-			return;
758
-		}
759
-
760
-		$duration = (float) (microtime(true) - $timestamp);
761
-
762
-		if (!isset($this->performance[$value])) {
763
-			// Prevent ugly E_NOTICE
764
-			$this->performance[$value] = 0;
765
-		}
766
-
767
-		$this->performance[$value] += (float) $duration;
768
-		$this->performance['marktime'] += (float) $duration;
769
-
770
-		$callstack = Core\System::callstack();
771
-
772
-		if (!isset($this->callstack[$value][$callstack])) {
773
-			// Prevent ugly E_NOTICE
774
-			$this->callstack[$value][$callstack] = 0;
775
-		}
776
-
777
-		$this->callstack[$value][$callstack] += (float) $duration;
778
-	}
779
-
780 742
 	/**
781 743
 	 * Returns the current UserAgent as a String
782 744
 	 *
@@ -1227,7 +1189,7 @@ class App
1227 1189
 		if (!$this->isBackend()) {
1228 1190
 			$stamp1 = microtime(true);
1229 1191
 			session_start();
1230
-			$this->saveTimestamp($stamp1, 'parser');
1192
+			$this->profiler->saveTimestamp($stamp1, 'parser');
1231 1193
 			Core\L10n::setSessionVariable();
1232 1194
 			Core\L10n::setLangFromSession();
1233 1195
 		} else {

+ 3
- 3
src/Content/Text/BBCode.php View File

@@ -1027,7 +1027,7 @@ class BBCode extends BaseObject
1027 1027
 			@curl_exec($ch);
1028 1028
 			$curl_info = @curl_getinfo($ch);
1029 1029
 
1030
-			$a->saveTimestamp($stamp1, "network");
1030
+			$a->getProfiler()->saveTimestamp($stamp1, "network");
1031 1031
 
1032 1032
 			if (substr($curl_info["content_type"], 0, 6) == "image/") {
1033 1033
 				$text = "[url=" . $match[1] . "]" . $match[1] . "[/url]";
@@ -1086,7 +1086,7 @@ class BBCode extends BaseObject
1086 1086
 			@curl_exec($ch);
1087 1087
 			$curl_info = @curl_getinfo($ch);
1088 1088
 
1089
-			$a->saveTimestamp($stamp1, "network");
1089
+			$a->getProfiler()->saveTimestamp($stamp1, "network");
1090 1090
 
1091 1091
 			// if its a link to a picture then embed this picture
1092 1092
 			if (substr($curl_info["content_type"], 0, 6) == "image/") {
@@ -1915,7 +1915,7 @@ class BBCode extends BaseObject
1915 1915
 		// unmask the special chars back to HTML
1916 1916
 		$text = str_replace(['&\_lt\_;', '&\_gt\_;', '&\_amp\_;'], ['&lt;', '&gt;', '&amp;'], $text);
1917 1917
 
1918
-		$a->saveTimestamp($stamp1, "parser");
1918
+		$a->getProfiler()->saveTimestamp($stamp1, "parser");
1919 1919
 
1920 1920
 		// Libertree has a problem with escaped hashtags.
1921 1921
 		$text = str_replace(['\#'], ['#'], $text);

+ 1
- 1
src/Content/Text/Markdown.php View File

@@ -36,7 +36,7 @@ class Markdown extends BaseObject
36 36
 		$html = $MarkdownParser->transform($text);
37 37
 		$html = preg_replace('/<a(.*?)href="#/is', '<a$1href="' . ltrim($_SERVER['REQUEST_URI'], '/') . '#', $html);
38 38
 
39
-		self::getApp()->saveTimestamp($stamp1, "parser");
39
+		self::getApp()->getProfiler()->saveTimestamp($stamp1, "parser");
40 40
 
41 41
 		return $html;
42 42
 	}

+ 1
- 1
src/Core/Addon.php View File

@@ -219,7 +219,7 @@ class Addon extends BaseObject
219 219
 
220 220
 		$stamp1 = microtime(true);
221 221
 		$f = file_get_contents("addon/$addon/$addon.php");
222
-		$a->saveTimestamp($stamp1, "file");
222
+		$a->getProfiler()->saveTimestamp($stamp1, "file");
223 223
 
224 224
 		$r = preg_match("|/\*.*\*/|msU", $f, $m);
225 225
 

+ 4
- 4
src/Core/Cache.php View File

@@ -63,7 +63,7 @@ class Cache extends \Friendica\BaseObject
63 63
 
64 64
 		$return = self::getDriver()->getAllKeys($prefix);
65 65
 
66
-		self::getApp()->saveTimestamp($time, 'cache');
66
+		self::getApp()->getProfiler()->saveTimestamp($time, 'cache');
67 67
 
68 68
 		return $return;
69 69
 	}
@@ -82,7 +82,7 @@ class Cache extends \Friendica\BaseObject
82 82
 
83 83
 		$return = self::getDriver()->get($key);
84 84
 
85
-		self::getApp()->saveTimestamp($time, 'cache');
85
+		self::getApp()->getProfiler()->saveTimestamp($time, 'cache');
86 86
 
87 87
 		return $return;
88 88
 	}
@@ -105,7 +105,7 @@ class Cache extends \Friendica\BaseObject
105 105
 
106 106
 		$return = self::getDriver()->set($key, $value, $duration);
107 107
 
108
-		self::getApp()->saveTimestamp($time, 'cache_write');
108
+		self::getApp()->getProfiler()->saveTimestamp($time, 'cache_write');
109 109
 
110 110
 		return $return;
111 111
 	}
@@ -124,7 +124,7 @@ class Cache extends \Friendica\BaseObject
124 124
 
125 125
 		$return = self::getDriver()->delete($key);
126 126
 
127
-		self::getApp()->saveTimestamp($time, 'cache_write');
127
+		self::getApp()->getProfiler()->saveTimestamp($time, 'cache_write');
128 128
 
129 129
 		return $return;
130 130
 	}

+ 1
- 1
src/Core/Console/AutomaticInstallation.php View File

@@ -146,7 +146,7 @@ HELP;
146 146
 
147 147
 		$installer->resetChecks();
148 148
 
149
-		if (!$installer->checkDB($a->getConfig(), $db_host, $db_user, $db_pass, $db_data)) {
149
+		if (!$installer->checkDB($a->getConfig(), $a->getProfiler(), $db_host, $db_user, $db_pass, $db_data)) {
150 150
 			$errorMessage = $this->extractErrors($installer->getChecks());
151 151
 			throw new RuntimeException($errorMessage);
152 152
 		}

+ 4
- 2
src/Core/Installer.php View File

@@ -11,6 +11,7 @@ use Friendica\Database\DBA;
11 11
 use Friendica\Database\DBStructure;
12 12
 use Friendica\Object\Image;
13 13
 use Friendica\Util\Network;
14
+use Friendica\Util\Profiler;
14 15
 use Friendica\Util\Strings;
15 16
 
16 17
 /**
@@ -583,6 +584,7 @@ class Installer
583 584
 	 * Checking the Database connection and if it is available for the current installation
584 585
 	 *
585 586
 	 * @param ConfigCache $configCache The configuration cache
587
+	 * @param Profiler    $profiler    The profiler of this app
586 588
 	 * @param string $dbhost           Hostname/IP of the Friendica Database
587 589
 	 * @param string $dbuser           Username of the Database connection credentials
588 590
 	 * @param string $dbpass           Password of the Database connection credentials
@@ -591,9 +593,9 @@ class Installer
591 593
 	 * @return bool true if the check was successful, otherwise false
592 594
 	 * @throws Exception
593 595
 	 */
594
-	public function checkDB(ConfigCache $configCache, $dbhost, $dbuser, $dbpass, $dbdata)
596
+	public function checkDB(ConfigCache $configCache, Profiler $profiler, $dbhost, $dbuser, $dbpass, $dbdata)
595 597
 	{
596
-		if (!DBA::connect($configCache, $dbhost, $dbuser, $dbpass, $dbdata)) {
598
+		if (!DBA::connect($configCache, $profiler, $dbhost, $dbuser, $dbpass, $dbdata)) {
597 599
 			$this->addCheck(L10n::t('Could not connect to database.'), false, true, '');
598 600
 
599 601
 			return false;

+ 10
- 10
src/Core/Logger.php View File

@@ -155,7 +155,7 @@ class Logger extends BaseObject
155 155
 
156 156
 		$stamp1 = microtime(true);
157 157
 		self::$logger->emergency($message, $context);
158
-		self::getApp()->saveTimestamp($stamp1, 'file');
158
+		self::getApp()->GetProfiler()->saveTimestamp($stamp1, 'file');
159 159
 	}
160 160
 
161 161
 	/**
@@ -179,7 +179,7 @@ class Logger extends BaseObject
179 179
 
180 180
 		$stamp1 = microtime(true);
181 181
 		self::$logger->alert($message, $context);
182
-		self::getApp()->saveTimestamp($stamp1, 'file');
182
+		self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
183 183
 	}
184 184
 
185 185
 	/**
@@ -202,7 +202,7 @@ class Logger extends BaseObject
202 202
 
203 203
 		$stamp1 = microtime(true);
204 204
 		self::$logger->critical($message, $context);
205
-		self::getApp()->saveTimestamp($stamp1, 'file');
205
+		self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
206 206
 	}
207 207
 
208 208
 	/**
@@ -225,7 +225,7 @@ class Logger extends BaseObject
225 225
 
226 226
 		$stamp1 = microtime(true);
227 227
 		self::$logger->error($message, $context);
228
-		self::getApp()->saveTimestamp($stamp1, 'file');
228
+		self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
229 229
 	}
230 230
 
231 231
 	/**
@@ -249,7 +249,7 @@ class Logger extends BaseObject
249 249
 
250 250
 		$stamp1 = microtime(true);
251 251
 		self::$logger->warning($message, $context);
252
-		self::getApp()->saveTimestamp($stamp1, 'file');
252
+		self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
253 253
 	}
254 254
 
255 255
 	/**
@@ -270,7 +270,7 @@ class Logger extends BaseObject
270 270
 
271 271
 		$stamp1 = microtime(true);
272 272
 		self::$logger->notice($message, $context);
273
-		self::getApp()->saveTimestamp($stamp1, 'file');
273
+		self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
274 274
 	}
275 275
 
276 276
 	/**
@@ -293,7 +293,7 @@ class Logger extends BaseObject
293 293
 
294 294
 		$stamp1 = microtime(true);
295 295
 		self::$logger->info($message, $context);
296
-		self::getApp()->saveTimestamp($stamp1, 'file');
296
+		self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
297 297
 	}
298 298
 
299 299
 	/**
@@ -314,7 +314,7 @@ class Logger extends BaseObject
314 314
 
315 315
 		$stamp1 = microtime(true);
316 316
 		self::$logger->debug($message, $context);
317
-		self::getApp()->saveTimestamp($stamp1, 'file');
317
+		self::getApp()->getProfiler()->saveTimestamp($stamp1, 'file');
318 318
 	}
319 319
 
320 320
     /**
@@ -334,7 +334,7 @@ class Logger extends BaseObject
334 334
 
335 335
         $stamp1 = microtime(true);
336 336
 		self::$logger->log($level, $msg);
337
-        self::getApp()->saveTimestamp($stamp1, "file");
337
+		self::getApp()->getProfiler()->saveTimestamp($stamp1, "file");
338 338
     }
339 339
 
340 340
 	/**
@@ -355,6 +355,6 @@ class Logger extends BaseObject
355 355
 
356 356
         $stamp1 = microtime(true);
357 357
         self::$devLogger->log($level, $msg);
358
-        self::getApp()->saveTimestamp($stamp1, "file");
358
+		self::getApp()->getProfiler()->saveTimestamp($stamp1, "file");
359 359
     }
360 360
 }

+ 2
- 2
src/Core/Renderer.php View File

@@ -74,7 +74,7 @@ class Renderer extends BaseObject
74 74
             exit();
75 75
         }
76 76
 
77
-        $a->saveTimestamp($stamp1, "rendering");
77
+		$a->getProfiler()->saveTimestamp($stamp1, "rendering");
78 78
 
79 79
         return $output;
80 80
     }
@@ -101,7 +101,7 @@ class Renderer extends BaseObject
101 101
             exit();
102 102
         }
103 103
 
104
-        $a->saveTimestamp($stamp1, "file");
104
+        $a->getProfiler()->saveTimestamp($stamp1, "file");
105 105
 
106 106
         return $template;
107 107
     }

+ 1
- 1
src/Core/Theme.php View File

@@ -51,7 +51,7 @@ class Theme
51 51
 		$a = \get_app();
52 52
 		$stamp1 = microtime(true);
53 53
 		$theme_file = file_get_contents("view/theme/$theme/theme.php");
54
-		$a->saveTimestamp($stamp1, "file");
54
+		$a->getProfiler()->saveTimestamp($stamp1, "file");
55 55
 
56 56
 		$result = preg_match("|/\*.*\*/|msU", $theme_file, $matches);
57 57
 

+ 2
- 84
src/Core/Worker.php View File

@@ -380,20 +380,7 @@ class Worker
380 380
 
381 381
 		// We use the callstack here to analyze the performance of executed worker entries.
382 382
 		// For this reason the variables have to be initialized.
383
-		if (Config::get("system", "profiler")) {
384
-			$a->performance["start"] = microtime(true);
385
-			$a->performance["database"] = 0;
386
-			$a->performance["database_write"] = 0;
387
-			$a->performance["cache"] = 0;
388
-			$a->performance["cache_write"] = 0;
389
-			$a->performance["network"] = 0;
390
-			$a->performance["file"] = 0;
391
-			$a->performance["rendering"] = 0;
392
-			$a->performance["parser"] = 0;
393
-			$a->performance["marktime"] = 0;
394
-			$a->performance["markstart"] = microtime(true);
395
-			$a->callstack = [];
396
-		}
383
+		$a->getProfiler()->reset();
397 384
 
398 385
 		// For better logging create a new process id for every worker call
399 386
 		// But preserve the old one for the worker
@@ -452,76 +439,7 @@ class Worker
452 439
 
453 440
 		Logger::log("Process ".$mypid." - Prio ".$queue["priority"]." - ID ".$queue["id"].": ".$funcname." - done in ".number_format($duration, 4)." seconds. Process PID: ".$new_process_id);
454 441
 
455
-		// Write down the performance values into the log
456
-		if (Config::get("system", "profiler")) {
457
-			$duration = microtime(true)-$a->performance["start"];
458
-
459
-			$o = '';
460
-			if (Config::get("rendertime", "callstack")) {
461
-				if (isset($a->callstack["database"])) {
462
-					$o .= "\nDatabase Read:\n";
463
-					foreach ($a->callstack["database"] as $func => $time) {
464
-						$time = round($time, 3);
465
-						if ($time > 0) {
466
-							$o .= $func.": ".$time."\n";
467
-						}
468
-					}
469
-				}
470
-				if (isset($a->callstack["database_write"])) {
471
-					$o .= "\nDatabase Write:\n";
472
-					foreach ($a->callstack["database_write"] as $func => $time) {
473
-						$time = round($time, 3);
474
-						if ($time > 0) {
475
-							$o .= $func.": ".$time."\n";
476
-						}
477
-					}
478
-				}
479
-				if (isset($a->callstack["dache"])) {
480
-					$o .= "\nCache Read:\n";
481
-					foreach ($a->callstack["dache"] as $func => $time) {
482
-						$time = round($time, 3);
483
-						if ($time > 0) {
484
-							$o .= $func.": ".$time."\n";
485
-						}
486
-					}
487
-				}
488
-				if (isset($a->callstack["dache_write"])) {
489
-					$o .= "\nCache Write:\n";
490
-					foreach ($a->callstack["dache_write"] as $func => $time) {
491
-						$time = round($time, 3);
492
-						if ($time > 0) {
493
-							$o .= $func.": ".$time."\n";
494
-						}
495
-					}
496
-				}
497
-				if (isset($a->callstack["network"])) {
498
-					$o .= "\nNetwork:\n";
499
-					foreach ($a->callstack["network"] as $func => $time) {
500
-						$time = round($time, 3);
501
-						if ($time > 0) {
502
-							$o .= $func.": ".$time."\n";
503
-						}
504
-					}
505
-				}
506
-			}
507
-
508
-			Logger::log(
509
-				"ID ".$queue["id"].": ".$funcname.": ".sprintf(
510
-					"DB: %s/%s, Cache: %s/%s, Net: %s, I/O: %s, Other: %s, Total: %s".$o,
511
-					number_format($a->performance["database"] - $a->performance["database_write"], 2),
512
-					number_format($a->performance["database_write"], 2),
513
-					number_format($a->performance["cache"], 2),
514
-					number_format($a->performance["cache_write"], 2),
515
-					number_format($a->performance["network"], 2),
516
-					number_format($a->performance["file"], 2),
517
-					number_format($duration - ($a->performance["database"]
518
-						+ $a->performance["cache"] + $a->performance["cache_write"]
519
-						+ $a->performance["network"] + $a->performance["file"]), 2),
520
-					number_format($duration, 2)
521
-				),
522
-				Logger::DEBUG
523
-			);
524
-		}
442
+		$a->getProfiler()->saveLog("ID " . $queue["id"] . ": " . $funcname);
525 443
 
526 444
 		$cooldown = Config::get("system", "worker_cooldown", 0);
527 445
 

+ 12
- 10
src/Database/DBA.php View File

@@ -6,6 +6,7 @@ use Friendica\Core\Config\IConfigCache;
6 6
 use Friendica\Core\Logger;
7 7
 use Friendica\Core\System;
8 8
 use Friendica\Util\DateTimeFormat;
9
+use Friendica\Util\Profiler;
9 10
 use mysqli;
10 11
 use mysqli_result;
11 12
 use mysqli_stmt;
@@ -35,6 +36,10 @@ class DBA
35 36
 	 * @var IConfigCache
36 37
 	 */
37 38
 	private static $configCache;
39
+	/**
40
+	 * @var Profiler
41
+	 */
42
+	private static $profiler;
38 43
 	private static $server_info = '';
39 44
 	private static $connection;
40 45
 	private static $driver;
@@ -50,7 +55,7 @@ class DBA
50 55
 	private static $db_name = '';
51 56
 	private static $db_charset = '';
52 57
 
53
-	public static function connect($configCache, $serveraddr, $user, $pass, $db, $charset = null)
58
+	public static function connect(IConfigCache $configCache, Profiler $profiler, $serveraddr, $user, $pass, $db, $charset = null)
54 59
 	{
55 60
 		if (!is_null(self::$connection) && self::connected()) {
56 61
 			return true;
@@ -58,6 +63,7 @@ class DBA
58 63
 
59 64
 		// We are storing these values for being able to perform a reconnect
60 65
 		self::$configCache = $configCache;
66
+		self::$profiler = $profiler;
61 67
 		self::$db_serveraddr = $serveraddr;
62 68
 		self::$db_user = $user;
63 69
 		self::$db_pass = $pass;
@@ -158,7 +164,7 @@ class DBA
158 164
 	public static function reconnect() {
159 165
 		self::disconnect();
160 166
 
161
-		$ret = self::connect(self::$configCache, self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name, self::$db_charset);
167
+		$ret = self::connect(self::$configCache, self::$profiler, self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name, self::$db_charset);
162 168
 		return $ret;
163 169
 	}
164 170
 
@@ -392,7 +398,6 @@ class DBA
392 398
 	 * @throws \Exception
393 399
 	 */
394 400
 	public static function p($sql) {
395
-		$a = \get_app();
396 401
 
397 402
 		$stamp1 = microtime(true);
398 403
 
@@ -582,7 +587,7 @@ class DBA
582 587
 			self::$errorno = $errorno;
583 588
 		}
584 589
 
585
-		$a->saveTimestamp($stamp1, 'database');
590
+		self::$profiler->saveTimestamp($stamp1, 'database');
586 591
 
587 592
 		if (self::$configCache->get('system', 'db_log')) {
588 593
 			$stamp2 = microtime(true);
@@ -611,7 +616,6 @@ class DBA
611 616
 	 * @throws \Exception
612 617
 	 */
613 618
 	public static function e($sql) {
614
-		$a = \get_app();
615 619
 
616 620
 		$stamp = microtime(true);
617 621
 
@@ -654,7 +658,7 @@ class DBA
654 658
 			self::$errorno = $errorno;
655 659
 		}
656 660
 
657
-		$a->saveTimestamp($stamp, "database_write");
661
+		self::$profiler->saveTimestamp($stamp, "database_write");
658 662
 
659 663
 		return $retval;
660 664
 	}
@@ -777,7 +781,6 @@ class DBA
777 781
 	 * @return array current row
778 782
 	 */
779 783
 	public static function fetch($stmt) {
780
-		$a = \get_app();
781 784
 
782 785
 		$stamp1 = microtime(true);
783 786
 
@@ -824,7 +827,7 @@ class DBA
824 827
 				}
825 828
 		}
826 829
 
827
-		$a->saveTimestamp($stamp1, 'database');
830
+		self::$profiler->saveTimestamp($stamp1, 'database');
828 831
 
829 832
 		return $columns;
830 833
 	}
@@ -1534,7 +1537,6 @@ class DBA
1534 1537
 	 * @return boolean was the close successful?
1535 1538
 	 */
1536 1539
 	public static function close($stmt) {
1537
-		$a = \get_app();
1538 1540
 
1539 1541
 		$stamp1 = microtime(true);
1540 1542
 
@@ -1562,7 +1564,7 @@ class DBA
1562 1564
 				break;
1563 1565
 		}
1564 1566
 
1565
-		$a->saveTimestamp($stamp1, 'database');
1567
+		self::$profiler->saveTimestamp($stamp1, 'database');
1566 1568
 
1567 1569
 		return $ret;
1568 1570
 	}

+ 25
- 0
src/Factory/ProfilerFactory.php View File

@@ -0,0 +1,25 @@
1
+<?php
2
+
3
+namespace Friendica\Factory;
4
+
5
+use Friendica\Core\Config\ConfigCache;
6
+use Friendica\Util\Profiler;
7
+use Psr\Log\LoggerInterface;
8
+
9
+class ProfilerFactory
10
+{
11
+	/**
12
+	 * Creates a Profiler for the current execution
13
+	 *
14
+	 * @param LoggerInterface $logger      The logger for saving the profiling data
15
+	 * @param ConfigCache     $configCache The configuration cache
16
+	 *
17
+	 * @return Profiler
18
+	 */
19
+	public static function create(LoggerInterface $logger, ConfigCache $configCache)
20
+	{
21
+		$enabled = $configCache->get('system', 'profiler', false);
22
+		$renderTime = $configCache->get('rendertime', 'callstack', false);
23
+		return new Profiler($logger, $enabled, $renderTime);
24
+	}
25
+}

+ 2
- 2
src/Module/Install.php View File

@@ -75,7 +75,7 @@ class Install extends BaseModule
75 75
 				$dbdata  = Strings::escapeTags(trim(defaults($_POST, 'dbdata', '')));
76 76
 
77 77
 				// If we cannot connect to the database, return to the previous step
78
-				if (!self::$installer->checkDB($a->getConfig(), $dbhost, $dbuser, $dbpass, $dbdata)) {
78
+				if (!self::$installer->checkDB($a->getConfig(), $a->getProfiler(), $dbhost, $dbuser, $dbpass, $dbdata)) {
79 79
 					self::$currentWizardStep = self::DATABASE_CONFIG;
80 80
 				}
81 81
 
@@ -92,7 +92,7 @@ class Install extends BaseModule
92 92
 				$adminmail = Strings::escapeTags(trim(defaults($_POST, 'adminmail', '')));
93 93
 
94 94
 				// If we cannot connect to the database, return to the Database config wizard
95
-				if (!self::$installer->checkDB($a->getConfig(), $dbhost, $dbuser, $dbpass, $dbdata)) {
95
+				if (!self::$installer->checkDB($a->getConfig(), $a->getProfiler(), $dbhost, $dbuser, $dbpass, $dbdata)) {
96 96
 					self::$currentWizardStep = self::DATABASE_CONFIG;
97 97
 					return;
98 98
 				}

+ 5
- 5
src/Object/Image.php View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 namespace Friendica\Object;
7 7
 
8
+use Exception;
8 9
 use Friendica\App;
9 10
 use Friendica\Core\Cache;
10 11
 use Friendica\Core\Config;
@@ -14,7 +15,6 @@ use Friendica\Core\System;
14 15
 use Friendica\Database\DBA;
15 16
 use Friendica\Model\Photo;
16 17
 use Friendica\Util\Network;
17
-use Exception;
18 18
 use Imagick;
19 19
 use ImagickPixel;
20 20
 
@@ -656,7 +656,7 @@ class Image
656 656
 
657 657
 		$stamp1 = microtime(true);
658 658
 		file_put_contents($path, $string);
659
-		$a->saveTimestamp($stamp1, "file");
659
+		$a->getProfiler()->saveTimestamp($stamp1, "file");
660 660
 	}
661 661
 
662 662
 	/**
@@ -802,7 +802,7 @@ class Image
802 802
 					$a = \get_app();
803 803
 					$stamp1 = microtime(true);
804 804
 					file_put_contents($tempfile, $img_str);
805
-					$a->saveTimestamp($stamp1, "file");
805
+					$a->getProfiler()->saveTimestamp($stamp1, "file");
806 806
 
807 807
 					$data = getimagesize($tempfile);
808 808
 					unlink($tempfile);
@@ -910,7 +910,7 @@ class Image
910 910
 
911 911
 			$stamp1 = microtime(true);
912 912
 			$imagedata = @file_get_contents($url);
913
-			$a->saveTimestamp($stamp1, "file");
913
+			$a->getProfiler()->saveTimestamp($stamp1, "file");
914 914
 		}
915 915
 
916 916
 		$maximagesize = Config::get('system', 'maximagesize');
@@ -924,7 +924,7 @@ class Image
924 924
 
925 925
 		$stamp1 = microtime(true);
926 926
 		file_put_contents($tempfile, $imagedata);
927
-		$a->saveTimestamp($stamp1, "file");
927
+		$a->getProfiler()->saveTimestamp($stamp1, "file");
928 928
 
929 929
 		$data = getimagesize($tempfile);
930 930
 

+ 7
- 7
src/Util/Network.php View File

@@ -4,13 +4,13 @@
4 4
  */
5 5
 namespace Friendica\Util;
6 6
 
7
+use DOMDocument;
8
+use DomXPath;
9
+use Friendica\Core\Config;
7 10
 use Friendica\Core\Hook;
8 11
 use Friendica\Core\Logger;
9 12
 use Friendica\Core\System;
10
-use Friendica\Core\Config;
11 13
 use Friendica\Network\CurlResult;
12
-use DOMDocument;
13
-use DomXPath;
14 14
 
15 15
 class Network
16 16
 {
@@ -232,7 +232,7 @@ class Network
232 232
 
233 233
 		@curl_close($ch);
234 234
 
235
-		$a->saveTimestamp($stamp1, 'network');
235
+		$a->getProfiler()->saveTimestamp($stamp1, 'network');
236 236
 
237 237
 		return $curlResponse;
238 238
 	}
@@ -334,7 +334,7 @@ class Network
334 334
 
335 335
 		curl_close($ch);
336 336
 
337
-		$a->saveTimestamp($stamp1, 'network');
337
+		$a->getProfiler()->saveTimestamp($stamp1, 'network');
338 338
 
339 339
 		Logger::log('post_url: end ' . $url, Logger::DATA);
340 340
 
@@ -641,7 +641,7 @@ class Network
641 641
 		$http_code = $curl_info['http_code'];
642 642
 		curl_close($ch);
643 643
 
644
-		$a->saveTimestamp($stamp1, "network");
644
+		$a->getProfiler()->saveTimestamp($stamp1, "network");
645 645
 
646 646
 		if ($http_code == 0) {
647 647
 			return $url;
@@ -683,7 +683,7 @@ class Network
683 683
 		$body = curl_exec($ch);
684 684
 		curl_close($ch);
685 685
 
686
-		$a->saveTimestamp($stamp1, "network");
686
+		$a->getProfiler()->saveTimestamp($stamp1, "network");
687 687
 
688 688
 		if (trim($body) == "") {
689 689
 			return $url;

+ 252
- 0
src/Util/Profiler.php View File

@@ -0,0 +1,252 @@
1
+<?php
2
+
3
+namespace Friendica\Util;
4
+
5
+use Friendica\Core;
6
+use Psr\Container\ContainerExceptionInterface;
7
+use Psr\Container\ContainerInterface;
8
+use Psr\Container\NotFoundExceptionInterface;
9
+use Psr\Log\LoggerInterface;
10
+
11
+/**
12
+ * A class to store profiling data
13
+ * It can handle different logging data for specific functions or global performance measures
14
+ *
15
+ * It stores the data as log entries (@see LoggerInterface )
16
+ */
17
+class Profiler implements ContainerInterface
18
+{
19
+	/**
20
+	 * @var array The global performance array
21
+	 */
22
+	private $performance;
23
+	/**
24
+	 * @var array The function specific callstack
25
+	 */
26
+	private $callstack;
27
+	/**
28
+	 * @var bool True, if the Profiler is enabled
29
+	 */
30
+	private $enabled;
31
+	/**
32
+	 * @var bool True, if the Profiler should measure the whole rendertime including functions
33
+	 */
34
+	private $rendertime;
35
+
36
+	/**
37
+	 * @var LoggerInterface The profiler logger
38
+	 */
39
+	private $logger;
40
+
41
+	/**
42
+	 * @param LoggerInterface $logger The profiler logger
43
+	 * @param bool $enabled           True, if the Profiler is enabled
44
+	 * @param bool $renderTime        True, if the Profiler should measure the whole rendertime including functions
45
+	 */
46
+	public function __construct(LoggerInterface $logger, $enabled = false, $renderTime = false)
47
+	{
48
+		$this->enabled = $enabled;
49
+		$this->rendertime = $renderTime;
50
+		$this->logger = $logger;
51
+		$this->performance = [];
52
+		$this->callstack   = [];
53
+	}
54
+
55
+	/**
56
+	 * Saves a timestamp for a value - f.e. a call
57
+	 * Necessary for profiling Friendica
58
+	 *
59
+	 * @param int $timestamp the Timestamp
60
+	 * @param string $value A value to profile
61
+	 */
62
+	public function saveTimestamp($timestamp, $value)
63
+	{
64
+		if (!$this->enabled) {
65
+			return;
66
+		}
67
+
68
+		$duration = (float) (microtime(true) - $timestamp);
69
+
70
+		if (!isset($this->performance[$value])) {
71
+			// Prevent ugly E_NOTICE
72
+			$this->performance[$value] = 0;
73
+		}
74
+
75
+		$this->performance[$value] += (float) $duration;
76
+		$this->performance['marktime'] += (float) $duration;
77
+
78
+		$callstack = Core\System::callstack();
79
+
80
+		if (!isset($this->callstack[$value][$callstack])) {
81
+			// Prevent ugly E_NOTICE
82
+			$this->callstack[$value][$callstack] = 0;
83
+		}
84
+
85
+		$this->callstack[$value][$callstack] += (float) $duration;
86
+	}
87
+
88
+	/**
89
+	 * Resets the performance and callstack profiling
90
+	 *
91
+	 * @param bool $performance If true, reset the performance (Default true)
92
+	 * @param bool $callstack   If true, reset the callstack (Default true)
93
+	 */
94
+	public function reset($performance = true, $callstack = true)
95
+	{
96
+		if ($performance) {
97
+			$this->performance = [];
98
+			$this->performance['start'] = microtime(true);
99
+			$this->performance['database'] = 0;
100
+			$this->performance['database_write'] = 0;
101
+			$this->performance['cache'] = 0;
102
+			$this->performance['cache_write'] = 0;
103
+			$this->performance['network'] = 0;
104
+			$this->performance['file'] = 0;
105
+			$this->performance['rendering'] = 0;
106
+			$this->performance['parser'] = 0;
107
+			$this->performance['marktime'] = 0;
108
+			$this->performance['markstart'] = microtime(true);
109
+		}
110
+
111
+		if ($callstack) {
112
+			$this->callstack['database'] = [];
113
+			$this->callstack['database_write'] = [];
114
+			$this->callstack['cache'] = [];
115
+			$this->callstack['cache_write'] = [];
116
+			$this->callstack['network'] = [];
117
+			$this->callstack['file'] = [];
118
+			$this->callstack['rendering'] = [];
119
+			$this->callstack['parser'] = [];
120
+		}
121
+	}
122
+
123
+	/**
124
+	 * Save the current profiling data to a log entry
125
+	 *
126
+	 * @param string $message Additional message for the log
127
+	 */
128
+	public function saveLog($message)
129
+	{
130
+		// Write down the performance values into the log
131
+		if ($this->enabled) {
132
+			$duration = microtime(true)-$this->get('start');
133
+			$this->logger->info(
134
+				$message,
135
+				[
136
+					'module' => 'api',
137
+					'action' => 'call',
138
+					'database_read' => round($this->get('database') - $this->get('database_write'), 3),
139
+					'database_write' => round($this->get('database_write'), 3),
140
+					'cache_read' => round($this->get('cache'), 3),
141
+					'cache_write' => round($this->get('cache_write'), 3),
142
+					'network_io' => round($this->get('network'), 2),
143
+					'file_io' => round($this->get('file'), 2),
144
+					'other_io' => round($duration - ($this->get('database')
145
+							+ $this->get('cache') + $this->get('cache_write')
146
+							+ $this->get('network') + $this->get('file')), 2),
147
+					'total' => round($duration, 2)
148
+				]
149
+			);
150
+
151
+			$o = '';
152
+			if ($this->rendertime) {
153
+				if (isset($this->callstack["database"])) {
154
+					$o .= "\nDatabase Read:\n";
155
+					foreach ($this->callstack["database"] as $func => $time) {
156
+						$time = round($time, 3);
157
+						if ($time > 0) {
158
+							$o .= $func.": ".$time."\n";
159
+						}
160
+					}
161
+				}
162
+				if (isset($this->callstack["database_write"])) {
163
+					$o .= "\nDatabase Write:\n";
164
+					foreach ($this->callstack["database_write"] as $func => $time) {
165
+						$time = round($time, 3);
166
+						if ($time > 0) {
167
+							$o .= $func.": ".$time."\n";
168
+						}
169
+					}
170
+				}
171
+				if (isset($this->callstack["dache"])) {
172
+					$o .= "\nCache Read:\n";
173
+					foreach ($this->callstack["dache"] as $func => $time) {
174
+						$time = round($time, 3);
175
+						if ($time > 0) {
176
+							$o .= $func.": ".$time."\n";
177
+						}
178
+					}
179
+				}
180
+				if (isset($this->callstack["dache_write"])) {
181
+					$o .= "\nCache Write:\n";
182
+					foreach ($this->callstack["dache_write"] as $func => $time) {
183
+						$time = round($time, 3);
184
+						if ($time > 0) {
185
+							$o .= $func.": ".$time."\n";
186
+						}
187
+					}
188
+				}
189
+				if (isset($this->callstack["network"])) {
190
+					$o .= "\nNetwork:\n";
191
+					foreach ($this->callstack["network"] as $func => $time) {
192
+						$time = round($time, 3);
193
+						if ($time > 0) {
194
+							$o .= $func.": ".$time."\n";
195
+						}
196
+					}
197
+				}
198
+			}
199
+
200
+			$this->logger->info(
201
+				$message . ": " . sprintf(
202
+					"DB: %s/%s, Cache: %s/%s, Net: %s, I/O: %s, Other: %s, Total: %s".$o,
203
+					number_format($this->get('database') - $this->get('database_write'), 2),
204
+					number_format($this->get('database_write'), 2),
205
+					number_format($this->get('cache'), 2),
206
+					number_format($this->get('cache_write'), 2),
207
+					number_format($this->get('network'), 2),
208
+					number_format($this->get('file'), 2),
209
+					number_format($duration - ($this->get('database')
210
+							+ $this->get('cache') + $this->get('cache_write')
211
+							+ $this->get('network') + $this->get('file')), 2),
212
+					number_format($duration, 2)
213
+				)
214
+			);
215
+		}
216
+	}
217
+
218
+	/**
219
+	 * Finds an entry of the container by its identifier and returns it.
220
+	 *
221
+	 * @param string $id Identifier of the entry to look for.
222
+	 *
223
+	 * @throws NotFoundExceptionInterface  No entry was found for **this** identifier.
224
+	 * @throws ContainerExceptionInterface Error while retrieving the entry.
225
+	 *
226
+	 * @return int Entry.
227
+	 */
228
+	public function get($id)
229
+	{
230
+		if (!$this->has($id)) {
231
+			return 0;
232
+		} else {
233
+			return $this->performance[$id];
234
+		}
235
+	}
236
+
237
+	/**
238
+	 * Returns true if the container can return an entry for the given identifier.
239
+	 * Returns false otherwise.
240
+	 *
241
+	 * `has($id)` returning true does not mean that `get($id)` will not throw an exception.
242
+	 * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
243
+	 *
244
+	 * @param string $id Identifier of the entry to look for.
245
+	 *
246
+	 * @return bool
247
+	 */
248
+	public function has($id)
249
+	{
250
+		return isset($this->performance[$id]);
251
+	}
252
+}

+ 4
- 0
tests/DatabaseTest.php View File

@@ -9,6 +9,7 @@ use Friendica\Core\Config;
9 9
 use Friendica\Database\DBA;
10 10
 use Friendica\Factory;
11 11
 use Friendica\Util\BasePath;
12
+use Friendica\Util\Profiler;
12 13
 use PHPUnit\DbUnit\DataSet\YamlDataSet;
13 14
 use PHPUnit\DbUnit\TestCaseTrait;
14 15
 use PHPUnit_Extensions_Database_DB_IDatabaseConnection;
@@ -43,8 +44,11 @@ abstract class DatabaseTest extends MockedTest
43 44
 		$configLoader = new Config\ConfigCacheLoader($basedir);
44 45
 		$config = Factory\ConfigFactory::createCache($configLoader);
45 46
 
47
+		$profiler = \Mockery::mock(Profiler::class);
48
+
46 49
 		DBA::connect(
47 50
 			$config,
51
+			$profiler,
48 52
 			getenv('MYSQL_HOST'),
49 53
 			getenv('MYSQL_USERNAME'),
50 54
 			getenv('MYSQL_PASSWORD'),

Loading…
Cancel
Save