Add method to return current unix epoch time
Add method to return current unix epoch time
It seems the lua 'os' library is not included in the factorio lua sandbox, likely for security considerations. In general, this is a good idea, but in particular, a way to access the unix epoch time would be useful. Epoch time is useful for logging (timestamps), debugging slow code execution (examining the difference between start and end timestamps), setting timers / alarms (the time between ticks can vary, so doing something in 60 ticks is not the same as 1 second), etc.
I'd guess something like game.os_time() would work. Millisecond or nanoseconds would be preferable to second accuracy.
Thoughts?
I'd guess something like game.os_time() would work. Millisecond or nanoseconds would be preferable to second accuracy.
Thoughts?
Re: Add method to return current unix epoch time
Slightly related discussion: https://forums.factorio.com/forum/vie ... 99&p=89368
Re: Add method to return current unix epoch time
Thanks for the link.sillyfly wrote:Slightly related discussion: https://forums.factorio.com/forum/vie ... 99&p=89368
I think to clarify, I don't care about player time, but machine / operating system time of the host / local player. I don't think the player time matters, just the time for the machine executing the code. I think the main usefulness here is for modders - debug logging, timing code.
Re: Add method to return current unix epoch time
The only reason we don't have it accessible now is determinism. You could never use a replay or play multiplayer with any mod that used os.time() (or any variant of it).
If you want to get ahold of me I'm almost always on Discord.
Re: Add method to return current unix epoch time
If the function only works in SP, that seems like an acceptable trade-off.Rseding91 wrote:The only reason we don't have it accessible now is determinism. You could never use a replay or play multiplayer with any mod that used os.time() (or any variant of it).
Re: Add method to return current unix epoch time
I believe. It's been raised somewhere already: devs don't support separation of multiplayer and single player mods. Even though you're not forced to ensure mp compatibility.
It would indeed be nice to have some tool for benchmarking which is not a bunch of cryptic numbers in an overlay which brings the renderer on it's knees on its own.
For anything else, it's really more reasonable to use the game's own timeline (as in, ticks) exactly because 1 second is not always 60 ticks.
It would indeed be nice to have some tool for benchmarking which is not a bunch of cryptic numbers in an overlay which brings the renderer on it's knees on its own.
For anything else, it's really more reasonable to use the game's own timeline (as in, ticks) exactly because 1 second is not always 60 ticks.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
Re: Add method to return current unix epoch time
How about player.uptime(), which tracks how long a player has been in the current map.
Re: Add method to return current unix epoch time
I don't see how that would be useful, as the return value would be given in ticks. (Returning time would be non-deterministic, and therefore not possible.) So if you wrote code like local t = player.uptime(); some calculation; player.print(player.uptime() - t);, it would always print 0.DaveMcW wrote:How about player.uptime(), which tracks how long a player has been in the current map.
You could of course use it to measure ticks between event callbacks, but then again, you can do that already without player.uptime(): Just subtract game.tick values.
Re: Add method to return current unix epoch time
Turn off the other debug options and it doesn't effect performance at all to have the debug times rendering.Adil wrote:I believe. It's been raised somewhere already: devs don't support separation of multiplayer and single player mods. Even though you're not forced to ensure mp compatibility.
It would indeed be nice to have some tool for benchmarking which is not a bunch of cryptic numbers in an overlay which brings the renderer on it's knees on its own.
For anything else, it's really more reasonable to use the game's own timeline (as in, ticks) exactly because 1 second is not always 60 ticks.
If you want to get ahold of me I'm almost always on Discord.
Re: Add method to return current unix epoch time
It still shows only first number for mods - all others were always 0 last time I checked.Rseding91 wrote:Turn off the other debug options and it doesn't effect performance at all to have the debug times rendering.Adil wrote:I believe. It's been raised somewhere already: devs don't support separation of multiplayer and single player mods. Even though you're not forced to ensure mp compatibility.
It would indeed be nice to have some tool for benchmarking which is not a bunch of cryptic numbers in an overlay which brings the renderer on it's knees on its own.
For anything else, it's really more reasonable to use the game's own timeline (as in, ticks) exactly because 1 second is not always 60 ticks.
And those missing ones are avg and max if I remember correctly?
Re: Add method to return current unix epoch time
Yes, you have to give it time to generate the average and max. That information isn't saved so it refreshes every time you open the game.orzelek wrote:It still shows only first number for mods - all others were always 0 last time I checked.Rseding91 wrote:Turn off the other debug options and it doesn't effect performance at all to have the debug times rendering.Adil wrote:I believe. It's been raised somewhere already: devs don't support separation of multiplayer and single player mods. Even though you're not forced to ensure mp compatibility.
It would indeed be nice to have some tool for benchmarking which is not a bunch of cryptic numbers in an overlay which brings the renderer on it's knees on its own.
For anything else, it's really more reasonable to use the game's own timeline (as in, ticks) exactly because 1 second is not always 60 ticks.
And those missing ones are avg and max if I remember correctly?
If you want to get ahold of me I'm almost always on Discord.
Re: Add method to return current unix epoch time
What is game.local_player then? That is a SP only method.Adil wrote:I believe. It's been raised somewhere already: devs don't support separation of multiplayer and single player mods. Even though you're not forced to ensure mp compatibility.
Counting ticks is not an useful method, there needs to be a way to measure wall time of the cpu clock. I know exactly how many ticks pass already. Tick time is not helpful for debugging slow code that executes during a single tick.Adil wrote:It would indeed be nice to have some tool for benchmarking which is not a bunch of cryptic numbers in an overlay which brings the renderer on it's knees on its own.
For anything else, it's really more reasonable to use the game's own timeline (as in, ticks) exactly because 1 second is not always 60 ticks.
Re: Add method to return current unix epoch time
game.local_player is not a SP only method. It works just fine in MP - in fact that's the reason it was added so you could use it in MP and from the console.Afforess wrote:What is game.local_player then? That is a SP only method.Adil wrote:I believe. It's been raised somewhere already: devs don't support separation of multiplayer and single player mods. Even though you're not forced to ensure mp compatibility.
If you want to get ahold of me I'm almost always on Discord.
-
- Filter Inserter
- Posts: 952
- Joined: Sat May 23, 2015 12:10 pm
- Contact:
Re: Add method to return current unix epoch time
It only exists when the callstack originates from a console command and is the player that typed and submitted the commandAfforess wrote:What is game.local_player then? That is a SP only method.Adil wrote:I believe. It's been raised somewhere already: devs don't support separation of multiplayer and single player mods. Even though you're not forced to ensure mp compatibility.
just like a gui click event also contains the player that clicked
Re: Add method to return current unix epoch time
I have never seen anything else then 0's for 2nd and 3rd mod timings.Rseding91 wrote:Yes, you have to give it time to generate the average and max. That information isn't saved so it refreshes every time you open the game.orzelek wrote:It still shows only first number for mods - all others were always 0 last time I checked.Rseding91 wrote:Turn off the other debug options and it doesn't effect performance at all to have the debug times rendering.Adil wrote:I believe. It's been raised somewhere already: devs don't support separation of multiplayer and single player mods. Even though you're not forced to ensure mp compatibility.
It would indeed be nice to have some tool for benchmarking which is not a bunch of cryptic numbers in an overlay which brings the renderer on it's knees on its own.
For anything else, it's really more reasonable to use the game's own timeline (as in, ticks) exactly because 1 second is not always 60 ticks.
And those missing ones are avg and max if I remember correctly?
Even after charting thousands of tiles with RSO and chart command only number changed is first one. And it takes quite a few minutes to do all that charting.
Re: Add method to return current unix epoch time
Mods don't do the charting. Mods run a command which tells the game "chart this area" and the game does it slowly over the next X ticks where X is however long it takes to do the charting without lagging the game.orzelek wrote:I have never seen anything else then 0's for 2nd and 3rd mod timings.
Even after charting thousands of tiles with RSO and chart command only number changed is first one. And it takes quite a few minutes to do all that charting.
If you want to get ahold of me I'm almost always on Discord.
Re: Add method to return current unix epoch time
RSO gets called every chunk generated and shows some serious time on first number - never anything on 2nd and 3rd. And first one can jump up to 2 ms or so quite frequently since it's generating a lot of ores. I can see numbers for stuff like entities/scripts etc taking much less time and all 3 numbers working.Rseding91 wrote:Mods don't do the charting. Mods run a command which tells the game "chart this area" and the game does it slowly over the next X ticks where X is however long it takes to do the charting without lagging the game.orzelek wrote:I have never seen anything else then 0's for 2nd and 3rd mod timings.
Even after charting thousands of tiles with RSO and chart command only number changed is first one. And it takes quite a few minutes to do all that charting.
What is needed to get 2nd/3rd number to show up for mod?
It might be that I have wrong assumption about what those two mean.
Re: Add method to return current unix epoch time
Although this is (or was, if a moderator moves it) in Won't implement, and is stupidly old, I created a way to get performance metrics for lua scripts (I have source access), which is in 0.17.15.
LuaGameScript.create_profiler, returns a LuaProfiler, which can be used anywhere a localised string is used. You can't read the raw time values from lua. This means that it is totally desync safe.
LuaGameScript.create_profiler, returns a LuaProfiler, which can be used anywhere a localised string is used. You can't read the raw time values from lua. This means that it is totally desync safe.