-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fc1b88
commit ba74da5
Showing
10 changed files
with
173 additions
and
995 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,36 @@ | ||
import os | ||
import psutil | ||
import linecache | ||
import tracemalloc | ||
process = psutil.Process(os.getpid()) | ||
|
||
def memory_consumed(): | ||
return process.memory_info().rss | ||
|
||
def display_tracemalloc_top(snapshot, key_type='lineno', limit=3): | ||
""" | ||
from https://stackoverflow.com/a/45679009/1685729 | ||
""" | ||
snapshot = snapshot.filter_traces(( | ||
tracemalloc.Filter(False, "<frozen importlib._bootstrap>"), | ||
tracemalloc.Filter(False, "<unknown>"), | ||
)) | ||
top_stats = snapshot.statistics(key_type) | ||
|
||
print("Top %s lines" % limit) | ||
for index, stat in enumerate(top_stats[:limit], 1): | ||
frame = stat.traceback[0] | ||
# replace "/path/to/module/file.py" with "module/file.py" | ||
filename = os.sep.join(frame.filename.split(os.sep)[-2:]) | ||
print("#%s: %s:%s: %.1f KiB" | ||
% (index, filename, frame.lineno, stat.size / 1024)) | ||
line = linecache.getline(frame.filename, frame.lineno).strip() | ||
if line: | ||
print(' %s' % line) | ||
|
||
other = top_stats[limit:] | ||
if other: | ||
size = sum(stat.size for stat in other) | ||
print("%s other: %.1f KiB" % (len(other), size / 1024)) | ||
total = sum(stat.size for stat in top_stats) | ||
print("Total allocated size: %.1f KiB" % (total / 1024)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.