Page 1 of 1

Remove "Elapsed:"+"ms" from LuaProfiler printout

Posted: Wed Oct 21, 2020 3:20 pm
by eradicator
What?

When printing a profiler it should print just the time, without any words.

Current state

profiler.png
profiler.png (46.33 KiB) Viewed 3303 times

Why?

Formating custom messages with the profiler is ugly due to the enforced word content. Especially when the user has set their locale to a language that the profiler-providing mod is not localized for. English and Japanese examples:

profilerEN.png
profilerEN.png (84.76 KiB) Viewed 3303 times
profilerJA.png
profilerJA.png (98.44 KiB) Viewed 3303 times

Desired behavior

The compiler should print as an undecorated number.
Note that for example Japanese uses the localized unit name "ミリ秒" for "ms" and also does not include any whitespace.

Code: Select all


/c game.print{"my-mod.my-profiler-message",game.create_profiler()}

-- English locale.
The function took 0.123456ms to run!

-- Japanese locale.
関数呼び出しには0.12456ミリ秒がかかりました!

Re: Remove "Elapsed:"+"ms" from LuaProfiler printout

Posted: Thu Oct 22, 2020 9:58 pm
by Boodals
When I made the lua profiler, I gave it that locale so that you can quickly see whether the timer is paused or not when it is read, without having to add extra code. It was not intended to be seen by users, since it is just a debugging tool for mod developers.
You can just overwrite the locale in your mod if you really want to display it, although I guess you'd have to do it for every supported language.

Re: Remove "Elapsed:"+"ms" from LuaProfiler printout

Posted: Thu Oct 22, 2020 11:16 pm
by eradicator
Boodals wrote:
Thu Oct 22, 2020 9:58 pm
It was not intended to be seen by users, since it is just a debugging tool for mod developers.
Well, when a mod developer uses a debugging mod, then they're users from the debugging mod developers perspective. But they're still mod developers. It's a user-developer dualism! ;)
Boodals wrote:
Thu Oct 22, 2020 9:58 pm
You can just overwrite the locale in your mod
I assumed this would be hardcoded for ... no reason at all :oops:. Thanks a lot for bothering to tell me! I'll count that as "already implemented".

For future readers:

Code: Select all

[lua-profiler]
elapsed=Elapsed: __1__ms
duration=Duration: __1__ms

Re: Remove "Elapsed:"+"ms" from LuaProfiler printout

Posted: Fri Oct 30, 2020 1:55 am
by justarandomgeek
eradicator wrote:
Thu Oct 22, 2020 11:16 pm
[snip]

For future readers:

Code: Select all

[lua-profiler]
elapsed=Elapsed: __1__ms
duration=Duration: __1__ms
Also for future readers: if you're using my profiler tool in vscode you'll need to keep a single : before the time so that i can parse it correctly, since i assume default locale

Re: Remove "Elapsed:"+"ms" from LuaProfiler printout

Posted: Fri Oct 30, 2020 3:39 am
by Pi-C
justarandomgeek wrote:
Fri Oct 30, 2020 1:55 am
Also for future readers: if you're using my profiler tool in vscode you'll need to keep a single : before the time so that i can parse it correctly, since i assume default locale
If you assume missing colons may be a problem, why don't you match the input against ":*"?

Re: Remove "Elapsed:"+"ms" from LuaProfiler printout

Posted: Fri Oct 30, 2020 3:42 am
by justarandomgeek
Pi-C wrote:
Fri Oct 30, 2020 3:39 am
justarandomgeek wrote:
Fri Oct 30, 2020 1:55 am
Also for future readers: if you're using my profiler tool in vscode you'll need to keep a single : before the time so that i can parse it correctly, since i assume default locale
If you assume missing colons may be a problem, why don't you match the input against ":*"?
it's part of a larger message with sections divided by : because reasons, i just throw away the label section

Re: Remove "Elapsed:"+"ms" from LuaProfiler printout

Posted: Fri Oct 30, 2020 3:46 pm
by eradicator
justarandomgeek wrote:
Fri Oct 30, 2020 3:42 am
Pi-C wrote:
Fri Oct 30, 2020 3:39 am
justarandomgeek wrote:
Fri Oct 30, 2020 1:55 am
Also for future readers: if you're using my profiler tool in vscode you'll need to keep a single : before the time so that i can parse it correctly, since i assume default locale
If you assume missing colons may be a problem, why don't you match the input against ":*"?
it's part of a larger message with sections divided by : because reasons, i just throw away the label section
If you're going through the trouble of parsing a translated localized string anyway, why not match "(%d%.%d+)"`?