- $this->enabled = $configCache->get('system', 'profiler');
- $this->rendertime = $configCache->get('rendertime', 'callstack');
- $this->reset();
+ 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])) {
+ $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;