Skip to content
Snippets Groups Projects
Commit 30c40ba1 authored by Dirkjan Ochtman's avatar Dirkjan Ochtman
Browse files

updating lsprof.py from remote repository

parent 31726c27
No related branches found
No related tags found
No related merge requests found
# this is copied from the lsprof distro because somehow #! /usr/bin/env python
# it is not installed by distutils
#
# small modifications made
import sys import sys
...@@ -5,15 +2,9 @@ ...@@ -5,15 +2,9 @@
import sys import sys
try: from _lsprof import Profiler, profiler_entry, profiler_subentry
from _lsprof import Profiler, profiler_entry, profiler_subentry
except ImportError, inst:
import packagescan
if packagescan.scan_in_progress:
raise packagescan.SkipPackage('_lsprof not available')
raise
__all__ = ['profile', 'Stats'] __all__ = ['profile', 'Stats']
def profile(f, *args, **kwds): def profile(f, *args, **kwds):
"""XXX docstring""" """XXX docstring"""
p = Profiler() p = Profiler()
...@@ -14,8 +5,8 @@ ...@@ -14,8 +5,8 @@
__all__ = ['profile', 'Stats'] __all__ = ['profile', 'Stats']
def profile(f, *args, **kwds): def profile(f, *args, **kwds):
"""XXX docstring""" """XXX docstring"""
p = Profiler() p = Profiler()
p.enable(subcalls=True) p.enable(subcalls=True, builtins=True)
try: try:
...@@ -21,4 +12,4 @@ ...@@ -21,4 +12,4 @@
try: try:
ret = f(*args, **kwds) f(*args, **kwds)
finally: finally:
p.disable() p.disable()
...@@ -23,6 +14,6 @@ ...@@ -23,6 +14,6 @@
finally: finally:
p.disable() p.disable()
return ret, Stats(p.getstats()) return Stats(p.getstats())
class Stats(object): class Stats(object):
...@@ -49,10 +40,10 @@ ...@@ -49,10 +40,10 @@
d = self.data d = self.data
if top is not None: if top is not None:
d = d[:top] d = d[:top]
cols = "% 12s %11.4f %11.4f %s\n" cols = "% 12s %12s %11.4f %11.4f %s\n"
hcols = "% 12s %12s %12s %s\n" hcols = "% 12s %12s %12s %12s %s\n"
cols2 = "+%12s %11.4f %11.4f + %s\n" cols2 = "+%12s %12s %11.4f %11.4f + %s\n"
file.write(hcols % ("CallCount", "Total(s)", file.write(hcols % ("CallCount", "Recursive", "Total(ms)",
"Inline(s)", "module:lineno(function)")) "Inline(ms)", "module:lineno(function)"))
count = 0 count = 0
for e in d: for e in d:
...@@ -57,6 +48,6 @@ ...@@ -57,6 +48,6 @@
count = 0 count = 0
for e in d: for e in d:
file.write(cols % (e.callcount, e.totaltime, file.write(cols % (e.callcount, e.reccallcount, e.totaltime,
e.inlinetime, label(e.code))) e.inlinetime, label(e.code)))
count += 1 count += 1
if limit is not None and count == limit: if limit is not None and count == limit:
...@@ -64,7 +55,7 @@ ...@@ -64,7 +55,7 @@
ccount = 0 ccount = 0
if e.calls: if e.calls:
for se in e.calls: for se in e.calls:
file.write(cols % ("+%s" % se.callcount, file.write(cols % ("+%s" % se.callcount, se.reccallcount,
se.totaltime, se.inlinetime, se.totaltime, se.inlinetime,
"+%s" % label(se.code))) "+%s" % label(se.code)))
count += 1 count += 1
...@@ -83,11 +74,11 @@ ...@@ -83,11 +74,11 @@
e = self.data[i] e = self.data[i]
if not isinstance(e.code, str): if not isinstance(e.code, str):
self.data[i] = type(e)((label(e.code),) + e[1:]) self.data[i] = type(e)((label(e.code),) + e[1:])
if e.calls: if e.calls:
for j in range(len(e.calls)): for j in range(len(e.calls)):
se = e.calls[j] se = e.calls[j]
if not isinstance(se.code, str): if not isinstance(se.code, str):
e.calls[j] = type(se)((label(se.code),) + se[1:]) e.calls[j] = type(se)((label(se.code),) + se[1:])
_fn2mod = {} _fn2mod = {}
...@@ -97,7 +88,7 @@ ...@@ -97,7 +88,7 @@
try: try:
mname = _fn2mod[code.co_filename] mname = _fn2mod[code.co_filename]
except KeyError: except KeyError:
for k, v in sys.modules.iteritems(): for k, v in sys.modules.items():
if v is None: if v is None:
continue continue
if not hasattr(v, '__file__'): if not hasattr(v, '__file__'):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment