awesome-wm-widgets
awesome-wm-widgets copied to clipboard
cpu widget - ps (average historical values) vs top (current values)
Not sure if anyone else is likely to agree, but just in case... I was surprised that the cpu figures for specific processes didn't seem to match those from "top" at all. Digging deeper, it seems the cpu widgets gets per-process values from ps. According to respective man pages, for ps: "CPU usage is currently expressed as the percentage of time spent running during the entire lifetime of a process. This is not ideal, and it does not conform to the standards that ps otherwise conforms to." For top, the figure relates not to average but to current CPU usage: "The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time." Current values are far more interesting to me - code for them, using top and awk, is here: https://github.com/qpkorr/awesome-wm-widgets/commit/0ad1359de6b10dc5dc584702804a026b2dcaa592
Thanks for this information! I was wondering the same, but didn't investigate much. I think it could be useful to define a parameter for this option, so that user can choose which values to show. I'll add it and will post here when it's done.
Great! Thanks so much for the excellent widgets! Given the cpu graphs above the per process values are current, host historical averages, I'd encourage defaulting to 'top' values - but keeping both for backwards compatibility sounds good too. I wasn't sure if awk was standard enough but couldn't easily do what I needed to do with head/tail/cut - and at least calling awk is just one process, not three. Anyway - thanks again!
FYI - my code in the mentioned commit was less than ideal for processes like [foo/bar] - it was trying to 'drop the path' and converting that to just /bar] - but the start was not a path. I've updated in my fork. I hit one more issue - that sometimes the Name entries were a little bit too wide I think, and were causing some kind of line wrapping - I think - which was moving the bottom of the popup down (and making it hard to close the popup again by clicking on the widget). I made the popup a little wider - but couldn't get it looking quite right. I was struggling to close it though on a laptop, so I'm happy with the change unless you can do it better. Another alternative - would it be reasonable to close the popup by clicking anywhere within it (except the kill buttons, obviously)?
On an unrelated note - thanks for adding the net-widget! I was disappointed to not find one when I first found your repo. One request - my laptop sometimes connects via wifi, and sometimes via ethernet - is the final version of your widget likely to support aggregated network figures, if no interface is specified?
Thanks for the feedback, I also noticed the name entry issue, didin't have much time to check yet. But for the unrelated note, which is a good idea, btw - just pushed the change (https://github.com/streetturtle/awesome-wm-widgets/commit/bf6c45fb3a96baf8a39cabdf460f200b82a9de89) to get the speed from all intefaces by default. Please check if it works as expected.
Ha - we might well have been coding the second issue at the same time :) I chose a different route though, via the command line (I'd say yours is better) - except - I figured the "lo" interface (loopback, I presume?) should be omitted. Perhaps you could adopt the bash extglob from my solution?
if interface == nil then
watch([[bash -O extglob -c "cat /sys/class/net/!(lo)/statistics/*_bytes | awk 'NR%2{rx+=\$1}!(NR%2){tx+=\$1}END{print rx;print tx}'"]], 1, update_widget, net_speed_widget)
else
watch(string.format([[bash -c "cat /sys/class/net/%s/statistics/*_bytes"]], interface), 1, update_widget, net_speed_widget)
end