Function asizeof calculates the combined (approximate) size
in bytes of one or several Python objects.
Function asizesof returns a tuple containing the (approximate)
size in bytes for each given Python object separately.
Function asized returns for each object an instance of class
Asized containing all the size information of the object and a
tuple with the referents.
Functions basicsize and itemsize return the basic respectively
item size of the given object.
Function flatsize returns the flat size of a Python object in
bytes defined as the basic size plus the item size times the
length of the given object.
Function leng returns the length of an object, like standard
len but extended for several types, e.g. the leng of a multi-
precision int (or long) is the number of digits [3]. The length
of most mutable sequence objects includes an estimate of the
over-allocation and therefore, the leng value may differ from
the standard len result.
Function refs returns (a generator for) the referents of the
given object, i.e. the objects referenced by the given object.
Function calcsize is equivalent to standard struct.calcsize
but handles format characters 'z' for signed C type Py_ssize_t
and 'Z' for unsigned C type size_t.
Certain classes are known to be sub-classes of or to behave as
dict objects. Function adict can be used to install other
class objects to be treated like dict.
The size of an object is defined as the sum of the flat size
of the object plus the sizes of any referents. Referents are
visited recursively up to a given limit. However, the size
of objects referenced multiple times is included only once.
The flat size of an object is defined as the basic size of the
object plus the item size times the number of allocated items.
The flat size does include the size for the items (references
to the referents), but not the referents themselves.
The flat size returned by function flatsize equals the result
of the asizeof function with options code=True, ignored=False,
limit=0 and option align set to the same value.
The accurate flat size for an object is obtained from function
sys.getsizeof() where available. Otherwise, the length and
size of sequence objects as dicts, lists, sets, etc. is based
on an estimate for the number of allocated items. As a result,
the reported length and size may substantially differ from the
actual length and size.
The basic and item sizes are obtained from the __basicsize__
respectively __itemsize__ attribute of the (type of the) object.
Where necessary (e.g. sequence objects), a zero __itemsize__
is replaced by the size of a corresponding C type.
The basic size (of GC managed objects) objects includes the
overhead for Python's garbage collector (GC) as well as the
space needed for refcounts (only in certain Python builds).
Optionally, sizes can be aligned to any power of 2 multiple.
To avoid excessive sizes, several object types are ignored [4]
by default, e.g. built-in functions, built-in types and classes
[5], function globals and module referents. However, any
instances thereof are sized and module objects will be sized
when passed as given objects. Ignored object types are included
if option ignored is set accordingly.
In addition, many __...__ attributes of callable objects are
ignored, except crucial ones, e.g. class attributes __dict__,
__doc__, __name__ and __slots__. For more details, see the
type-specific _..._refs() and _len_...() functions below.
Option all can be used to size all Python objects and/or get
the referents from gc.get_referents() and override the type-
specific __..._refs() functions.
|
|
calcsize(fmt)
struct.calcsize() handling 'z' for signed Py_ssize_t and 'Z' for unsigned size_t. |
source code
|
|
|
|
_items(obj)
Return iter-/generator, preferably. |
source code
|
|
|
|
_keys(obj)
Return iter-/generator, preferably. |
source code
|
|
|
|
_values(obj)
Use iter-/generator, preferably. |
source code
|
|
|
|
_kwds(**kwds)
Return name=value pairs as keywords dict. |
source code
|
|
|
|
_basicsize(t,
base=0,
heap=False,
obj=None)
Get non-zero basicsize of type,
including the header sizes. |
source code
|
|
|
|
_derive_typedef(typ)
Return single, existing super type typedef or None. |
source code
|
|
|
|
_dir2(obj,
pref='',
excl=(),
slots=None,
itor='')
Return an attribute name, object 2-tuple for certain
attributes or for the '__slots__' attributes of the
given object, but not both. |
source code
|
|
|
|
_infer_dict(obj)
Return True for likely dict object. |
source code
|
|
|
|
_isdictclass(obj)
Return True for known dict objects. |
source code
|
|
|
|
|
|
|
_itemsize(t,
item=0)
Get non-zero itemsize of type. |
source code
|
|
|
|
_kwdstr(**kwds)
Keyword arguments as a string. |
source code
|
|
|
|
|
|
|
_nameof(obj,
dflt='')
Return the name of an object. |
source code
|
|
|
|
_objs(objs,
all=None,
**unused)
Return the given or 'all' objects. |
source code
|
|
|
|
_p100(part,
total,
prec=1)
Return percentage as string. |
source code
|
|
|
|
|
|
|
|
|
|
_prepr(obj,
clip=0)
Prettify and clip long repr() string. |
source code
|
|
|
|
_printf(fmt,
*args,
**print3opts)
Formatted print. |
source code
|
|
|
|
_refs(obj,
named,
*ats,
**kwds)
Return specific attribute objects of an object. |
source code
|
|
|
|
_repr(obj,
clip=80)
Clip long repr() string. |
source code
|
|
|
|
_SI(size,
K=1024,
i='i')
Return size as SI string. |
source code
|
|
|
|
_SI2(size,
**kwds)
Return size as regular plus SI string. |
source code
|
|
|
|
_class_refs(obj,
named)
Return specific referents of a class object. |
source code
|
|
|
|
_co_refs(obj,
named)
Return specific referents of a code object. |
source code
|
|
|
|
_dict_refs(obj,
named)
Return key and value objects of a dict/proxy. |
source code
|
|
|
|
_enum_refs(obj,
named)
Return specific referents of an enumerate object. |
source code
|
|
|
|
_exc_refs(obj,
named)
Return specific referents of an Exception object. |
source code
|
|
|
|
_file_refs(obj,
named)
Return specific referents of a file object. |
source code
|
|
|
|
_frame_refs(obj,
named)
Return specific referents of a frame object. |
source code
|
|
|
|
_func_refs(obj,
named)
Return specific referents of a function or lambda object. |
source code
|
|
|
|
_gen_refs(obj,
named)
Return the referent(s) of a generator object. |
source code
|
|
|
|
_im_refs(obj,
named)
Return specific referents of a method object. |
source code
|
|
|
|
_inst_refs(obj,
named)
Return specific referents of a class instance. |
source code
|
|
|
|
_iter_refs(obj,
named)
Return the referent(s) of an iterator object. |
source code
|
|
|
|
_module_refs(obj,
named)
Return specific referents of a module object. |
source code
|
|
|
|
_prop_refs(obj,
named)
Return specific referents of a property object. |
source code
|
|
|
|
_seq_refs(obj,
unused)
Return specific referents of a frozen/set, list, tuple and xrange object. |
source code
|
|
|
|
_stat_refs(obj,
named)
Return referents of a os.stat object. |
source code
|
|
|
|
_statvfs_refs(obj,
named)
Return referents of a os.statvfs object. |
source code
|
|
|
|
_tb_refs(obj,
named)
Return specific referents of a traceback object. |
source code
|
|
|
|
_type_refs(obj,
named)
Return specific referents of a type object. |
source code
|
|
|
|
_weak_refs(obj,
unused)
Return weakly referent object. |
source code
|
|
|
|
|
|
|
|
|
|
|
|
|
_len_code(obj)
Length of code object (stack and variables only). |
source code
|
|
|
|
_len_dict(obj)
Dict length in items (estimate). |
source code
|
|
|
|
|
|
|
_len_int(obj)
Length of multi-precision int (aka long) in digits. |
source code
|
|
|
|
_len_iter(obj)
Length (hint) of an iterator. |
source code
|
|
|
|
|
|
|
|
|
|
_len_set(obj)
Length of frozen/set (estimate). |
source code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_claskey(obj,
style)
Wrap an old- or new-style class object. |
source code
|
|
|
|
_instkey(obj)
Wrap an old-style class (instance). |
source code
|
|
|
|
_keytuple(obj)
Return class and instance keys for a class. |
source code
|
|
|
|
_objkey(obj)
Return the key for any object. |
source code
|
|
|
|
_typedef_both(t,
base=0,
item=0,
leng=None,
refs=None,
kind='static',
heap=False)
Add new typedef for both data and code. |
source code
|
|
|
|
_typedef_code(t,
base=0,
refs=None,
kind='static',
heap=False)
Add new typedef for code only. |
source code
|
|
|
|
_typedef(obj,
derive=False,
infer=False)
Create a new typedef for an object. |
source code
|
|
|
|
adict(*classes)
Install one or more classes to be handled as dict. |
source code
|
|
|
|
asized(*objs,
**opts)
Return a tuple containing an Asized instance for each
object passed as positional argment using the following
options. |
source code
|
|
|
|
asizeof(*objs,
**opts)
Return the combined size in bytes of all objects passed
as positional argments. |
source code
|
|
|
|
asizesof(*objs,
**opts)
Return a tuple containing the size in bytes of all objects
passed as positional argments using the following options. |
source code
|
|
|
|
_typedefof(obj,
save=False,
**opts)
Get the typedef for an object. |
source code
|
|
|
|
|
|
|
flatsize(obj,
align=0,
**opts)
Return the flat size of an object (in bytes),
optionally aligned to a given power of 2. |
source code
|
|
|
|
|
|
|
|
|
|
refs(obj,
all=False,
**opts)
Return (a generator for) specific referents of an
object. |
source code
|
|
|
|
_builtin_modules = ('__builtin__', 'types', 'exceptions', 'top...
|
|
|
_sizeof_Cbyte = 1
|
|
|
_sizeof_Clong = 4
|
|
|
_sizeof_Cvoidp = 4
|
|
|
_Zz = 'Ll'
|
|
|
_sizeof_CPyCodeObject = 68
|
|
|
_sizeof_CPyFrameObject = 316
|
|
|
_sizeof_CPyModuleObject = 12
|
|
|
_sizeof_CPyDictEntry = 12
|
|
|
_sizeof_Csetentry = 8
|
|
|
_sizeof_Cdigit = 2
|
|
|
_sizeof_Cunicode = 2
|
|
|
_sizeof_CPyGC_Head = 12
|
|
|
_sizeof_Crefcounts = 0
|
|
|
_Py_TPFLAGS_HEAPTYPE = 512
|
|
|
_Py_TPFLAGS_HAVE_GC = 16384
|
|
|
_all_refs = None, _class_refs, _co_refs, _dict_refs, _enum_ref...
|
|
|
_digit2p2 = 65536
|
|
|
_digitmax = 65535
|
|
|
_digitlog = 0.0901684400556
|
|
|
_all_lengs = None, _len, _len_array, _len_bytearray, _len_code...
|
|
|
_old_style = '*'
|
|
|
_new_style = ''
|
|
|
_claskeys = {6956320: <type 'Struct' def>, 14939424: <type 'ar...
|
|
|
_instkeys = {}
|
|
|
_all_kinds = ('static', 'dynamic', 'derived', 'ignored', 'infe...
|
|
|
_typedefs = {<type 'listiterator' def>: (436, 0, None, <functi...
|
|
|
_dict_typedef = (136, 12, <function _len_dict at 0xbe1f684>, <...
|
|
|
_dict_classes = {'UserDict': ('IterableUserDict', 'UserDict'),...
|
|
|
_asizer = Asizer()
|
|
|
__package__ = 'topo.misc'
|
|
|
_kind_derived = 'derived'
|
|
|
_kind_dynamic = 'dynamic'
|
|
|
_kind_ignored = 'ignored'
|
|
|
_kind_inferred = 'inferred'
|
|
|
_kind_static = 'static'
|