Skip to content

Commit

Permalink
Merge pull request #998 from Igalia/fix-issue-975
Browse files Browse the repository at this point in the history
Make "snabbvmx top" print out only counters that are defined
  • Loading branch information
dpino authored Nov 6, 2017
2 parents 4bdfe8c + b0fe977 commit 52bf472
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/program/snabbvmx/top/top.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module(..., package.seeall)
local counter = require("core.counter")
local ffi = require("ffi")
local lib = require("core.lib")
local counters = require("program.lwaftr.coutners")
local counters = require("program.lwaftr.counters")
local lwutil = require("apps.lwaftr.lwutil")
local shm = require("core.shm")
local top = require("program.top.top")
Expand Down Expand Up @@ -50,7 +50,8 @@ end

local function open_counters (tree)
local function open_counter (name)
return counter.open(tree.."/apps/lwaftr/"..name..".counter", 'readonly')
local path = tree.."/apps/lwaftr/"..name..".counter"
return shm.exists(path) and counter.open(path, 'readonly')
end
local function open_counter_list (t)
local ret = {}
Expand Down Expand Up @@ -111,8 +112,9 @@ end
local lwaftr_metrics_row = {51, 7, 7, 7, 7, 11}
local function print_lwaftr_metrics (new_stats, last_stats, time_delta)
local function delta(t, s, name)
assert(t[name] and s[name])
return tonumber(t[name] - s[name])
if t[name] and s[name] then
return tonumber(t[name] - s[name])
end
end
local function delta_v6 (t, s)
local rx = delta(t, s, "in-ipv6-packets")
Expand Down Expand Up @@ -164,14 +166,18 @@ local function print_lwaftr_metrics (new_stats, last_stats, time_delta)
if lwaftrspec == "nic" then
local name = "ifInDiscards"
local diff = delta(t, s, name)
print_row(metrics_row, { lwaftrspec .. " " .. name,
int_s(t[name]), int_s(diff)})
else
for name, id in pairs(counter_names(lwaftrspec)) do
local diff = delta(t, s, name)
if diff then
print_row(metrics_row, { lwaftrspec .. " " .. name,
int_s(t[name]), int_s(diff)})
end
else
for _, name in ipairs(counter_names(lwaftrspec)) do
local diff = delta(t, s, name)
if diff then
print_row(metrics_row, { lwaftrspec .. " " .. name,
int_s(t[name]), int_s(diff)})
end
end
end
end
end
Expand Down

0 comments on commit 52bf472

Please sign in to comment.