Page 1 of 1

New API to get the system-level tick

Posted: Sun Mar 26, 2017 12:01 pm
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.

Re: New API to get the system-level tick

Posted: Sun Mar 26, 2017 12:02 pm
by folk
I guess you would have to seed it to be replay-compatible.

Re: New API to get the system-level tick

Posted: Tue Mar 28, 2017 6:05 pm
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.

Re: New API to get the system-level tick

Posted: Tue Mar 28, 2017 6:38 pm
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() :-)

Re: New API to get the system-level tick

Posted: Mon Mar 18, 2019 7:17 pm
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.