Coder Social home page Coder Social logo

pixelb / ps_mem Goto Github PK

View Code? Open in Web Editor NEW
1.5K 76.0 285.0 114 KB

A utility to accurately report the in core memory usage for a program

License: GNU Lesser General Public License v2.1

Python 94.88% Roff 5.12%
ram memory process usage shared

ps_mem's Introduction

ps_mem

A utility to accurately report the core memory usage for a program

Yes the name is a bit weird. coremem would be more appropriate, but for backwards compatible reasons the ps_mem name remains.

Install:

pip install ps_mem is supported, or rpm and deb packages are available for most distros. Also the ps_mem.py script can be run directly.

Usage:

ps_mem [-h|--help] [-p PID,...] [-s|--split-args] [-t|--total] [-w N]
       [-d|--discriminate-by-pid] [-S|--swap]

Example output:

 Private  +   Shared  =  RAM used       Program

 34.6 MiB +   1.0 MiB =  35.7 MiB       gnome-terminal
139.8 MiB +   2.3 MiB = 142.1 MiB       firefox
291.8 MiB +   2.5 MiB = 294.3 MiB       gnome-shell
272.2 MiB +  43.9 MiB = 316.1 MiB       chrome (12)
913.9 MiB +   3.2 MiB = 917.1 MiB       thunderbird
---------------------------------
                          1.9 GiB
=================================

The [-p PID,...] option allows filtering the results. For example to restrict output to the current $USER you could:

sudo ps_mem -p $(pgrep -d, -u $USER)

or to summarize the total RAM usage per user you could:

for i in $(ps -e -o user= | sort | uniq); do
  printf '%-20s%10s\n' $i $(sudo ps_mem --total -p $(pgrep -d, -u $i))
done

ps_mem's People

Contributors

andresriancho avatar arza-zara avatar elops avatar facundovictor avatar ferringb avatar fightingdreamer avatar gipi avatar harkabeeparolus avatar hmg018 avatar ilyabrin avatar insop avatar io41 avatar jayvdb avatar jrybar-rh avatar ngothan avatar pixelb avatar six-arm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ps_mem's Issues

Hugepage Memory not computed correctly

I have run ps_mem.py on a process and it has negative value in output as that process is using hugepages

python ps_mem.py -d -p 16299
Private + Shared = RAM used Program[pid]

2.0 GiB + -2095209.5 KiB = 4.3 MiB ora_smon_stgtes [16299]

                      4.3 MiB

=================================

cat /proc/16299/smaps_rollup
00400000-ffffffffff601000 ---p 00000000 00:00 0 [rollup]
Rss: 49072 kB
Pss: 4446 kB
Shared_Clean: 46568 kB
Shared_Dirty: 0 kB
Private_Clean: 196 kB
Private_Dirty: 2308 kB
Referenced: 49072 kB
Anonymous: 2308 kB
LazyFree: 0 kB
AnonHugePages: 0 kB
ShmemPmdMapped: 0 kB
Shared_Hugetlb: 90112 kB
Private_Hugetlb: 2097152 kB
Swap: 0 kB
SwapPss: 0 kB
Locked: 0 kB

##kernel Version
4.14.35-1902.301.1.el7uek.x86_64

Huge Page size is 2048Kb but os.sysconf(SC_PAGE_SIZE) is picking 4Kb page size.

grep -i huge /proc/meminfo
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
HugePages_Total: 23764
HugePages_Free: 23764
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB

As per script logic, the automation is not considering hugetlb values and due to that this value is not correctly computed.
Correct me if i am wrong in computing memory value

unable to run script

I'm sorry but could you make an advise please how to run your script on FreeBSD? I try to run it via invoking from CLI from root command: "python ps_mem.py" and have this output:

Traceback (most recent call last):
File "ps_mem.py", line 131, in open
return open(self.path(*args), errors='ignore')
FileNotFoundError: [Errno 2] No such file or directory: '/compat/linux/proc/sys/kernel/osrelease'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "ps_mem.py", line 660, in
if name == 'main': main()
File "ps_mem.py", line 613, in main
verify_environment(pids_to_show)
File "ps_mem.py", line 594, in verify_environment
kernel_ver()
File "ps_mem.py", line 232, in kernel_ver
kv = proc.open('sys/kernel/osrelease').readline().split(".")[:3]
File "ps_mem.py", line 137, in open
raise LookupError
LookupError

[FR] OpenBSD support

right now if i try to run ps_mem.py i get:

./ps_mem.py
Traceback (most recent call last):
  File "./ps_mem.py", line 120, in open
    return open(self.path(*args), errors='ignore')
FileNotFoundError: [Errno 2] No such file or directory: '/proc/sys/kernel/osrelease'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./ps_mem.py", line 629, in <module>
    if __name__ == '__main__': main()
  File "./ps_mem.py", line 582, in main
    verify_environment(pids_to_show)
  File "./ps_mem.py", line 567, in verify_environment
    kernel_ver()
  File "./ps_mem.py", line 221, in kernel_ver
    kv = proc.open('sys/kernel/osrelease').readline().split(".")[:3]
  File "./ps_mem.py", line 126, in open
    raise LookupError
LookupError

Thanks

pip install error on ubuntu:16.04

while using pip install ps_mem I get the following error:

Collecting ps_mem
  Downloading https://files.pythonhosted.org/packages/46/81/ff8429735e2eb13be225dcfabef16d90bfa96b559e3f2643935d33b67697/ps_mem-3.12.tar.gz
Building wheels for collected packages: ps-mem
  Running setup.py bdist_wheel for ps-mem ... error
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-YitmIm/ps-mem/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpNh95GJpip-wheel- --python-tag cp27:
  /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'long_description_content_type'
    warnings.warn(msg)
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help
  
  error: invalid command 'bdist_wheel'
  
  ----------------------------------------
  Failed building wheel for ps-mem
  Running setup.py clean for ps-mem
Failed to build ps-mem
Installing collected packages: ps-mem
  Running setup.py install for ps-mem ... done
Successfully installed ps-mem-3.12

Unify Firefox memory report

Currently ps_mem reports Firefox memory in 3 processes:

 93.9 MiB +  13.0 MiB = 106.9 MiB       WebExtensions
 96.5 MiB +  45.2 MiB = 141.7 MiB       Web Content (3)
164.6 MiB +  31.3 MiB = 195.9 MiB       firefox

All processes are firefox process (ps aux report):

vuk      27853 31.2  2.1 1729288 257304 ?      Sl   23:22   0:06 /usr/lib/firefox-developer-edition/firefox
vuk      27915  8.2  1.1 1470628 135276 ?      Sl   23:22   0:01 /usr/lib/firefox-developer-edition/firefox -contentproc -childID 1 -isForBrowser -prefsLen 1 -prefMapSize 170756 -schedulerPrefs 0001,2 -parentBuildID 20180907104503 -greomni /usr/lib/firefox-developer-edition/omni.ja -appomni /usr/lib/firefox-developer-edition/browser/omni.ja -appdir /usr/lib/firefox-developer-edition/browser 27853 true tab
vuk      27964  9.0  1.0 1509708 133032 ?      Sl   23:22   0:01 /usr/lib/firefox-developer-edition/firefox -contentproc -childID 2 -isForBrowser -prefsLen 173 -prefMapSize 170756 -schedulerPrefs 0001,2 -parentBuildID 20180907104503 -greomni /usr/lib/firefox-developer-edition/omni.ja -appomni /usr/lib/firefox-developer-edition/browser/omni.ja -appdir /usr/lib/firefox-developer-edition/browser 27853 true tab
vuk      28021  3.6  0.8 1438404 100860 ?      Sl   23:22   0:00 /usr/lib/firefox-developer-edition/firefox -contentproc -childID 3 -isForBrowser -prefsLen 4303 -prefMapSize 170756 -schedulerPrefs 0001,2 -parentBuildID 20180907104503 -greomni /usr/lib/firefox-developer-edition/omni.ja -appomni /usr/lib/firefox-developer-edition/browser/omni.ja -appdir /usr/lib/firefox-developer-edition/browser 27853 true tab
vuk      28053  1.1  0.6 1417336 73696 ?       Sl   23:22   0:00 /usr/lib/firefox-developer-edition/firefox -contentproc -childID 4 -isForBrowser -prefsLen 4942 -prefMapSize 170756 -schedulerPrefs 0001,2 -parentBuildID 20180907104503 -greomni /usr/lib/firefox-developer-edition/omni.ja -appomni /usr/lib/firefox-developer-edition/browser/omni.ja -appdir /usr/lib/firefox-developer-edition/browser 27853 true tab

Unify them into firefox

[Feature request] Set one memory usage dimension

At now script output size via most suitable dimension (MiB,KiB,GiB), but when comparing size there are not comfortable. Please add option for fix memory usage dimension, to show, for example, all numbers in Megabytes.

Misformatted output for negative values.

Before:

$ sudo ps_mem -p 10606,7171
 Private  +   Shared  =  RAM used       Program

366.3 MiB + -3939.5 KiB = 362.4 MiB     mpv
445.4 MiB + -29473.5 KiB = 416.6 MiB    firefox
---------------------------------
                        779.1 MiB
=================================

After:

$ sudo ps_mem -p 10606,7171
 Private  +   Shared  =  RAM used       Program

366.3 MiB +  -3.9 MiB = 362.4 MiB       mpv
444.0 MiB + -28.8 MiB = 415.2 MiB       firefox
---------------------------------
                        777.7 MiB
=================================

My fix:

$ diff -Naur ps_mem.py ps_mem
--- ps_mem.py   2014-10-19 20:13:24.762857984 +0000
+++ ps_mem      2014-10-19 20:13:11.342930686 +0000
@@ -299,7 +299,7 @@
 def human(num, power="Ki", units=None):
     if units is None:
         powers = ["Ki", "Mi", "Gi", "Ti"]
-        while num >= 1000: #4 digits
+        while abs(num) >= 1000: #4 digits
             num /= 1024.0
             power = powers[powers.index(power)+1]
         return "%.1f %sB" % (num, power)

I don't speak python and I have no idea if this is the right way to do it.

Incorrect number of processes

Hi, I get this:

1.9 GiB +  16.0 MiB =   1.9 GiB ruby (40)

for my ruby processes but when I run ps aux | grep ruby | wc -l, I get 24, not 40... also it looks like this (a lot of defunct processes)

$ ps aux | grep ruby
david     3084  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david     5114  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    10469  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    10484  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    11420  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    13612  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    15320  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    17353  0.0  1.1 242052 47500 pts/18   Sl+   2014  52:41 ruby /home/david/.rbenv/versions/2.1.2/bin/rackup faye.ru -E production
david    17801  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    17859  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    22542  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    22876  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    23697  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    24419  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    24507  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    26512  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    26653  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    27051  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    27057  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    27655  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    28428  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    28987  0.0  1.9 256912 77896 ?        Sl    2014   0:03 ruby update_db.rb
david    29409  0.0  0.0      0     0 ?        Zs    2014   0:00 [ruby] <defunct>
david    30525  0.0  0.0   7836   836 pts/4    S+   15:10   0:00 grep ruby

what gives?

OSX support

Would be great to have OSX support, thanks :)

Nice tools

Just wanna say thanks, and wanna ask. Any similiar tool for cpu usage?

thanks

add option to remove verbose header and footer (need this for batch scripting)

again apache + php

for PID in $(pgrep -f php-cgi | tr '\n' ' '); do ps_mem --show-cmdline -p $PID; done

I do not need all these captions and sums for all 100 php processes

...

 Private  +   Shared  =  RAM used	Program 

  8.8 MiB + 215.5 KiB =   9.0 MiB	/opt/php73/bin/php-cgi php
---------------------------------
                          9.0 MiB
=================================
 Private  +   Shared  =  RAM used	Program 

  9.9 MiB + 217.5 KiB =  10.1 MiB	/opt/php73/bin/php-cgi php
---------------------------------
                         10.1 MiB
=================================
 Private  +   Shared  =  RAM used	Program 

  8.8 MiB + 215.5 KiB =   9.0 MiB	/opt/php73/bin/php-cgi php
---------------------------------
                          9.0 MiB
=================================
 Private  +   Shared  =  RAM used	Program 

 10.8 MiB + 216.0 KiB =  11.0 MiB	/opt/php73/bin/php-cgi php
---------------------------------
                         11.0 MiB
=================================

individual processes list

I'm tuning apache+php and I have to script it like this

for PID in $(pgrep -f php-cgi | tr '\n' ' '); do ps_mem --show-cmdline -p $PID; done

FreeBSD 11 Error

