CrashDump: add server uptime to crash information

This commit is contained in:
Dylan K. Taylor 2020-12-23 20:26:18 +00:00
parent 135f1c95e4
commit f0241043de
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -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();