mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 23:34:45 +08:00
Make some profile output better
This commit is contained in:
@@ -4,7 +4,7 @@ Profile a piece of Python code with ``profile``. Tries a completion on a
|
|||||||
certain piece of code.
|
certain piece of code.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
profile.py [<code>] [-n <number>] [-d] [-o] [-s <sort>] [-i]
|
profile.py [<code>] [-n <number>] [-d] [-o] [-s <sort>] [-i] [--precision]
|
||||||
profile.py -h | --help
|
profile.py -h | --help
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
@@ -14,6 +14,7 @@ Options:
|
|||||||
-o --omit Omit profiler, just do a normal run.
|
-o --omit Omit profiler, just do a normal run.
|
||||||
-i --infer Infer types instead of completions.
|
-i --infer Infer types instead of completions.
|
||||||
-s <sort> Sort the profile results, e.g. cum, name [default: time].
|
-s <sort> Sort the profile results, e.g. cum, name [default: time].
|
||||||
|
--precision Makes profile time formatting more precise (nanoseconds)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
@@ -29,15 +30,12 @@ import jedi
|
|||||||
def f8(x):
|
def f8(x):
|
||||||
ret = "%7.3f " % x
|
ret = "%7.3f " % x
|
||||||
if ret == ' 0.000 ':
|
if ret == ' 0.000 ':
|
||||||
return "%6dµs" % (x * 10000000)
|
return "%6dµs" % (x * 1e6)
|
||||||
if ret.startswith(' 0.00'):
|
if ret.startswith(' 0.00'):
|
||||||
return "%8.4f" % x
|
return "%8.4f" % x
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
pstats.f8 = f8
|
|
||||||
|
|
||||||
|
|
||||||
def run(code, index, infer=False):
|
def run(code, index, infer=False):
|
||||||
start = time.time()
|
start = time.time()
|
||||||
script = jedi.Script(code)
|
script = jedi.Script(code)
|
||||||
@@ -57,6 +55,9 @@ def main(args):
|
|||||||
for i in range(n):
|
for i in range(n):
|
||||||
run(code, i, infer=infer)
|
run(code, i, infer=infer)
|
||||||
|
|
||||||
|
if args['--precision']:
|
||||||
|
pstats.f8 = f8
|
||||||
|
|
||||||
jedi.set_debug_function(notices=args['--debug'])
|
jedi.set_debug_function(notices=args['--debug'])
|
||||||
if args['--omit']:
|
if args['--omit']:
|
||||||
run(code, n, infer=infer)
|
run(code, n, infer=infer)
|
||||||
|
|||||||
Reference in New Issue
Block a user