I'm getting the following error:
Traceback (most recent call last):
File "ps_mem.py", line 623, in
if name == 'main': main()
File "ps_mem.py", line 576, in main
verify_environment(pids_to_show)
File "ps_mem.py", line 561, in verify_environment
kernel_ver()
File "ps_mem.py", line 217, in kernel_ver
kv = proc.open('sys/kernel/osrelease').readline().split(".")[:3]
File "ps_mem.py", line 126, in open
raise LookupError
LookupError

root@sites:/usr/home/ec2-user # uname
FreeBSD

root@sites:/usr/home/ec2-user # freebsd-version
11.1-RELEASE-p8

does not work on ubuntu 20.04 with pip3 install --user

I can install it and it is under $HOME/.local/bin/ps_mem:

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from ps_mem import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

ModuleNotFoundError: No module named 'ps_mem'

it used to fine under ubuntu 18.04 with the same command.

if I do sudo pip3 install ps_mem it works well though.

New release on PyPI ?

Hi,

The release on PyPI is pretty old, could you release a new version ?

Thanks :-)

wrong memory calculation?

Our backup server currently runs and rdiff-backup process which is checking the destination dir and uses a lot of memory. but ps_mem.py does not show it:

root@bserver3:~# ps_mem.py
Private + Shared = RAM used Program

180.0 KiB + 36.5 KiB = 216.5 KiB acpid
192.0 KiB + 28.5 KiB = 220.5 KiB atd
232.0 KiB + 34.5 KiB = 266.5 KiB rpc.idmapd
200.0 KiB + 73.0 KiB = 273.0 KiB pv (2)
152.0 KiB + 144.5 KiB = 296.5 KiB sh (3)
280.0 KiB + 52.0 KiB = 332.0 KiB upstart-file-bridge
260.0 KiB + 78.5 KiB = 338.5 KiB upstart-udev-bridge
288.0 KiB + 66.0 KiB = 354.0 KiB cron
360.0 KiB + 53.5 KiB = 413.5 KiB upstart-socket-bridge
324.0 KiB + 99.5 KiB = 423.5 KiB rpcbind
352.0 KiB + 142.5 KiB = 494.5 KiB systemd-logind
300.0 KiB + 206.5 KiB = 506.5 KiB pickup
336.0 KiB + 208.5 KiB = 544.5 KiB qmgr
352.0 KiB + 201.5 KiB = 553.5 KiB master
576.0 KiB + 56.5 KiB = 632.5 KiB dbus-daemon
544.0 KiB + 110.0 KiB = 654.0 KiB rpc.statd
764.0 KiB + 75.5 KiB = 839.5 KiB systemd-udevd
836.0 KiB + 114.0 KiB = 950.0 KiB ntpd
956.0 KiB + 166.5 KiB = 1.1 MiB bacula-fd
1.1 MiB + 188.5 KiB = 1.3 MiB rbackup
1.1 MiB + 298.0 KiB = 1.4 MiB getty (7)
1.5 MiB + 142.5 KiB = 1.6 MiB init
1.3 MiB + 359.5 KiB = 1.6 MiB ssh
1.4 MiB + 332.5 KiB = 1.7 MiB screen (2)
1.9 MiB + 69.0 KiB = 1.9 MiB rsyslogd
1.8 MiB + 322.5 KiB = 2.1 MiB bacula-dir
2.0 MiB + 1.1 MiB = 3.1 MiB sshd (2)
2.5 MiB + 704.0 KiB = 3.2 MiB iscsid (2)
3.5 MiB + 78.0 KiB = 3.5 MiB snmpd
2.9 MiB + 791.5 KiB = 3.7 MiB multipathd
3.5 MiB + 779.0 KiB = 4.3 MiB bash (3)
12.9 MiB + 3.3 MiB = 16.2 MiB postgres (6)

40.1 MiB + 1.0 MiB = 41.1 MiB rdiff-backup

                     95.9 MiB

root@bserver3:~# free -m
total used free shared buffers cached
Mem: 64433 64087 346 12 6 690
-/+ buffers/cache: 63389 1043
Swap: 2047 0 2047

root@bserver3:~# ps -eo rss,cmd --sort=rss | tail -n 3 | cut -b -50
5252 /sbin/multipathd
16092 /usr/lib/postgresql/9.3/bin/postgres -D /var
44264 /usr/bin/python /usr/bin/rdiff-backup --term

Option for one unit size

It's very hard to parse the output, because we need to differentiate KiB and GiB, convert them to use in automation, monitoring tools etc.
Can we please have an option to use only MiB's or B's?

