bs_mem module¶
Reports on memory usage:
mem_usage
: prints the topn
largest global items in memorymemory_display_top
: prints the topn
largest memory allocations since tracing startedmemory_display_top_diffs
: prints the topn
largest memory allocations since the last snapshot.
memory_display_top(snapshot, key_type='lineno', limit=5)
¶
prints out the lines with the top limit
allocations of memory since tracemalloc.start()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
snapshot |
Snapshot
|
obtained from tracemalloc.take_snapshot() |
required |
key_type |
str
|
'lineno' gives file and line number; 'traceback' gives all |
'lineno'
|
limit |
int | None
|
how many top allocations we want |
5
|
Returns:
Type | Description |
---|---|
None
|
just prints. |
Examples:
>>> tracemalloc.start()
>>> .... execute ...
>>> snapshot = tracemalloc.take_snapshot()
>>> memory_display_top(snapshot)
Source code in bs_python_utils/bs_mem.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
memory_display_top_diffs(snapshot1, snapshot2, key_type='lineno', limit=5)
¶
prints out the lines with the top limit
allocations between the two snapshots
Parameters:
Name | Type | Description | Default |
---|---|---|---|
snapshot1 |
Snapshot
|
previous snapshot |
required |
snapshot2 |
Snapshot
|
new snapshot |
required |
key_type |
str
|
'lineno' gives file and line number; 'traceback' gives all |
'lineno'
|
limit |
int
|
how many top allocations we want |
5
|
Returns:
Type | Description |
---|---|
None
|
just prints. |
Examples:
>>> tracemalloc.start()
>>> .... execute ...
>>> snapshot1 = tracemalloc.take_snapshot()
>>> .... execute ...
>>> snapshot2 = tracemalloc.take_snapshot()
>>> memory_display_top_diffs(snapshot1, snapshot2)
Source code in bs_python_utils/bs_mem.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
memory_usage(n=10)
¶
prints the top n
largest global items in memory
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int | None
|
we report the size of the largest |
10
|
Returns:
Type | Description |
---|---|
None
|
nothing. |
Source code in bs_python_utils/bs_mem.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|