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

Replace /proc hackery with psutil (widget portability) #1250

Open
wants to merge 14 commits into
base: develop
from

Conversation

Projects
None yet
4 participants
@ekollof
Copy link

ekollof commented Dec 20, 2018

Start of replacing 'groping for values in /proc' with a cross platform system monitoring interface called psutil.

Already done:

  • memory/swap widgets
  • CPUGraph/MemoryGraph in graph.py

To be done:

  • SwapGraph
  • net.py
  • NetGraph
@ekollof

This comment has been minimized.

Copy link

ekollof commented Dec 20, 2018

Oh, easy fix, hang on

Emiel Kollof added some commits Dec 20, 2018

Emiel Kollof
Emiel Kollof
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015 Jörg Thalheim (Mic92)
# -*- coding: utf-8 -*- # Copyright (c) 2015 Jörg Thalheim (Mic92)

This comment has been minimized.

@tych0

tych0 Dec 20, 2018

Member

? this seems like noise.

@ekollof

This comment has been minimized.

Copy link

ekollof commented Dec 20, 2018

val['MemUsed'] = val['MemTotal'] - val['MemFree']
val['MemUsed'] = int(psutil.virtual_memory().used / 1024 / 1024)
val['MemTotal'] = int(psutil.virtual_memory().total / 1024 / 1024)
val['MemFree'] = val['MemTotal'] - val['MemUsed']

This comment has been minimized.

@ramnes

ramnes Dec 20, 2018

Member

There's a potential config breakage for people doing stuff like this here.

Maybe we could accept that config breakage but then expose all the stuff contained in psutil.virtual_memory(), so that people actually can replace what they used to do? We could then drop the useless mapping in names.

For the same reason, I would also add psutil.swap_memory() informations here and not in a separate widget (plus I don't feel like the two widgets will benefit from being separated, the code being identical).

This comment has been minimized.

@ekollof

ekollof Dec 20, 2018

Good point. It would be easy to merge that into memory.py. I basically did the same on graph.py. I'll get on that.

return val


class Memory(base.InLoopPollText):
"""Displays memory usage"""
orientations = base.ORIENTATION_HORIZONTAL
defaults = [
("fmt", "{MemUsed}M/{MemTotal}M", "see /proc/meminfo for field names")
("fmt", "{MemUsed}M/{MemTotal}M", "Formatting for field names")

This comment has been minimized.

@ramnes

ramnes Dec 20, 2018

Member

We should then document what fields are available for use exactly, since /proc/meminfo wouldn't be a reference anymore.

This comment has been minimized.

@ekollof

ekollof Dec 20, 2018

I've made them the same as the /proc interface. I'll put them in the docs

This comment has been minimized.

@ramnes

ramnes Dec 20, 2018

Member

My sentence was a continuation to:

Maybe we could accept that config breakage but then expose all the stuff contained in psutil.virtual_memory(), so that people actually can replace what they used to do? We could then drop the useless mapping in names.

Sorry if that wasn't clear!

This comment has been minimized.

@ekollof

ekollof Dec 20, 2018

Oh yeah that. Well, we could use these as general purpose widgets for portability (most people just want CPU/Mem/Swap usage anyway), and maybe keep the old ones for OS-specific hackery? Maybe rename the original one to linux_memory.py (since it is really OS-specific).

ekollof added some commits Dec 20, 2018

@ramnes

This comment has been minimized.

Copy link
Member

ramnes commented Dec 20, 2018

Any reason that you repeat calls like psutil.virtual_memory() rather than keeping and reusing the returned value? I guess it doesn't change much since it's just reading a pseudo-filesystem anyway, but still.

@ekollof

This comment has been minimized.

Copy link

ekollof commented Dec 20, 2018

Good point. I guess I yank and paste faster than I think ;)

I'll change it. Thanks for pointing it out

Show resolved Hide resolved libqtile/widget/memory.py Outdated
Show resolved Hide resolved libqtile/widget/graph.py
Show resolved Hide resolved libqtile/widget/memory.py Outdated

Emiel Kollof and others added some commits Dec 21, 2018

Emiel Kollof
- Merge Swap into Memory
- Port net.py to psutil
- Port NetGraph to psutil
@flacjacket

This comment has been minimized.

Copy link
Member

flacjacket commented Jan 10, 2019

This should be good now, it just needs a rebase!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment