possibly more accurate profiling #3707

Closed
opened 2023-02-03 01:26:05 +00:00 by flux · 2 comments
Member

i've discovered that the profiler uses minetest.get_us_time, which keeps counting when a process is sleeping. instead it probably should be using os.clock. this can be implemented w/ a very minor change to the builtin lua api

diff --git a/builtin/profiler/instrumentation.lua b/builtin/profiler/instrumentation.lua
index 80f1c66af..0fc32448e 100644
--- a/builtin/profiler/instrumentation.lua
+++ b/builtin/profiler/instrumentation.lua
@@ -72,9 +72,9 @@ end
 -- Keep `measure` and the closure in `instrument` lean, as these, and their
 -- directly called functions are the overhead that is caused by instrumentation.
 --
-local time, log = core.get_us_time, sampler.log
+local time, log = os.clock, sampler.log
 local function measure(modname, instrument_name, start, ...)
-       log(modname, instrument_name, time() - start)
+       log(modname, instrument_name, (time() - start) * 1e6)
        return ...
 end
 --- Automatically instrument a function to measure and log to the sampler.
i've discovered that the profiler uses `minetest.get_us_time`, which keeps counting when a process is sleeping. instead it probably should be using `os.clock`. this can be implemented w/ a very minor change to the builtin lua api ```diff diff --git a/builtin/profiler/instrumentation.lua b/builtin/profiler/instrumentation.lua index 80f1c66af..0fc32448e 100644 --- a/builtin/profiler/instrumentation.lua +++ b/builtin/profiler/instrumentation.lua @@ -72,9 +72,9 @@ end -- Keep `measure` and the closure in `instrument` lean, as these, and their -- directly called functions are the overhead that is caused by instrumentation. -- -local time, log = core.get_us_time, sampler.log +local time, log = os.clock, sampler.log local function measure(modname, instrument_name, start, ...) - log(modname, instrument_name, time() - start) + log(modname, instrument_name, (time() - start) * 1e6) return ... end --- Automatically instrument a function to measure and log to the sampler. ```
flux added the
1. kind/other
3. source/engine
labels 2023-02-03 01:26:37 +00:00
Author
Member

i'm trying to get the opinion of core devs on this, but i don't want to forget it.

i'm trying to get the opinion of core devs on this, but i don't want to forget it.
flux added the
5. result/wontfix
label 2023-07-17 18:17:12 +00:00
Author
Member

i've learned that os.clock() counts the execution time across all threads within the process, so it's not suitable for measuring the timing of something in a single thread. closing.

i've learned that `os.clock()` counts the execution time across *all threads within the process*, so it's *not* suitable for measuring the timing of something in a single thread. closing.
flux closed this issue 2023-07-17 18:18:16 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: your-land/bugtracker#3707
No description provided.