Skip to content

Commit 254d930

Browse files
deepskyblue86therealbobo
authored andcommitted
fix(chisels): process non-empty captures without events
7a19b38 prevented chisel output without events, but on very busy systems we can have captures with just the preamble and no events. Skip the output if we don't have events AND the thread table is empty. Signed-off-by: Angelo Puglisi <[email protected]>
1 parent e89ee29 commit 254d930

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

userspace/sysdig/chisels/lsof.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ limitations under the License.
2121
description = "This chisel prints the open file descriptors for every process in the system, with an output that is similar to the one of lsof. Output is at a point in time; adjust this in the filter. It defaults to time of evt.num=0";
2222
short_description = "List (and optionally filter) the open file descriptors.";
2323
category = "System State";
24-
24+
2525
-- Argument list
2626
args =
2727
{
@@ -66,7 +66,7 @@ function on_init()
6666
end
6767

6868
-- Final chisel initialization
69-
function on_capture_start()
69+
function on_capture_start()
7070
capturing = true
7171
return true
7272
end
@@ -83,16 +83,16 @@ function on_capture_end()
8383
if not capturing then
8484
return
8585
end
86-
87-
if match == false then
86+
87+
local ttable = sysdig.get_thread_table(filter)
88+
89+
if match == false and next(ttable) == nil then
8890
print("empty capture or no event matching the filter")
8991
return
9092
end
9193

92-
local ttable = sysdig.get_thread_table(filter)
93-
9494
local sorted_ttable = pairs_top_by_val(ttable, 0, function(t,a,b) return a < b end)
95-
95+
9696
print(extend_string("COMMAND", 20) ..
9797
extend_string("PID", 8) ..
9898
extend_string("TID", 8) ..

userspace/sysdig/chisels/netstat.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ limitations under the License.
2121
description = "Print the system network connections, with an output that is similar to the one of netstat. Output is at a point in time; adjust this in the filter. It defaults to time of evt.num=0";
2222
short_description = "List (and optionally filter) network connections.";
2323
category = "System State";
24-
24+
2525
-- Argument list
2626
args =
2727
{
@@ -66,7 +66,7 @@ function on_init()
6666
end
6767

6868
-- Final chisel initialization
69-
function on_capture_start()
69+
function on_capture_start()
7070
capturing = true
7171
return true
7272
end
@@ -83,14 +83,14 @@ function on_capture_end()
8383
if not capturing then
8484
return
8585
end
86-
87-
if match == false then
86+
87+
local ttable = sysdig.get_thread_table(filter)
88+
89+
if match == false and next(ttable) == nil then
8890
print("empty capture or no event matching the filter")
8991
return
9092
end
9193

92-
local ttable = sysdig.get_thread_table(filter)
93-
9494
print(extend_string("Proto", 6) ..
9595
extend_string("Server Address", 25) ..
9696
extend_string("Client Address", 25) ..
@@ -99,7 +99,7 @@ function on_capture_end()
9999

100100
for tid, proc in pairs(ttable) do
101101
local fdtable = proc.fdtable
102-
102+
103103
for fd, fdinfo in pairs(fdtable) do
104104
local cip = fdinfo.cip
105105
local cport = fdinfo.cport

userspace/sysdig/chisels/ps.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ limitations under the License.
2121
description = "List the running processes, with an output that is similar to the one of ps. Output is at a point in time; adjust this in the filter. It defaults to time of evt.num=0";
2222
short_description = "List (and optionally filter) the machine processes.";
2323
category = "System State";
24-
24+
2525
-- Argument list
2626
args =
2727
{
@@ -65,7 +65,7 @@ function on_init()
6565
return true
6666
end
6767

68-
function on_capture_start()
68+
function on_capture_start()
6969
capturing = true
7070
return true
7171
end
@@ -82,16 +82,16 @@ function on_capture_end(ts_s, ts_ns, delta)
8282
if not capturing then
8383
return
8484
end
85-
86-
if match == false then
85+
86+
local ttable = sysdig.get_thread_table(filter)
87+
88+
if match == false and next(ttable) == nil then
8789
print("empty capture or no event matching the filter")
8890
return
8991
end
90-
91-
local ttable = sysdig.get_thread_table(filter)
9292

9393
local sorted_ttable = pairs_top_by_val(ttable, 0, function(t,a,b) return a < b end)
94-
94+
9595
print(extend_string("TID", 8) ..
9696
extend_string("PID", 8) ..
9797
extend_string("USER", 12) ..

0 commit comments

Comments
 (0)