Skip to content

Commit b787286

Browse files
committed
fix systrack synchronization
* change luaprobe to sleep=false * split systrack into two runtimes (driver and probes)
1 parent 0bc550b commit b787286

File tree

4 files changed

+44
-22
lines changed

4 files changed

+44
-22
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ examples_install:
5454
${INSTALL} -m 0644 examples/dnsblock/*.lua ${SCRIPTS_INSTALL_PATH}/examples/dnsblock
5555
${MKDIR} ${SCRIPTS_INSTALL_PATH}/examples/dnsdoctor
5656
${INSTALL} -m 0644 examples/dnsdoctor/*.lua ${SCRIPTS_INSTALL_PATH}/examples/dnsdoctor
57+
${MKDIR} ${SCRIPTS_INSTALL_PATH}/examples/systrack
58+
${INSTALL} -m 0644 examples/systrack/*.lua ${SCRIPTS_INSTALL_PATH}/examples/systrack
5759

5860
examples_uninstall:
5961
${RM} -r ${SCRIPTS_INSTALL_PATH}/examples

examples/systrack.lua

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,31 @@
33
-- SPDX-License-Identifier: MIT OR GPL-2.0-only
44
--
55

6-
local linux = require("linux")
7-
local probe = require("probe")
8-
local device = require("device")
9-
local systab = require("syscall.table")
10-
11-
local syscalls = {"openat", "read", "write", "readv", "writev", "close"}
6+
local lunatik = require("lunatik")
7+
local linux = require("linux")
8+
local device = require("device")
9+
local rcu = require("rcu")
1210

1311
local function nop() end -- do nothing
1412

1513
local s = linux.stat
1614
local driver = {name = "systrack", open = nop, release = nop, mode = s.IRUGO}
1715

18-
local track = {}
16+
local systrack = rcu.table()
17+
lunatik._ENV.systrack = systrack
18+
1919
local toggle = true
2020
function driver:read()
2121
local log = ""
2222
if toggle then
23-
for symbol, counter in pairs(track) do
24-
log = log .. string.format("%s: %d\n", symbol, counter)
25-
end
23+
rcu.map(systrack, function (symbol, counter)
24+
log = log .. string.format("%s: %d\n", symbol, counter:getnumber(0))
25+
end)
2626
end
2727
toggle = not toggle
2828
return log
2929
end
3030

31-
for _, symbol in ipairs(syscalls) do
32-
local address = systab[symbol]
33-
track[symbol] = 0
34-
35-
local function handler()
36-
track[symbol] = track[symbol] + 1
37-
end
38-
39-
probe.new(address, {pre = handler, post = nop})
40-
end
41-
31+
driver.probes = lunatik.runtime("systrack/probes", false)
4232
device.new(driver)
4333

examples/systrack/probes.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--
2+
-- SPDX-FileCopyrightText: (c) 2023-2024 Ring Zero Desenvolvimento de Software LTDA
3+
-- SPDX-License-Identifier: MIT OR GPL-2.0-only
4+
--
5+
6+
local lunatik = require("lunatik")
7+
local probe = require("probe")
8+
local syscall = require("syscall.table")
9+
local data = require("data")
10+
11+
local systrack = lunatik._ENV.systrack
12+
13+
local function nop() end -- do nothing
14+
15+
local function inc(counter)
16+
counter:setnumber(0, counter:getnumber(0) + 1)
17+
end
18+
19+
local sizeofnumber = string.packsize("n")
20+
21+
for symbol, address in pairs(syscall) do
22+
systrack[symbol] = data.new(sizeofnumber)
23+
24+
local function handler()
25+
inc(systrack[symbol])
26+
end
27+
28+
probe.new(address, {pre = handler, post = nop})
29+
end
30+

lib/luaprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static const lunatik_class_t luaprobe_class = {
167167
.name = "probe",
168168
.methods = luaprobe_mt,
169169
.release = luaprobe_release,
170-
.sleep = true,
170+
.sleep = false,
171171
};
172172

173173
static int luaprobe_new(lua_State *L)

0 commit comments

Comments
 (0)