Profile(filename[, lineevents, linetimings]) | |
LineData(data) | |
load(filename) | Return standard pstats class and lineevent data. |
Inheritance diagram for mmf.utils.mmf_profile:
Profiling Module based on hotshot using line-event data.
First we start with the standard profiling analysis:
>>> import numpy as np
>>> import mmf.utils.mmf_profile
>>> def f(A):
... np.roll(A, 1, axis=1)
>>> prof = mmf.utils.mmf_profile.Profile('data_file.prof')
>>> A = np.empty((100,100,100))
>>> prof.runcall(f, A)
>>> prof.close()
>>> stats, data = mmf.utils.mmf_profile.load('data_file.prof')
>>> stats = stats.strip_dirs()
>>> stats = stats.sort_stats('time', 'calls')
>>> stats = stats.print_stats(20)
3 function calls in ... CPU seconds
Ordered by: internal time, call count
ncalls tottime percall cumtime percall filename:lineno(function)
1 ... ... ... ... numeric.py:1033(roll)
1 ... ... ... ... <doctest mmf.utils.mmf_profile[2]>:1(f)
1 ... ... ... ... numeric.py:...(asanyarray)
0 ... ... profile:0(profiler)
This is not so useful because the time is taken in the function roll rather than in external calls. Now let’s look at the line data by annotating the files:
>>> files = data.annotate_files()
Warning: Ignoring source file ...
>>> for f in files:
... print(f)
... print(files[f])
/...
1033: ------ ------ def roll(a, shift, axis=None):
...
1082: ...% 1 a = asanyarray(a)
1083: ...% 1 if axis is None:
1084: ------ ------ n = a.size
1085: ------ ------ reshape = True
1086: ------ ------ else:
1087: ...% 1 n = a.shape[axis]
1088: ...% 1 reshape = False
1089: ...% 1 shift %= n
1090: ...% 1 indexes = concatenate((arange(n-shift,n),arange(n-shift)))
1091: 9...% 1 res = a.take(indexes, axis)
1092: ...% 1 if reshape:
1093: ------ ------ return res.reshape(a.shape)
1094: ------ ------ else:
1095: ...% 1 return res
1096: ------ ------
...
Bases: hotshot.Profile
Methods
addinfo(key, value) | Add an arbitrary labelled value to the profile log. |
close() | Close the logfile and terminate the profiler. |
fileno() | Return the file descriptor of the profiler’s log file. |
run(cmd) | Profile an exec-compatible string in the script environment. |
runcall(func, *args, **kw) | Profile a single call of a callable. |
runctx(cmd, globals, locals) | Evaluate an exec-compatible string in a specific environment. |
start() | Start the profiler. |
stop() | Stop the profiler. |
Bases: object
Methods
annotate_files() | |
format_data() | |
print_data() |