Publish to pypi..

I think it would be good if this can be installed with just

pip install ps_mem

error in freebsd 8.2

i have error like this

 Private  +   Shared  =  RAM used       Program

Traceback (most recent call last):
  File "./ps_mem.py", line 494, in <module>
    sorted_cmds, shareds, count, total = get_memory_usage( pids_to_show, split_args )
  File "./ps_mem.py", line 396, in get_memory_usage
    cmd = getCmdName(pid, split_args)
  File "./ps_mem.py", line 261, in getCmdName
    cmdline = proc.open(pid, 'cmdline').read().split("\0")
IOError: [Errno 14] Bad address

i use freebsd 8.2.

Shared and Private memories

I checked your assumption that "Shared + Private = Rss" (for one pid) and got 4 or 8 KB inequality. Do you have any idea why it's so? I tried that several times and this inequality is always present.

Remote machine support

I would like to use this with some embedded targets where python isn't an option. I was able to hack something up to get the proc PID files onto a machine with python. Then I was able to change the proc.path/proc.open functions to be something that runs from the current directory to generate results based off the local files rather than local running machine.

I had to just skip the exe check to get it to work as well.

Would other people find this useful as a pull request?

No header for swap pss

Hello.
In "show swap" mode only one column header print for two columns.
`
ps_mem --swap
Private + Shared = RAM used Swap used Program

192.0 KiB + 38.0 KiB = 230.0 KiB 0.0 KiB 0.0 KiB acpid
232.0 KiB + 76.0 KiB = 308.0 KiB 0.0 KiB 0.0 KiB atd
292.0 KiB + 51.5 KiB = 343.5 KiB 0.0 KiB 0.0 KiB agetty
`
I think that becouse function "print_header" calls before variable "have_swap_pss" set in function "getMemStats".

Optionally split processes by user owner in report

In multi-user instance ps_mem group all process with same name to one line, even if they have different owner (user). So, if I have 3 logged in users with separate firefox process - I see the sum of all processes, and can't understand firefox from each user eats more memory.

For solve this problem can you add option for split processes by user owner in report?

If I run an application which has shared library twice, almost double shared memory is consumed

Hi all.
I'm using Linux, however don't know well about shared memory and shared library concept.
I'd like to use ps_mem to calculate and analyze my application's memory usage but I got a question.

My application uses a big shared library. (.so files)
It's architecture is as below:

  1. My application is composed of part A and B.
  2. A is run as a process.
  3. A forks B, so that B is run as another process.
  4. A can forks B many times.
  5. B uses a big shared library C.

Case 1: A forks B once.

 10.6 MiB + 614.5 KiB =  11.2 MiB       A
106.0 MiB +  28.5 MiB = 134.4 MiB       B

Case 2: A forks B twice.

 12.6 MiB + 432.5 KiB =  13.0 MiB       A
180.6 MiB +  59.3 MiB = 239.9 MiB       B (2)

Case 3: A forks B three times.

 14.6 MiB + 350.5 KiB =  15.0 MiB       A
270.5 MiB +  74.1 MiB = 344.6 MiB       B (3)

I thought that the big shared library, C might be shared, so that B's shared memory size might be almost same.
But, according to the test result, its size might be multiplied as the number of forks.

Why is the shared size multiplied?

Accurate reporting for host machine - when inside a docker container

I was trying to use ps_mem inside a glances container to write logs in response to alerts.
The glances docker container that I ran ps_mem inside of has full access to the host and shows processes correctly. Unfortunately, ps_mem did not list the actual processes from the host.

Is there a trick to make this work as is? or would it be a feature request?

Show cumulatve memory usage by process name

Would it be possible to show the cumulative memory usage by process name, e.g., for opera or chrome where multiple processes are spawned?

Currently it's possible to use -w along with the full (and cumulative) list of all processes. It would be great if this can be done for a single process by name.

Total memory in a more useful format

I would like to get the total memory used in a usable format for scripting, E.g. echo $used_mem - $(ps_mem.py -t) | bc -- to get how much memory is unaccounted for. But ps_mem returns something like 609MiB or 2.1GiB which is not very helpful for scripting.

Can a switch be added to just return a float number?

Maybe something like by default return human readable format and also add:

  -k - return total used memory as a float of kilobytes
  -m - return total used memory as a float of megabytes

Windows 7 error

