From 328f7aa71b8a8a00a97e5a727ef3c88ce6b45b8f Mon Sep 17 00:00:00 2001 From: Yessiest Date: Mon, 14 Mar 2022 23:26:11 +0400 Subject: [PATCH] Added debug tools --- core/binds/globalkeys.lua | 18 +++++++++++++++++- libs/debug.lua | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 libs/debug.lua diff --git a/core/binds/globalkeys.lua b/core/binds/globalkeys.lua index c5e0bb8..842937e 100644 --- a/core/binds/globalkeys.lua +++ b/core/binds/globalkeys.lua @@ -1,5 +1,6 @@ local awful = require("awful") local gears = require("gears") +local debug = require("libs.debug") local globalkeys = gears.table.join( awful.key({ global.modkey, }, "Left", awful.tag.viewprev, @@ -76,7 +77,21 @@ local globalkeys = gears.table.join( ) end end, - {description = "restore minimized", group = "client"}) + {description = "restore minimized", group = "client"}), + awful.key({global.modkey,"Control" }, "s", function() + debug.print_awesome_memory_stats("Precollect") + collectgarbage("collect") + collectgarbage("collect") + gears.timer { + callback = function() + debug.print_awesome_memory_stats("Postcollect") + return false + end, + timeout = 5, + autostart = true, + single_shot = true + } + end, {description = "print awesome wm memory statistics", group="awesome"}) ) -- Bind all key numbers to tags. @@ -127,6 +142,7 @@ for i = 1, 9 do end, {description = "toggle focused client on tag #" .. i, group = "tag"}) ) + end return globalkeys diff --git a/libs/debug.lua b/libs/debug.lua new file mode 100644 index 0000000..a341515 --- /dev/null +++ b/libs/debug.lua @@ -0,0 +1,17 @@ +local naughty = require("naughty") +local debug = {} +-- Thanks, u/skhil +-- (https://www.reddit.com/r/awesomewm/comments/te49nb/why_does_awesomes_ram_consumption_get_higher_and/) +function debug.print_awesome_memory_stats(message) + print(os.date(), "\nLua memory usage:", collectgarbage("count")) + out_string = tostring(os.date()) .. "\nLua memory usage:"..tostring(collectgarbage("count")).."\n" + out_string = out_string .. "Objects alive:" + print("Objects alive:") + for name, obj in pairs{ button = button, client = client, drawable = drawable, drawin = drawin, key = key, screen = screen, tag = tag } do + out_string =out_string .. "\n" .. tostring(name) .. " = " ..tostring(obj.instances()) + print(name, obj.instances()) + end + naughty.notify({title = "Awesome WM memory statistics " .. message, text = out_string, timeout=20,hover_timeout=20}) +end + +return debug