From f0241043de4e90d3a61345821c0911e84aee7228 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 23 Dec 2020 20:26:18 +0000 Subject: [PATCH] CrashDump: add server uptime to crash information --- src/pocketmine/CrashDump.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/pocketmine/CrashDump.php b/src/pocketmine/CrashDump.php index 2b9f002df..88ba60dbc 100644 --- a/src/pocketmine/CrashDump.php +++ b/src/pocketmine/CrashDump.php @@ -47,6 +47,7 @@ use function is_resource; use function json_encode; use function json_last_error_msg; use function max; +use function microtime; use function mkdir; use function ob_end_clean; use function ob_get_contents; @@ -59,7 +60,6 @@ use function sprintf; use function str_split; use function strpos; use function substr; -use function time; use function zend_version; use function zlib_encode; use const E_COMPILE_ERROR; @@ -90,7 +90,7 @@ class CrashDump{ * having their content changed, version format changing, etc. * It is not necessary to increase this when adding new fields. */ - private const FORMAT_VERSION = 3; + private const FORMAT_VERSION = 4; private const PLUGIN_INVOLVEMENT_NONE = "none"; private const PLUGIN_INVOLVEMENT_DIRECT = "direct"; @@ -100,7 +100,7 @@ class CrashDump{ private $server; /** @var resource */ private $fp; - /** @var int */ + /** @var float */ private $time; /** * @var mixed[] @@ -113,12 +113,12 @@ class CrashDump{ private $path; public function __construct(Server $server){ - $this->time = time(); + $this->time = microtime(true); $this->server = $server; if(!is_dir($this->server->getDataPath() . "crashdumps")){ mkdir($this->server->getDataPath() . "crashdumps"); } - $this->path = $this->server->getDataPath() . "crashdumps/" . date("D_M_j-H.i.s-T_Y", $this->time) . ".log"; + $this->path = $this->server->getDataPath() . "crashdumps/" . date("D_M_j-H.i.s-T_Y", (int) $this->time) . ".log"; $fp = @fopen($this->path, "wb"); if(!is_resource($fp)){ throw new \RuntimeException("Could not create Crash Dump"); @@ -126,7 +126,8 @@ class CrashDump{ $this->fp = $fp; $this->data["format_version"] = self::FORMAT_VERSION; $this->data["time"] = $this->time; - $this->addLine($this->server->getName() . " Crash Dump " . date("D M j H:i:s T Y", $this->time)); + $this->data["uptime"] = $this->time - \pocketmine\START_TIME; + $this->addLine($this->server->getName() . " Crash Dump " . date("D M j H:i:s T Y", (int) $this->time)); $this->addLine(); $this->baseCrash(); $this->generalData();