<commit_before>-- Use of this source code is governed by the Apache 2.0 license; see COPYING.

module(..., package.seeall)

local S = require("syscall")
local lib = require("core.lib")
local shm = require("core.shm")

local function usage (code)
   local f = code == 0 and io.stdout or io.stderr
   f:write(require("program.top.README_inc"))
   main.exit(code)
end

local function parse_args (args)
   local opt = {}
   function opt.h (arg) usage(0) end
   args = lib.dogetopt(args, opt, "h", {help='h'})
   if #args ~= 0 then usage(1) end
end

local function compute_snabb_instances()
   -- Produces set of snabb instances, excluding this one.
   local pids = {}
   local my_pid = S.getpid()
   for _, name in ipairs(shm.children("/")) do
      -- This could fail as the name could be for example "by-name"
      local p = tonumber(name)
      if p and p ~= my_pid then table.insert(pids, p) end
   end
   return pids
end

function run (args)
   local instances = compute_snabb_instances()
   for _, instance in ipairs(instances) do print(instance) end
   main.exit(0)
end<commit_msg>snabb ps parses command-line args<commit_after>-- Use of this source code is governed by the Apache 2.0 license; see COPYING.

module(..., package.seeall)

local S = require("syscall")
local lib = require("core.lib")
local shm = require("core.shm")

local function usage (code)
   local f = code == 0 and io.stdout or io.stderr
   f:write(require("program.ps.README_inc"))
   main.exit(code)
end

local function parse_args (args)
   local opt = {}
   function opt.h (arg) usage(0) end
   args = lib.dogetopt(args, opt, "h", {help='h'})
   if #args ~= 0 then usage(1) end
end

local function compute_snabb_instances()
   -- Produces set of snabb instances, excluding this one.
   local pids = {}
   local my_pid = S.getpid()
   for _, name in ipairs(shm.children("/")) do
      -- This could fail as the name could be for example "by-name"
      local p = tonumber(name)
      if p and p ~= my_pid then table.insert(pids, p) end
   end
   return pids
end

function run (args)
   parse_args (args)
   local instances = compute_snabb_instances()
   for _, instance in ipairs(instances) do print(instance) end
   main.exit(0)
end
{'fraction_non_alphanumeric': 0.11809954751131221, 'fraction_numerical': 0.006334841628959276, 'mean_word_length': 3.413173652694611, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5793148', 'n_tokens_mistral': 743, 'n_tokens_neox': 734, 'n_words': 259}