1
0
forked from VimPlug/jedi

added speed function

This commit is contained in:
David Halter
2012-11-24 18:15:20 +01:00
parent 1e259c1c6e
commit dfaa2ed38e

View File

@@ -1,4 +1,6 @@
import inspect
import time
try:
# Use colorama for nicer console output.
from colorama import Fore, init
@@ -7,19 +9,26 @@ except ImportError:
class Fore(object):
RED = ''
GREEN = ''
YELLOW = ''
RESET = ''
NOTICE = object()
WARNING = object()
ERROR = object()
SPEED = object()
enable_speed = False
enable_warning = False
enable_notice = False
debug_function = None
ignored_modules = ['parsing', 'builtin', 'jedi.builtin', 'jedi.parsing']
start_time = time.time()
def dbg(*args):
""" Looks at the stack, to see if a debug message should be printed. """
if debug_function:
if debug_function and enable_notice:
frm = inspect.stack()[1]
mod = inspect.getmodule(frm[0])
if not (mod.__name__ in ignored_modules):
@@ -27,18 +36,24 @@ def dbg(*args):
def warning(*args):
if debug_function:
if debug_function and enable_warning:
debug_function(WARNING, *args)
def error(*args):
def speed(name):
if debug_function:
debug_function(ERROR, *args)
args = ('%s\t\t' % name,)
debug_function(SPEED, *args)
def print_to_stdout(level, *args):
""" The default debug function """
msg = (Fore.GREEN + 'dbg: ' if level == NOTICE else Fore.RED + 'warning: ')
if level == NOTICE:
msg = Fore.GREEN + 'dbg: '
elif level == WARNING:
msg = Fore.RED + 'warning: '
else:
msg = Fore.YELLOW + 'speed: '
print(msg + ', '.join(str(a) for a in args) + Fore.RESET)