-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_profiler.py
66 lines (50 loc) · 1.63 KB
/
_profiler.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
56
57
58
59
60
61
62
63
64
"""
Used for profiling.
"""
import cProfile
import pstats
import os
#import mock
from brian_FPC import *
_GPROF2DOT = '/usr/local/bin/gprof2dot'
_DOT = '/opt/local/bin/dot'
if __name__ == '__main__':
# turn off all graphics by replacing graphics functions with mock functions
# plt.plot = mock.Mock(return_value=None)
# topo.PlotTargets = mock.Mock(return_value=None)
# topo.PlotLayer = mock.Mock(return_value=None)
# topo.PlotKernel = mock.Mock(return_value=None)
# initialize setup
prof_file = 'brian_FPC.prof'
# profile with output to file, longer run
cProfile.run('''
test = InDegreeTester(N_s=30, N_t=100, p=0.5)
ks, p = test.two_level_test(n_runs=100, start_seed=0, control=False)
print 'p-value of KS-test of uniformity:', p
''',
prof_file)
# read profile data from file, output statistics in different orders
prof = pstats.Stats(prof_file).strip_dirs()
# print '=' * 80
# prof.sort_stats('name').print_stats()
#
# print '=' * 80
# prof.sort_stats('cum').print_stats()
#
# print '=' * 80
prof.sort_stats('time').print_stats()
#
# print '=' * 80
# prof.sort_stats('calls').print_stats()
#
# print '=' * 80
# prof.print_callers()
#
# print '=' * 80
# prof.print_callees()
# finally, invoke gprof2dot and dot to create a figure
os.system('{gprof2dot} -f pstats -o {file}.dot {file}'
.format(gprof2dot=_GPROF2DOT, file=prof_file))
os.system('{dot} -Tpdf -o {file}.pdf {file}.dot'
.format(dot=_DOT, file=prof_file))
print "Profile graph stored as {file}.pdf".format(file=prof_file)