1
0
mirror of https://github.com/danog/amp.git synced 2024-11-26 20:15:00 +01:00

Add further tracing to TracingDriver

This commit is contained in:
Niklas Keller 2017-12-07 19:15:32 +01:00
parent ebffe58bbc
commit 79039cddcb

View File

@ -7,6 +7,7 @@ use function Amp\Internal\formatStacktrace;
class TracingDriver extends Driver {
private $driver;
private $creationTraces = [];
private $cancelTraces = [];
public function __construct(Driver $driver) {
$this->driver = $driver;
@ -60,12 +61,13 @@ class TracingDriver extends Driver {
try {
$this->driver->enable($watcherId);
} catch (InvalidWatcherError $e) {
throw new InvalidWatcherError($watcherId, $e->getMessage() . "\r\n\r\nCreation Trace: " . $this->getCreationTrace($watcherId));
throw new InvalidWatcherError($watcherId, $e->getMessage() . "\r\n\r\n== Creation Trace =====\r\n" . $this->getCreationTrace($watcherId) . "\r\n\r\n== Cancel Trace =====\r\n" . $this->getCreationTrace($watcherId));
}
}
public function cancel(string $watcherId) {
$this->driver->cancel($watcherId);
$this->creationTraces[$watcherId] = formatStacktrace(\debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS));
}
public function disable(string $watcherId) {
@ -114,4 +116,10 @@ class TracingDriver extends Driver {
throw new InvalidWatcherError($watcher, "An invalid watcher has been used: " . $watcher);
})();
}
private function getCancelTrace(string $watcher): string {
return $this->cancelTraces[$watcher] ?? (function () use ($watcher) {
throw new InvalidWatcherError($watcher, "An invalid watcher has been used: " . $watcher);
})();
}
}