<!DOCTYPE html>
<html data-lt-installed="true">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="padding-bottom: 1px;">
<p>Hi, Sergey!</p>
<p>thanks for the patch! Please see my comments.</p>
<p>Sergey</p>
<div class="moz-cite-prefix">On 10/24/25 13:50, Sergey Kaplun wrote:<br>
</div>
<blockquote type="cite"
cite="mid:9c378a741df0ebcd8e56ec738436ff450c167d72.1761301736.git.skaplun@tarantool.org">
<pre wrap="" class="moz-quote-pre">This module contains 2 functions:
- `realtime()` -- returns the time represented by the wall clock.
- `process_cputime()` -- returns the time consumed by all threads of
the process.</pre>
</blockquote>
I would rephrase second bullet: "to measure CPU time instead of
elapsed time"<br>
Also, I would add this description to the Lua module as well.
<blockquote type="cite"
cite="mid:9c378a741df0ebcd8e56ec738436ff450c167d72.1761301736.git.skaplun@tarantool.org">
<pre wrap="" class="moz-quote-pre">
Both functions are implemented via FFI call to the `clock_gettime()`.
---
perf/utils/clock.lua | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
create mode 100644 perf/utils/clock.lua
diff --git a/perf/utils/clock.lua b/perf/utils/clock.lua
new file mode 100644
index 00000000..57385967
--- /dev/null
+++ b/perf/utils/clock.lua
@@ -0,0 +1,35 @@
+local ffi = require('ffi')
+
+ffi.cdef[[
+struct timespec {
+ long tv_sec; /* Seconds. */
+ long tv_nsec; /* Nanoseconds. */
+};
+
+int clock_gettime(int clockid, struct timespec *tp);
+]]
+
+local C = ffi.C
+
+-- Wall clock.
+local CLOCK_REALTIME = 0</pre>
</blockquote>
<p> This clock is not a reliable source of the time. This clock can
be adjusted by</p>
<p>NTP or manually or by timezones. It is better to use
CLOCK_MONOTONIC or</p>
<p>even CLOCK_MONOTONIC_RAW (not portable, Linux-specific), it is
more reliable</p>
<p>and does not depend on things listed above.</p>
<blockquote type="cite"
cite="mid:9c378a741df0ebcd8e56ec738436ff450c167d72.1761301736.git.skaplun@tarantool.org">
<pre wrap="" class="moz-quote-pre">
+-- CPU time consumed by the process.
+local CLOCK_PROCESS_CPUTIME_ID = 2
+
+-- All functions below returns the corresponding `clock_gettime()`</pre>
</blockquote>
s/`clock_gettime()`/elapsed time/
<blockquote type="cite"
cite="mid:9c378a741df0ebcd8e56ec738436ff450c167d72.1761301736.git.skaplun@tarantool.org">
<pre wrap="" class="moz-quote-pre">
+-- in seconds.
+local M = {}
+
+local timespec = ffi.new('struct timespec[1]')
+
+function M.realtime()
+ C.clock_gettime(CLOCK_REALTIME, timespec)
+ return tonumber(timespec[0].tv_sec) + tonumber(timespec[0].tv_nsec) / 1e9
+end
+</pre>
</blockquote>
<p>may be it is better to make conversion only once?</p>
<p>@@ -24,7 +24,7 @@ local timespec = ffi.new('struct timespec[1]')<br>
<br>
function M.realtime()<br>
C.clock_gettime(CLOCK_REALTIME, timespec)<br>
- return tonumber(timespec[0].tv_sec) +
tonumber(timespec[0].tv_nsec) / 1e9<br>
+ return tonumber(timespec[0].tv_sec + timespec[0].tv_nsec / 1e9)<br>
end<br>
<br>
the same below</p>
<blockquote type="cite"
cite="mid:9c378a741df0ebcd8e56ec738436ff450c167d72.1761301736.git.skaplun@tarantool.org">
<pre wrap="" class="moz-quote-pre">
+function M.process_cputime()
+ C.clock_gettime(CLOCK_PROCESS_CPUTIME_ID, timespec)
+ return tonumber(timespec[0].tv_sec) + tonumber(timespec[0].tv_nsec) / 1e9
+end
+
+return M
</pre>
</blockquote>
</body>
<lt-container></lt-container>
</html>