armi.bookkeeping.memoryProfiler module¶
Interface to help diagnose memory issues during debugging/development.
There are many approaches to memory profiling.
1. You can ask psutil for the memory used by the process from an OS perspective. This is great for top-down analysis. This module provides printouts that show info from every process running. This is very fast.
2. You can use asizeof
(part of pympler) to measure the size of various individual objects. This will help
you pin-point your issue. But it’s slow.
3. You can use gc.get_objects()
to list all objects that the garbage collector is tracking. If you want, you
can filter it down and get the counts and sizes of objects of interest (e.g. all armi objects).
This module has tools to do all of this. It should help you out.
Note that if psutil is reporting way more memory usage than the asizeof reports, then you probably are dealing with a garbage collection queue. If you free a large number of objects, call gc.collect() to force a garbage collection and the psutil process memory should fall by a lot. Also, it seems that even if your garbage is collected, Windows does not de-allocate all the memory. So if you are a worker and you just got a 1.6GB reactor but then deleted it, Windows will keep you at 1.6GB for a while.
See Also:
http://packages.python.org/Pympler/index.html https://pythonhosted.org/psutil/ https://docs.python.org/2/library/gc.html#gc.garbage
-
armi.bookkeeping.memoryProfiler.
describeInterfaces
(cs)[source]¶ Function for exposing interface(s) to other code
-
class
armi.bookkeeping.memoryProfiler.
MemoryProfiler
(r, cs)[source]¶ Bases:
armi.interfaces.Interface
Construct an interface.
The
r
andcs
arguments are required, but may beNone
, where appropriate for the specificInterface
implementation.- Parameters
r (Reactor) – A reactor to attach to
cs (Settings) – Settings object to use
- Raises
RuntimeError – Interfaces derived from Interface must define their name
-
name
= 'memoryProfiler'¶
-
displayMemoryUsage
(timeDescription)[source]¶ Print out some information to stdout about the memory usage of ARMI.
Makes use of the asizeof utility.
Useful when the debugMem setting is set to True.
Turn these on as appropriate to find all your problems.
-
_checkForDuplicateObjectsOnArmiModel
(attrName, refObject)[source]¶ Scans thorugh ARMI model for duplicate objects
-
_printFullMemoryBreakdown
(startsWith='armi', reportSize=True, printReferrers=False)[source]¶ looks for any class from any module in the garbage collector and prints their count and size
Very powerful. Also very slow if you reportSize
- Parameters
Notes
Just because you use startsWith=armi doesn’t mean you’ll capture all ARMI objects. Some are in lists and dictionaries.
-
static
getSpecificReferrers
(klass, ancestorKlass)[source]¶ Try to determine some useful information about the structure of ArmiObjects and potential orphans.
This takes a class and an expected/nominal parent class, which should both be instances of ArmiObject. It will then locate all instances of klass that are tracked by the GC, igoring those that have an ancestor of ancestorKlass type. A report will be generated containing the counts of the instances of klass that are _not_ part of the ancestor_class along with their referrer class.
This is useful for diagnosing memory leaks, as it points to unexpected referrers to ArmiObjects.
-
class
armi.bookkeeping.memoryProfiler.
ObjectSizeBreakdown
(name, minMBToShowAttrBreakdown=30.0, excludedAttributes=None, initialZeroes=0)[source]¶ Bases:
object
-
property
size
¶
-
property
-
class
armi.bookkeeping.memoryProfiler.
ProfileMemoryUsageAction
(timeDescription)[source]¶ Bases:
armi.mpiActions.MpiAction
-
invokeHook
()[source]¶ This method must be overridden in sub-clases.
This method is called by worker nodes, and has access to the worker node’s operator, reactor, and settings (through
self.o
,self.r
, andself.cs
). It must return a boolean value ofTrue
orFalse
, otherwise the worker node will raise an exception and terminate execution.- Returns
result – Dependent on implementation
- Return type
-
-
class
armi.bookkeeping.memoryProfiler.
PrintSystemMemoryUsageAction
[source]¶ Bases:
armi.mpiActions.MpiAction
-
property
minProcessMemoryInMB
¶
-
property
maxProcessMemoryInMB
¶
-
invokeHook
()[source]¶ This method must be overridden in sub-clases.
This method is called by worker nodes, and has access to the worker node’s operator, reactor, and settings (through
self.o
,self.r
, andself.cs
). It must return a boolean value ofTrue
orFalse
, otherwise the worker node will raise an exception and terminate execution.- Returns
result – Dependent on implementation
- Return type
-
property