Added optional description to Stopwatch records.

This commit is contained in:
Andrey Savchenko committed 2018-12-17 18:15:59 +02:00
1 parent 63f1b9e216
commit eb573e143e
1 file changed
+8 -2
+8 -2
View File
@@ -16,13 +16,18 @@ class Stopwatch_Record implements Record_Interface {
/** @var StopwatchEvent */ /** @var StopwatchEvent */
protected $stopwatch_event; protected $stopwatch_event;
/** @var string */
protected $description = '';
/** /**
* @param string $name Event name. * @param string $name Event name.
* @param StopwatchEvent $stopwatch_event Stopwatch event instance. * @param StopwatchEvent $stopwatch_event Stopwatch event instance.
* @param string $description Optional description for the event.
*/ */
public function __construct( string $name, StopwatchEvent $stopwatch_event ) { public function __construct( string $name, StopwatchEvent $stopwatch_event, string $description = '' ) {
$this->name = $name; $this->name = $name;
$this->stopwatch_event = $stopwatch_event; $this->stopwatch_event = $stopwatch_event;
$this->description = $description;
} }
/** /**
@@ -39,8 +44,9 @@ class Stopwatch_Record implements Record_Interface {
$duration = round( $this->stopwatch_event->getDuration() ); $duration = round( $this->stopwatch_event->getDuration() );
$memory = $this->stopwatch_event->getMemory() / 1024 / 1024; $memory = $this->stopwatch_event->getMemory() / 1024 / 1024;
$description = '' !== $this->description ? "<hr />{$this->description}" : '';
return "{$this->name} – {$duration} ms – {$memory} MB"; return "{$this->name} – {$duration} ms – {$memory} MB{$description}";
} }
/** /**