From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id AB4DE6F83A5; Mon, 29 Dec 2025 16:55:51 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AB4DE6F83A5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1767016551; bh=jtac5Y7GBgUp/S3auChxkczSNxKk7k97Sv/k8dRXoU8=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=QSF81TFJ1qUXbLDGjeY16J8yDs4um5wmGXJsAjL6Sw6SL6rgXgns4vPF6+9CkaycD qSgDZt7J+aq6AG6KodSUAJoNI6d9fNhlZyDhcYQTss6AxmEH2+jPbb0/mZraOFi1rm jbGiYHdditEO6tKvBaH/G3W3yaSDpwVHO9wuXni4= Received: from send194.i.mail.ru (send194.i.mail.ru [95.163.59.33]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id F05ED6F83A5 for ; Mon, 29 Dec 2025 16:55:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org F05ED6F83A5 Received: by exim-smtp-7b4fb89df9-5mc8r with esmtpa (envelope-from ) id 1vaDiv-000000005km-3yKI; Mon, 29 Dec 2025 16:55:50 +0300 Content-Type: multipart/alternative; boundary="------------3Kslb8iV2Qp54fZVU0XCSsI3" Message-ID: <6fa76c02-99fc-4cde-a663-593047a15ccb@tarantool.org> Date: Mon, 29 Dec 2025 16:55:49 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org References: In-Reply-To: X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD979975AF0D777FEBD390EF5E93CD1F77387498C0EC589AA68182A05F538085040FBAEC419924B4F823DE06ABAFEAF6705283E417934F8A464DBBE8904563065575C8D6840D30A5C53 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E50EC9128971FD6EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006379BF04B24BEB7B2D58638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B21532DFCF1884AFCA2E070BE324C7D3C4148379E96B3535A9F6B57BC7E64490618DEB871D839B73339E8FC8737B5C224936DA1BED736F9328CC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92176DF2183F8FC7C078FCF50C7EAF9C588941B15DA834481F9449624AB7ADAF37BA3038C0950A5D3613377AFFFEAFD269176DF2183F8FC7C0CAB4775CB929E3BB7B076A6E789B0E97A8DF7F3B2552694AD5FFEEA1DED7F25D49FD398EE364050F9647ADFADE5905B1F41620B44FB51B7DB3661434B16C20ACC84D3B47A649675FE827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B2303E78B907142AC75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A57876E2BDA20491DE5002B1117B3ED6965959DCB8B0A57ADDA13BD6A4B0E00B96823CB91A9FED034534781492E4B8EEAD47A3109F1ACFD409BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE191716CD42B3DD1D34CAB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D6595BAEB5F9DCC7AD1CD6F73CF0A1B6E1D80A22D17704358DC3797AE55E70EA89536BE9D2C5E483FB79B8341EE9D5BE9A0A640DEBA15ACF0851ED1751B0028FB1BE4E308A1A593D9D1D8CD93680B12512CF4C41F94D744909CE2512F26BEC029E55448553D2254B8D95CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVTZJppT4ZVHR2Ch0KUgp42o= X-Mailru-Sender: 811C44EDE0507D1FF7A5115BD94F8393F70CC65A56BE71466750B362712FA5BD4C3D5CF3B8D799C5A73B27EA175287C9645D15D82EE4B272BD6E4642A116CA93524AA66B5ACBE6721EF430B9A63E2A504198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v2 luajit 02/41] perf: introduce clock module X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This is a multi-part message in MIME format. --------------3Kslb8iV2Qp54fZVU0XCSsI3 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Sergey! Thanks for the patch! LGTM after submitting a new issue about investigating CLOCK_REALTIME drawbacks Sergey On 12/26/25 12:17, Sergey Kaplun wrote: > This module contains 2 functions: > - `realtime()` -- returns the time represented by the wall clock. > - `process_cputime()` -- measures the CPU time instead of elapsed time. > > 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..cf708194 > --- /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 > +-- CPU time consumed by the process. > +local CLOCK_PROCESS_CPUTIME_ID = 2 > + > +-- All functions below returns the corresponding elapsed time 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 > + > +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 --------------3Kslb8iV2Qp54fZVU0XCSsI3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Hi, Sergey!

Thanks for the patch!

LGTM after submitting a new issue about investigating CLOCK_REALTIME drawbacks

Sergey

On 12/26/25 12:17, Sergey Kaplun wrote:
This module contains 2 functions:
- `realtime()` -- returns the time represented by the wall clock.
- `process_cputime()` -- measures the CPU time instead of elapsed time.

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..cf708194
--- /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
+-- CPU time consumed by the process.
+local CLOCK_PROCESS_CPUTIME_ID = 2
+
+-- All functions below returns the corresponding elapsed time 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
+
+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
--------------3Kslb8iV2Qp54fZVU0XCSsI3--