2014-10-02 19:16:57 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2014-10-02 19:16:57 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2014-10-02 19:16:57 -04:00
|
|
|
*/
|
2014-10-03 14:39:09 -04:00
|
|
|
namespace OC\Diagnostics;
|
2014-10-02 19:16:57 -04:00
|
|
|
|
2014-10-03 14:39:09 -04:00
|
|
|
use OCP\Diagnostics\IEvent;
|
2014-10-02 19:16:57 -04:00
|
|
|
|
|
|
|
|
class Event implements IEvent {
|
2025-11-18 11:36:29 -05:00
|
|
|
protected ?float $end = null;
|
2014-10-02 19:16:57 -04:00
|
|
|
|
2025-11-17 09:32:54 -05:00
|
|
|
public function __construct(
|
2025-11-18 11:36:29 -05:00
|
|
|
protected string $id,
|
|
|
|
|
protected string $description,
|
|
|
|
|
protected float $start,
|
2025-11-17 09:32:54 -05:00
|
|
|
) {
|
2014-10-02 19:16:57 -04:00
|
|
|
}
|
|
|
|
|
|
2025-11-18 11:36:29 -05:00
|
|
|
public function end(float $time): void {
|
2014-10-02 19:16:57 -04:00
|
|
|
$this->end = $time;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-18 11:36:29 -05:00
|
|
|
public function getStart(): float {
|
2014-10-02 19:16:57 -04:00
|
|
|
return $this->start;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-18 11:36:29 -05:00
|
|
|
public function getId(): string {
|
2014-10-02 19:16:57 -04:00
|
|
|
return $this->id;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-18 11:36:29 -05:00
|
|
|
public function getDescription(): string {
|
2014-10-02 19:16:57 -04:00
|
|
|
return $this->description;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-18 11:36:29 -05:00
|
|
|
public function getEnd(): float {
|
|
|
|
|
return $this->end ?? -1;
|
2014-10-02 19:16:57 -04:00
|
|
|
}
|
|
|
|
|
|
2025-11-18 11:36:29 -05:00
|
|
|
public function getDuration(): float {
|
2014-10-03 16:13:55 -04:00
|
|
|
if (!$this->end) {
|
|
|
|
|
$this->end = microtime(true);
|
|
|
|
|
}
|
2014-10-02 19:16:57 -04:00
|
|
|
return $this->end - $this->start;
|
|
|
|
|
}
|
2022-02-02 03:57:50 -05:00
|
|
|
|
2024-04-02 11:13:35 -04:00
|
|
|
public function __toString(): string {
|
2022-02-02 03:57:50 -05:00
|
|
|
return $this->getId() . ' ' . $this->getDescription() . ' ' . $this->getDuration();
|
|
|
|
|
}
|
2014-10-02 19:16:57 -04:00
|
|
|
}
|