Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

topmem: Replace lua-filesystem dependency with libluv #45

Merged
merged 3 commits into from
Dec 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
topmem: Replace lua-filesystem dependency with libluv
  • Loading branch information
ventureoo committed Dec 24, 2023
commit 895113179ad5c46f1c56921c88b76789cc1ef2ff
15 changes: 8 additions & 7 deletions usr/bin/topmem
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env lua
local found, lfs = pcall(require, 'lfs')
local found, uv = pcall(require, 'luv')

if not found then
print("lua-filesystem dependency is missing, please install it from repositories")
print("libluv dependency is missing, please install it from repositories")
os.exit(1)
end

Expand Down Expand Up @@ -50,13 +50,13 @@ end

local function get_process_map()
local map = {}
for pid in lfs.dir("/proc/") do
local proceses = uv.fs_scandir("/proc")
local pid, ftype = uv.fs_scandir_next(proceses)

while pid do
if pid:match(pid_pattern) then
local f = table.concat({"/proc", pid}, "/")
local attr = lfs.attributes(f)
assert (type(attr) == "table")

if attr.mode == "directory" then
if ftype == "directory" then
local rss, swap = get_process_values(table.concat({f, "status"}, "/"))
local name = get_process_first_arg(table.concat({f, "cmdline"}, "/"))
if name and rss then
Expand All @@ -69,6 +69,7 @@ local function get_process_map()
end
end
end
pid, ftype = uv.fs_scandir_next(proceses)
end
map = convert_hashmap_table(map)
table.sort(map, function (a, b) return (a[1] > b[1]) end)
Expand Down