+ /**
+ * Start a profiler recording
+ *
+ * @param string $value
+ *
+ * @return void
+ */
+ public function startRecording(string $value)
+ {
+ if (!$this->enabled) {
+ return;
+ }
+
+ $this->timestamps[] = ['value' => $value, 'stamp' => microtime(true), 'credit' => 0];
+ }
+
+ /**
+ * Stop a profiler recording
+ *
+ * @param string $callstack
+ *
+ * @return void
+ */
+ 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])) {
+ $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;
+ }
+