diff options
author | Mattias Andrée <maandree@kth.se> | 2019-10-10 22:02:17 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2019-10-10 22:02:17 +0200 |
commit | 42483cf2421b21795a81f2c78e5c4d8bc32ed7bb (patch) | |
tree | 460ca22ce4714f4be5d697e189179b9a9d98e58b /src | |
parent | Fix typo (diff) | |
download | xpybar-42483cf2421b21795a81f2c78e5c4d8bc32ed7bb.tar.gz xpybar-42483cf2421b21795a81f2c78e5c4d8bc32ed7bb.tar.bz2 xpybar-42483cf2421b21795a81f2c78e5c4d8bc32ed7bb.tar.xz |
Update mem.py
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/mem.py | 140 |
1 files changed, 97 insertions, 43 deletions
diff --git a/src/plugins/mem.py b/src/plugins/mem.py index de30d7e..a480110 100644 --- a/src/plugins/mem.py +++ b/src/plugins/mem.py @@ -56,21 +56,21 @@ class Memory: line = filter(lambda x : not x == '', line.replace(':', ' ').split(' ')) line = list(line)[:2] self.__info[line[0]] = int(line[1]) - + self.keys = self.__info.keys() self.mem_total = self['MemTotal'] - self.mem_free = self['MemFree'] self.buffers = self['Buffers'] self.cached = self['Cached'] - self.mem_used = self.mem_total - (self.mem_free + self.buffers + self.cached) + self.mem_free = self['MemFree'] + self.buffers + self.cached + self.get('KReclaimable', self.get('SReclaimable')) + self.mem_used = self.mem_total - self.mem_free self.swap_cached = self['SwapCached'] self.swap_total = self['SwapTotal'] self.swap_free = self['SwapFree'] self.swap_used = self.swap_total - (self.swap_free + self.swap_cached) - self.shmem = self['Shmem'] if 'Shmem' in self else None - self.slab = self['Slab'] if 'Slab' in self else None - self.hardware_corrupted = self['HardwareCorrupted'] if 'HardwareCorrupted' in self else None + self.shmem = self.get('Shmem', None) + self.slab = self.get('Slab', None) + self.hardware_corrupted = self.get('HardwareCorrupted', None) def __contains__(self, key): @@ -81,48 +81,102 @@ class Memory: @return :bool The availability ''' return key in self.__info - - - def __getitem__(self, key): + + + def get(self, key, default = 0): ''' Look up a field from '/proc/meminfo' - @param key:str The field name - @return :int The value of the field, without the unit (KB if any) + @param key:str The field name + @param default:int The value to return if the field does not exist + @return :int The value of the field, without the unit (KB if any) This keys should be available, but are most probably more available: - @key MemTotal Total usable RAM (physical RAM minus a few reserved bit minus kernel binary code) - @key MemFree Amount of unused usable physical RAM - @key Buffers Relatively temporary storage for raw disc blocks - @key Cached In-memory cache for files read from the disc (the pagecache). - Does not include SwapCached. - @key SwapCached Memory that once was swapped out, is swapped - back in but still also is in the swapfile - @key Active Memory that has been used more recently and - usually not reclaimed unless absolutely necessary - @key Inactive Memory which has been less recently used. It is - more eligible to be reclaimed for other purposes - @key SwapTotal Total amount of swap space available - @key SwapFree Amount of unused swap space available - @key Dirty Memory which is waiting to get written back to the disc - @key Writeback Memory which is actively being written back to the disc - @key AnonPages Non-file backed pages mapped into userspace page tables - @key Mapped Files which have been mmaped, such as libraries - @key Slab In-kernel data structures cache - @key SReclaimable Part of Slab, that might be reclaimed, such as caches - @key SUnreclaim Part of Slab, that cannot be reclaimed on memory pressure - @key PageTables Amount of memory dedicated to the lowest level of page tables - @key NFS_Unstable NFS pages sent to the server, but not yet committed to stable storage - @key Bounce Memory used for block device “bounce buffers” - @key WritebackTmp Memory used by FUSE for temporary writeback buffers - @key CommitLimit The total amount of memory currently available to be allocated - on the system. Based on overcommit ratio. - @key Committed_AS The amount of memory presently allocated on the system. - @key VmallocTotal Total size of vmalloc memory area - @key VmallocUsed Amount of vmalloc area which is used - @key VmallocChunk Largest contiguous block of vmalloc area which is free - @key AnonHugePages Non-file backed huge pages mapped into userspace page tables + @key MemTotal Total usable RAM (physical RAM minus a few reserved bit minus kernel binary code) + @key MemFree Amount of unused usable physical RAM + @key MemAvailable An estimate of how much memory is available for starting new applications, without swapping + @key Buffers Relatively temporary storage for raw disc blocks + @key Cached In-memory cache for files read from the disc (the pagecache). + Does not include SwapCached. + @key SwapCached Memory that once was swapped out, is swapped + back in but still also is in the swapfile + @key Active Memory that has been used more recently and + usually not reclaimed unless absolutely necessary + @key Inactive Memory which has been less recently used. It is + more eligible to be reclaimed for other purposes + @key Active(anon) [To be documented.] + @key Inactive(anon) [To be documented.] + @key Active(file) [To be documented.] + @key Inactive(file) [To be documented.] + @key Unevictable [To be documented.] + @key Mlocked [To be documented.] + @key HighTotal Total amount of highmem. Highmem is all memory above ~860MB of physical + memory. Highmem areas are for use by user-space programs, or for the page + cache. The kernel must use tricks to access this memory, making it slower + to access than lowmem. + @key HighFree Amount of free highmem + @key LowTotal Total amount of lowmem. Lowmem is memory which can be used for everything + that highmem can be used for, but it is also available for the kernel's use + for its own data structures. Among many other things, it is where everything + from Slab is allocated. Bad things happen when you're out of lowmem. + @key LowFree Amount of free lowmem + @key MmapCopy [To be documented.] + @key SwapTotal Total amount of swap space available + @key SwapFree Amount of unused swap space available + @key Dirty Memory which is waiting to get written back to the disc + @key Writeback Memory which is actively being written back to the disc + @key AnonPages Non-file backed pages mapped into userspace page tables + @key Mapped Files which have been mmaped, such as libraries + @key Shmem Amount of memory consumed in tmpfs(5) filesystems + @key KReclaimable Kernel allocations that the kernel will attempt to reclaim under memory + pressure. Includes SReclaimable, and other direct allocations with a shrinker. + @key Slab In-kernel data structures cache + @key SReclaimable Part of Slab, that might be reclaimed, such as caches + @key SUnreclaim Part of Slab, that cannot be reclaimed on memory pressure + @key KernelStack Amount of memory allocated to kernel stacks + @key PageTables Amount of memory dedicated to the lowest level of page tables + @key Quicklists [To be documented.] + @key NFS_Unstable NFS pages sent to the server, but not yet committed to stable storage + @key Bounce Memory used for block device “bounce buffers” + @key WritebackTmp Memory used by FUSE for temporary writeback buffers + @key CommitLimit The total amount of memory currently available to be allocated + on the system. Based on overcommit ratio. + @key Committed_AS The amount of memory presently allocated on the system. + @key VmallocTotal Total size of vmalloc memory area + @key VmallocUsed Amount of vmalloc area which is used + @key VmallocChunk Largest contiguous block of vmalloc area which is free + @key Percpu [To be documented.] + @key HardwareCorrupted [To be documented.] + @key LazyFree Shows the amount of memory marked by madvise(2) MADV_FREE + @key AnonHugePages Non-file backed huge pages mapped into userspace page tables + @key ShmemHugePages Memory used by shared memory (shmem) and tmpfs(5) allocated with huge pages + @key ShmemPmdMapped Shared memory mapped into user space with huge pages + @key CmaTotal Total CMA (Contiguous Memory Allocator) pages + @key CmaFree Free CMA (Contiguous Memory Allocator) pages + @key HugePages_Total The size of the pool of huge pages + @key HugePages_Free The number of huge pages in the pool that are not yet allocated + @key HugePages_Rsvd This is the number of huge pages for which a commitment to allocate from + the pool has been made, but no allocation has yet been made. These reserved + huge pages guarantee that an application will be able to allocate a huge + page from the pool of huge pages at fault time + @key HugePages_Surp This is the number of huge pages in the pool above the value in + /proc/sys/vm/nr_hugepages. The maximum number of surplus huge pages is + controlled by /proc/sys/vm/nr_overcommit_hugepages. + @key Hugepagesize The size of huge pages + @key Hugetlb [To be documented.] + @key DirectMap4k Number of bytes of RAM linearly mapped by kernel in 4kB pages + @key DirectMap2M Number of bytes of RAM linearly mapped by kernel in 2MB pages + @key DirectMap4M Number of bytes of RAM linearly mapped by kernel in 4MB pages + @key DirectMap1G Number of bytes of RAM linearly mapped by kernel in 1GB pages ''' - return self.__info[key] + return self.__info.get(key, default) + + def __getitem__(self, key): + ''' + Equivalent to `self.get(key)`, except + it fails rather than return 0 if the + field does not exist + ''' + return self.__info[key] |