Skip to content

Commit b79267b

Browse files
committed
cpu metrics: make cpu metrics module hot reloadable
1 parent 411dad9 commit b79267b

File tree

3 files changed

+45
-39
lines changed

3 files changed

+45
-39
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- cpu metrics hot reload [#228](https://github.com/tarantool/metrics/issues/228)
810

911
## [0.8.0] - 2021-04-13
1012
### Added

metrics/default_metrics/tarantool/cpu.lua

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,49 @@
11
local ffi = require('ffi')
22
local utils = require('metrics.utils')
33

4-
if ffi.os == 'OSX' then
5-
ffi.cdef[[
6-
typedef int32_t suseconds_t;
7-
struct timeval {
8-
long tv_sec; /* seconds */
9-
suseconds_t tv_usec; /* microseconds */
10-
};
11-
]]
12-
else
13-
ffi.cdef[[
14-
struct timeval {
15-
long tv_sec; /* seconds */
16-
long tv_usec; /* microseconds */
17-
};
18-
]]
4+
if not pcall(ffi.typeof, "struct timeval") then
5+
if ffi.os == 'OSX' then
6+
ffi.cdef[[
7+
typedef int32_t suseconds_t;
8+
struct timeval {
9+
long tv_sec; /* seconds */
10+
suseconds_t tv_usec; /* microseconds */
11+
};
12+
]]
13+
else
14+
ffi.cdef[[
15+
struct timeval {
16+
long tv_sec; /* seconds */
17+
long tv_usec; /* microseconds */
18+
};
19+
]]
20+
end
1921
end
2022

21-
ffi.cdef[[
22-
struct rusage {
23-
struct timeval ru_utime; /* user CPU time used */
24-
struct timeval ru_stime; /* system CPU time used */
25-
long ru_maxrss; /* maximum resident set size */
26-
long ru_ixrss; /* integral shared memory size */
27-
long ru_idrss; /* integral unshared data size */
28-
long ru_isrss; /* integral unshared stack size */
29-
long ru_minflt; /* page reclaims (soft page faults) */
30-
long ru_majflt; /* page faults (hard page faults) */
31-
long ru_nswap; /* swaps */
32-
long ru_inblock; /* block input operations */
33-
long ru_oublock; /* block output operations */
34-
long ru_msgsnd; /* IPC messages sent */
35-
long ru_msgrcv; /* IPC messages received */
36-
long ru_nsignals; /* signals received */
37-
long ru_nvcsw; /* voluntary context switches */
38-
long ru_nivcsw; /* involuntary context switches */
39-
};
40-
int getrusage(int who, struct rusage *usage);
41-
int gettimeofday(struct timeval *tv, struct timezone *tz);
42-
]]
23+
if not pcall(ffi.typeof, "struct rusage") then
24+
ffi.cdef[[
25+
struct rusage {
26+
struct timeval ru_utime; /* user CPU time used */
27+
struct timeval ru_stime; /* system CPU time used */
28+
long ru_maxrss; /* maximum resident set size */
29+
long ru_ixrss; /* integral shared memory size */
30+
long ru_idrss; /* integral unshared data size */
31+
long ru_isrss; /* integral unshared stack size */
32+
long ru_minflt; /* page reclaims (soft page faults) */
33+
long ru_majflt; /* page faults (hard page faults) */
34+
long ru_nswap; /* swaps */
35+
long ru_inblock; /* block input operations */
36+
long ru_oublock; /* block output operations */
37+
long ru_msgsnd; /* IPC messages sent */
38+
long ru_msgrcv; /* IPC messages received */
39+
long ru_nsignals; /* signals received */
40+
long ru_nvcsw; /* voluntary context switches */
41+
long ru_nivcsw; /* involuntary context switches */
42+
};
43+
int getrusage(int who, struct rusage *usage);
44+
int gettimeofday(struct timeval *tv, struct timezone *tz);
45+
]]
46+
end
4347

4448
local RUSAGE_SELF = 0
4549

test/integration/hotreload_test.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ require('strict').on()
33
local t = require("luatest")
44
local g = t.group('hotreload')
55

6-
g.test_cpu_reloads = function()
6+
g.test_cpu_hotreload = function()
77
require('metrics.default_metrics.tarantool.cpu')
88
for k in pairs(package.loaded) do
9-
if k:find('metrics') ~= nil then
9+
if k:find('cpu') ~= nil then
1010
package.loaded[k] = nil
1111
end
1212
end

0 commit comments

Comments
 (0)