forked from manu-tej/Kinect2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBenchmarker.py
executable file
·55 lines (45 loc) · 1.76 KB
/
Benchmarker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import linecache
import os
import tracemalloc
def start(frameN):
tracemalloc.start(frameN)
def display_current_memory(topN):
snapshot = tracemalloc.take_snapshot()
display_top(snapshot, limit=topN)
def display_traceback_memory(topN):
snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('traceback')
# pick the biggest memory block
stat = top_stats[0]
print("%s memory blocks: %.1f KiB" % (stat.count, stat.size / 1024))
for line in stat.traceback.format():
print(line)
def display_top(snapshot, key_type='lineno', limit=20):
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))
"""
# ... run your application ...
import subprocess
subprocess.call(['python', 'AnalyzeData.py', '-C', 'MethodsData.xlsx'])
snapshot = tracemalloc.take_snapshot()
display_top(snapshot)
"""