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

Things that already exist in the current mod API
Post Reply
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5201
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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 753 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 753 times
profilerJA.png
profilerJA.png (98.44 KiB) Viewed 753 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γƒŸγƒͺη§’γŒγ‹γ‹γ‚ŠγΎγ—γŸοΌ
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: ζ—₯本θͺž, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Boodals
Fast Inserter
Fast Inserter
Posts: 129
Joined: Sun Feb 11, 2018 7:10 pm
Contact:

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

Post 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.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5201
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: ζ—₯本θͺž, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

justarandomgeek
Filter Inserter
Filter Inserter
Posts: 292
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

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

Post 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

Pi-C
Smart Inserter
Smart Inserter
Posts: 1088
Joined: Sun Oct 14, 2018 8:13 am
Contact:

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

Post 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 ":*"?
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

justarandomgeek
Filter Inserter
Filter Inserter
Posts: 292
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

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

Post 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

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5201
Joined: Tue Jul 12, 2016 9:03 am
Contact:

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

Post 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+)"`?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: ζ—₯本θͺž, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to β€œAlready exists”