mirror of
https://github.com/friendica/friendica
synced 2025-04-29 17:44:24 +02:00
Support for stacked profiler analysis
This commit is contained in:
parent
3cef3ab107
commit
c89533a70b
17 changed files with 763 additions and 611 deletions
|
@ -54,6 +54,8 @@ class Profiler implements ContainerInterface
|
|||
*/
|
||||
private $rendertime;
|
||||
|
||||
private $timestamps = [];
|
||||
|
||||
/**
|
||||
* True, if the Profiler should measure the whole rendertime including functions
|
||||
*
|
||||
|
@ -85,6 +87,48 @@ class Profiler implements ContainerInterface
|
|||
$this->reset();
|
||||
}
|
||||
|
||||
public function startRecording(string $value)
|
||||
{
|
||||
if (!$this->enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->timestamps[] = ['value' => $value, 'stamp' => microtime(true), 'credit' => 0];
|
||||
}
|
||||
|
||||
public function stopRecording(string $callstack = '')
|
||||
{
|
||||
if (!$this->enabled || empty($this->timestamps)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$timestamp = array_pop($this->timestamps);
|
||||
|
||||
$duration = floatval(microtime(true) - $timestamp['stamp'] - $timestamp['credit']);
|
||||
$value = $timestamp['value'];
|
||||
|
||||
foreach ($this->timestamps as $key => $stamp) {
|
||||
$this->timestamps[$key]['credit'] += $duration;
|
||||
}
|
||||
|
||||
$callstack = $callstack ?: System::callstack(4, $value == 'rendering' ? 0 : 1);
|
||||
|
||||
if (!isset($this->performance[$value])) {
|
||||
// Prevent ugly E_NOTICE
|
||||
$this->performance[$value] = 0;
|
||||
}
|
||||
|
||||
$this->performance[$value] += (float) $duration;
|
||||
$this->performance['marktime'] += (float) $duration;
|
||||
|
||||
if (!isset($this->callstack[$value][$callstack])) {
|
||||
// Prevent ugly E_NOTICE
|
||||
$this->callstack[$value][$callstack] = 0;
|
||||
}
|
||||
|
||||
$this->callstack[$value][$callstack] += (float) $duration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a timestamp for a value - f.e. a call
|
||||
* Necessary for profiling Friendica
|
||||
|
@ -227,6 +271,15 @@ class Profiler implements ContainerInterface
|
|||
}
|
||||
}
|
||||
}
|
||||
if (isset($this->callstack["rendering"])) {
|
||||
$output .= "\nRendering:\n";
|
||||
foreach ($this->callstack["rendering"] as $func => $time) {
|
||||
$time = round($time, 3);
|
||||
if ($time > $limit) {
|
||||
$output .= $func . ": " . $time . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue