New API to get the system-level tick

Post Reply
folk
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Fri Mar 03, 2017 5:00 pm
Contact:

New API to get the system-level tick

Post by folk »

Hi,

So it's quite hard to actually measure performance right now. It is possible to a certain degree, but it would be made much easier if you simply added a read-only .time/.os_tick attribute or function somewhere (like on .game) that simply returns the system-level tick.

See here for an example https://github.com/o-lim/luasystem/
To be exact, what I actually want is the monotime property of that library. Specifically, this is the code for their Linux/Win implementation (there's also a Mac one):

Code: Select all

#ifdef _WIN32
WINBASEAPI ULONGLONG WINAPI GetTickCount64(VOID);

static double time_monotime(void) {
    ULONGLONG ms = GetTickCount64();
    return ms*1.0e-3;
}
#else
static double time_monotime(void) {
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC, &ts);
    return ts.tv_sec + ts.tv_nsec*1.0e-9;
}
#endif
Then we could much more easily measure our addon codepaths and optimize accordingly.

Thank you.

folk
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Fri Mar 03, 2017 5:00 pm
Contact:

Re: New API to get the system-level tick

Post by folk »

I guess you would have to seed it to be replay-compatible.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: New API to get the system-level tick

Post by orzelek »

You can't access data that can be different on varius multiplayer clients - it will desync the game.
Currently log() command saves with timestamp so you can use it for measuring.

folk
Long Handed Inserter
Long Handed Inserter
Posts: 96
Joined: Fri Mar 03, 2017 5:00 pm
Contact:

Re: New API to get the system-level tick

Post by folk »

orzelek wrote:You can't access data that can be different on varius multiplayer clients - it will desync the game.
Yes, I assumed the game state was distributed by the host only.
orzelek wrote:Currently log() command saves with timestamp so you can use it for measuring.
Ah, thank you, I did not know about log() :-)

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

Re: New API to get the system-level tick

Post by Boodals »

Although this is (or was, if a moderator moves it) in Won't implement, and is pretty old, I created a way to get performance metrics for lua scripts (I have source access), which will be in the next version of 0.17.
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.

Post Reply

Return to “Implemented mod requests”