From a80446eb595d52382b29674cf8935fc9aa1f4caa Mon Sep 17 00:00:00 2001 From: phosit Date: Fri, 24 Jul 2026 16:15:22 +0200 Subject: [PATCH] Use the profiler to profile map generation Instead of writing the duration to the console it uses `Engine.ProfileStart` and `Engine.ProfileStop` to profile map generation. Refs: #5263 --- .../maps/random/rmgen/RandomMapLogger.js | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/binaries/data/mods/public/maps/random/rmgen/RandomMapLogger.js b/binaries/data/mods/public/maps/random/rmgen/RandomMapLogger.js index 2a9bbc021d..1e66acf595 100644 --- a/binaries/data/mods/public/maps/random/rmgen/RandomMapLogger.js +++ b/binaries/data/mods/public/maps/random/rmgen/RandomMapLogger.js @@ -1,6 +1,6 @@ function RandomMapLogger() { - this.lastTime = undefined; + this.taskStarted = false; this.startTime = Engine.GetMicroseconds ? Engine.GetMicroseconds() : 0; this.prefix = ""; // seems noisy @@ -21,27 +21,18 @@ RandomMapLogger.prototype.printDirectly = function(string) RandomMapLogger.prototype.print = function(string) { - this.printDuration(); - this.printDirectly(this.prefix + string + "..."); - this.lastTime = Engine.GetMicroseconds(); -}; + if (this.taskStarted) + Engine.ProfileStop(); -RandomMapLogger.prototype.printDuration = function() -{ - if (!this.lastTime) - return; - - this.printDurationDirectly("", this.lastTime); - this.lastTime = Engine.GetMicroseconds(); + const text = this.prefix + string; + this.printDirectly(text + "...\n"); + Engine.ProfileStart(text); + this.taskStarted = true; }; RandomMapLogger.prototype.close = function() { - this.printDuration(); - this.printDurationDirectly(this.prefix + "Total map generation time:", this.startTime); -}; - -RandomMapLogger.prototype.printDurationDirectly = function(text, startTime) -{ - this.printDirectly(text + " " + ((Engine.GetMicroseconds() - startTime) / 1000000).toFixed(6) + "s.\n"); + if (this.taskStarted) + Engine.ProfileStop(); + this.printDirectly(this.prefix + "Map generation finished.\n"); };