$ ver && python -V
Microsoft Windows [Version 6.1.7601]
Python 3.8.8

$ pip install ps_mem                               
Collecting ps_mem                                                                   
  Downloading ps_mem-3.12.tar.gz (18 kB)                                            
Using legacy 'setup.py install' for ps-mem, since package 'wheel' is not installed. 
Installing collected packages: ps-mem                                               
    Running setup.py install for ps-mem ... done                                    
Successfully installed ps-mem-3.12

$ ps_mem
Traceback (most recent call last):                                                 
  File "C:\Python\Scripts\ps_mem-script.py", line 33, in <module>                  
    sys.exit(load_entry_point('ps-mem==3.12', 'console_scripts', 'ps_mem')())      
  File "C:\Python\Scripts\ps_mem-script.py", line 25, in importlib_load_entry_point
    return next(matches).load()                                                    
  File "c:\python\lib\importlib\metadata.py", line 77, in load                     
    module = import_module(match.group('module'))                                  
  File "c:\python\lib\importlib\__init__.py", line 127, in import_module           
    return _bootstrap._gcd_import(name[level:], package, level)                    
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import                  
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load                
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked       
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked                
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module          
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed     
  File "c:\python\lib\site-packages\ps_mem.py", line 98, in <module>               
    PAGESIZE = os.sysconf("SC_PAGE_SIZE") / 1024 #KiB                              
AttributeError: module 'os' has no attribute 'sysconf'                             

Bug: Erroneous Memusage

I have 2x8Gb's of ram on my desktop.

With that being said, I assume total memory usage should be lesser than 16Gb.

But ps_mem shows me some numbers above that range:

screencast.mp4

output is not redirected to the log file if it got killed

While running 'timeout 7 ps_mem -w 1 > log' on aarch64, ppc64le and ppc64 the output of the command is not redirected to the log file if it got killed. On x86_64 and s390x the output is caught in the file.

Steps to Reproduce:

  1. timeout 7 ps_mem -w 1 > log

Actual results:
The log file doesn't contain any output

Expected results:
The log file contains output of the ps_mem command

miscalculated ram of firefox

Fedora 35 - x86_64 - kernel-5.15.2-200 - firefox-94, ps_men is latest git code: 3759690

# ps_mem.py 
 Private  +   Shared  =  RAM used       Program

204.0 KiB +  22.5 KiB = 226.5 KiB       gpm
188.0 KiB +  62.5 KiB = 250.5 KiB       xinit
252.0 KiB +  32.5 KiB = 284.5 KiB       mcelog
292.0 KiB +  79.5 KiB = 371.5 KiB       wmclock
344.0 KiB +  91.5 KiB = 435.5 KiB       irqbalance
360.0 KiB +  76.5 KiB = 436.5 KiB       wmmon
368.0 KiB + 118.5 KiB = 486.5 KiB       rtkit-daemon
460.0 KiB + 278.5 KiB = 738.5 KiB       alsactl
908.0 KiB +  68.5 KiB = 976.5 KiB       crond
988.0 KiB + 141.5 KiB =   1.1 MiB       chronyd
740.0 KiB + 456.5 KiB =   1.2 MiB       sd_dummy
  1.0 MiB + 458.5 KiB =   1.4 MiB       wmix
  1.1 MiB + 430.5 KiB =   1.5 MiB       gvfsd-fuse
  1.7 MiB +  29.5 KiB =   1.7 MiB       dhclient
  1.4 MiB + 375.5 KiB =   1.8 MiB       gvfsd
  1.1 MiB + 730.5 KiB =   1.8 MiB       su
  1.2 MiB + 704.5 KiB =   1.9 MiB       login
  1.8 MiB + 143.5 KiB =   2.0 MiB       smartd
  1.3 MiB + 756.5 KiB =   2.1 MiB       systemd-logind
  1.6 MiB + 505.5 KiB =   2.1 MiB       upowerd
  1.6 MiB + 630.5 KiB =   2.2 MiB       sshd
  1.9 MiB + 308.0 KiB =   2.2 MiB       dbus-broker (2)
  1.6 MiB + 599.0 KiB =   2.2 MiB       dbus-broker-launch (2)
  2.2 MiB +  57.5 KiB =   2.3 MiB       speech-dispatcher
  2.6 MiB + 510.5 KiB =   3.1 MiB       wpa_supplicant
  2.8 MiB + 408.5 KiB =   3.2 MiB       cupsd
  2.8 MiB + 573.5 KiB =   3.3 MiB       systemd-udevd
  3.0 MiB + 535.5 KiB =   3.6 MiB       sd_espeak-ng
  3.7 MiB + 526.5 KiB =   4.2 MiB       colord
  1.6 MiB +   2.6 MiB =   4.2 MiB       systemd-journald
  3.3 MiB +   2.2 MiB =   5.5 MiB       rsyslogd
  7.2 MiB +   4.0 MiB =  11.2 MiB       systemd (3)
 10.9 MiB +   1.6 MiB =  12.5 MiB       pulseaudio
 10.6 MiB +   1.9 MiB =  12.5 MiB       wmaker (2)
 12.3 MiB + 653.5 KiB =  12.9 MiB       polkitd
 11.6 MiB +   1.5 MiB =  13.1 MiB       bash (6)
 25.4 MiB +  13.4 MiB =  38.8 MiB       Xorg
 40.4 MiB +   4.3 MiB =  44.7 MiB       konsole
197.6 MiB +  26.1 MiB = 223.7 MiB       thunderbird (2)
368.5 MiB +  78.7 MiB = 447.2 MiB       firefox (9)
442.6 MiB +  23.4 MiB = 466.0 MiB       GeckoMain
---------------------------------
                          1.3 GiB
=================================

GeckoMain is a firefox thread/process. It should be added to it.

Thank you.

Incorrect total on Ubuntu 20.04 (Shows 20.4 GiB used and free shows 9.7GiB used)

craig@home:~ (master)$ ps_mem | head -2
 Private  +   Shared  =  RAM used	Program

craig@home:~ (master)$ ps_mem | tail -3
---------------------------------
                         20.2 GiB
=================================
craig@home:~ (master)$ free -h
              total        used        free      shared  buff/cache   available
Mem:           62Gi       9.5Gi        12Gi       419Mi        40Gi        52Gi
Swap:            0B          0B          0B
craig@home:~ (master)$ uname -a
Linux home 5.9.16-050916-generic #202012211331 SMP Mon Dec 21 14:11:13 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

craig@home:~ (master)$ ps_mem --version
3.12

Also tested with 3.13 (downloaded, but not showing in pip) with same results.

ADD identify actual java app name

since most Java (Eclipse fw based apps I use) use their own packaged java binary to run themselves, these show up as plain java in ps_mem:

545.6 MiB +   1.3 MiB = 546.9 MiB	java [updated]
 22.6 GiB +  12.0 MiB =  22.6 GiB	java (2)

for the main use case of ps_mem (identifying what app is using what amount of physical memory), I believe it to be useful to distinguish different java apps

in my instance what makes up the ps_mem group 'java' are completely different apps:

/opt/clion/jbr/bin/java
/opt/datagrip/jbr/bin/java
/opt/dataspell/jbr/bin/java
/opt/goland/jbr/bin/java
/opt/intellij-idea-community/jbr/bin/java
/opt/intellij-idea-ultimate/jbr/bin/java
/opt/phpstorm/jbr/bin/java
/opt/pycharm-professional/jbr/bin/java
/opt/rider/jbr/bin/java
/opt/rubymine/jbr/bin/java
/opt/webstorm/jbr/bin/java
/usr/share/dbeaver-ce/jre/bin/java
/usr/share/dbeaver/jre/bin/java
etc..

..so a lot of context is lost by grouping them under their binary runners name ('java')

Importing ps_mem in ipython crashes the interpreter

To reproduce
sudo $(which ipython)

import ps_mem
ps_mem.main()

prints to STDOUT the table, but says about STDOUT:

Error in sys.excepthook:

Original exception was:

Using
Kubuntu 18.04
Linux 5.0.x
iPython 7.12.0
python 3.6.9

However, in python 3 default interpreter works without a crash.

Not reporting Swap on Ubuntu 16.04

Getting error "Warning: Swap is not reported by this system"

OS: Ubuntu 16.04.

free
total used free shared buff/cache available
Mem: 1016056 281732 94528 67752 639796 459000
Swap: 1048572 184044 864528

cat /proc/swaps
Filename Type Size Used Priority
/swapfile file 1048572 184488 -1

Let me know what debugging info you need. My python isn't good enough to see what the script is looking for. Running as root, so should have full permissions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.