HWRF  trunk@4391
Classes | Functions | Variables
produtil.rusage Namespace Reference

This module allows querying resource usage and limits, as well as setting resource limits. More...

Detailed Description

This module allows querying resource usage and limits, as well as setting resource limits.

It is a wrapper around the Python resource module.

Setting resource limits:

1 use logging, produtil.rusage
2 logger=logging.logger("rusage")
3 produtil.rusage.setrlimit(logger,data=1e9,nofile=500,aspace=2e9,stack=5e8)

Printing resource limits to a logger:

1 use logging, produtil.rusage
2 logger=logging.logger("rusage")
3 u.produtil.rusage.getrlimit(logger) # writes the limits to the logger
4 # Limits are also in the returned object "u"
5 # Send None instead of logger to avoid logging.

Classes

class  RLimit
 Gets the resource limits set on this process: core, cpu, fsize, data, stack, rss, nproc, nofile, memlock, aspace Each is set to a tuple containing the soft and hard limit. More...
 
class  RUsage
 Contains resource usage (rusage) information that can be used with a Python "with" construct to collect the resources utilized by a block of code, or group of subprocesses executing during that block. More...
 
class  RUsageReport
 Raised when caller makes an RUsage, and tries to generate its report, before calling its enter or exit routines. More...
 

Functions

def setrlimit (logger=None, ignore=False, hard=False, kwargs)
 Sets resource limits. More...
 
def getrlimit
 Gets the current resource limits. More...
 

Variables

tuple rtypemap
 Maps the name used in this module for each resource class to the name used by the Python resource module. More...
 
tuple rnamemap
 Maps the name used in this module for each resource class, to a short human-readable string explaining the resource's meaning. More...
 
tuple rusage_keys
 A tuple containing all rusage keys. More...
 
tuple rusage_meanings
 A mapping from rusage key to a human-readable explanation of the meaning. More...
 
 rusage = RUsage
 Alias for produtil.rusage.RUsage.
 

Function Documentation

def produtil.rusage.getrlimit (   logger = None)

Gets the current resource limits.

If logger is not None, sends the limits to the logger at level INFO.

Returns
a RLimit object with resource information

Definition at line 132 of file rusage.py.

Referenced by hwrf.init.HWRFInit.run_init_after_anl(), pom.init.fbtr.setrun(), pom.init.g3.setrun(), and pom.init.na.setrun().

def produtil.rusage.setrlimit (   logger = None,
  ignore = False,
  hard = False,
  kwargs 
)

Sets resource limits.

Parameters
ignoreIf ignore=True, ignores any errors from getrlimit or setrlimit.
hardIf hard=True, attempts to set hard limits, which generally requires administrator privileges.
loggerThe logger argument sets the logger (default: produtil.setrlimit logging domain).
kwargsThe kwargs should be a list of resource limits. Accepted resource limits:
  • core = core file size (RLIMIT_CORE)
  • cpu = max. cpu usage (RLIMIT_CPU)
  • fsize = max. file size (RLIMIT_FSIZE)
  • data = max. heap size (RLIMIT_DATA)
  • stack = max. stack size (RLIMIT_STACK)
  • rss = max. resident set size (RLIMIT_RSS)
  • nproc = max. processes (RLIMIT_NPROC)
  • nofile = max. open files (RLIMIT_NOFILE or RLIMIT_OFILE)
  • memlock= max locked memory (RLIMIT_MEMLOCK)
  • aspace = max. address space (RLIMIT_AS) See "man setrlimit" for details.

Definition at line 60 of file rusage.py.

Referenced by pom.init.fbtr.setrun(), pom.init.g3.setrun(), and pom.init.na.setrun().

Variable Documentation

produtil.rusage.rnamemap
Initial value:
1 = dict(core='core file size',
2  cpu='cpu usage',
3  fsize='max. file size',
4  data='max. heap size',
5  stack='max. stack size',
6  rss='max. resident set size',
7  nproc='max. processes',
8  nofile='max. open files',
9  #ofile='max. open files (BSD)',
10  memlock='max. locked memory',
11  #vmem='max. virtual memory',
12  aspace='max. address space')

Maps the name used in this module for each resource class, to a short human-readable string explaining the resource's meaning.

Definition at line 45 of file rusage.py.

produtil.rusage.rtypemap
Initial value:
1 = dict(core=resource.RLIMIT_CORE,
2  cpu=resource.RLIMIT_CPU,
3  fsize=resource.RLIMIT_FSIZE,
4  data=resource.RLIMIT_DATA,
5  stack=resource.RLIMIT_STACK,
6  rss=resource.RLIMIT_RSS,
7  nproc=resource.RLIMIT_NPROC,
8  nofile=resource.RLIMIT_NOFILE,
9  #ofile=resource.RLIMIT_OFILE,
10  memlock=resource.RLIMIT_MEMLOCK,
11  #vmem=resource.RLIMIT_VMEM,
12  aspace=resource.RLIMIT_AS)

Maps the name used in this module for each resource class to the name used by the Python resource module.

Definition at line 27 of file rusage.py.

produtil.rusage.rusage_keys
Initial value:
1 = ('ru_utime','ru_stime','ru_maxrss','ru_ixrss','ru_idrss',
2  'ru_isrss','ru_minflt','ru_majflt','ru_nswap','ru_inblock',
3  'ru_oublock','ru_msgsnd','ru_msgrcv','ru_nsignals',
4  'ru_nvcsw','ru_nivcsw')

A tuple containing all rusage keys.

Definition at line 144 of file rusage.py.

produtil.rusage.rusage_meanings
Initial value:
1 = dict(ru_utime='time in user mode',
2  ru_stime='time in system mode',
3  ru_maxrss='maximum resident set size',
4  ru_ixrss='shared memory size',
5  ru_idrss='unshared memory size',
6  ru_isrss='unshared stack size',
7  ru_minflt='page faults not requiring I/O',
8  ru_majflt='page faults requiring I/O',
9  ru_nswap='number of swap outs',
10  ru_inblock='block input operations',
11  ru_oublock='block output operations',
12  ru_msgsnd='messages sent',
13  ru_msgrcv='messages received',
14  ru_nsignals='signals received',
15  ru_nvcsw='voluntary context switches',
16  ru_nivcsw='involuntary context switches')

A mapping from rusage key to a human-readable explanation of the meaning.

Definition at line 152 of file rusage.py.