Get resource usage of process¶
AUTHORS:
- William Stein (2006-03-04): initial version
-
sage.misc.getusage.
VmB
(VmKey)¶ Function used internally by this module.
-
sage.misc.getusage.
get_memory_usage
(t=None)¶ Return memory usage.
INPUT:
t
- a float (default: None); output of an earlier call
OUTPUT:
Linux
- Returns float number (in megabytes)OS X
- Returns float number (in megabytes) that matches VSIZE column oftop
Solaris or OpenSolaris
- Returns float number (in megabytes) that matches RSS column ofprstat
. Depending on the memory usage,prstat
will output the data in KB, MB or GB. In each case, the value returned by this function will always be in MB.FreeBSD
- Returns float number (in megabytes) that matches RSS column ofps -auxwww
other
- not implemented for any other operating systems
EXAMPLES:
sage: t = get_memory_usage(); t # random 873.98046875
Note
- Currently,
get_memory_usage()
callsprstat
on Solaris and OpenSolaris to get the data it requires. In the long term, a better solution would be to use Solaris system calls. - In some instances,
top
may be used on OS X. This may break if the memory usage is greater than 9999 MB. However, normallytop
is not used on OS X.
-
sage.misc.getusage.
linux_memory_usage
()¶ Return memory usage in megabytes.
-
sage.misc.getusage.
top
()¶ Return the ‘top’ or ‘prstat’ line that contains this running Sage process. For FreeBSD, return the line containing this running Sage process from ‘ps -axwww -o pid,user,vsz,rss,state,pri,nice,time,cpu,comm’.
OUTPUT:
- a string
EXAMPLES:
sage: top() # random output '72373 python 0.0% 0:01.36 1 14+ 1197 39M+ 34M+ 55M+ 130M+'
NOTES:
The external command ‘top’ (http://www.unixtop.org/) is called on Linux, and most other operating systems. The output format of ‘top’ is not consistent across all platforms and all versions of ‘top’. If the
top()
function does not work in Sage, you may need to install ‘top’.The external command ‘prstat’ is called on the Solaris and OpenSolaris systems. That is part of Solaris, and will not need to be installed. The columns used in the ‘prstat’ output are:
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP