Settings for debug/profile and use them in console plugin.
This commit is contained in:
@ -19,6 +19,7 @@ import sys
|
|||||||
|
|
||||||
from colorama import Fore, Style
|
from colorama import Fore, Style
|
||||||
|
|
||||||
|
from bonobo import settings
|
||||||
from bonobo.plugins import Plugin
|
from bonobo.plugins import Plugin
|
||||||
from bonobo.util.term import CLEAR_EOL, MOVE_CURSOR_UP
|
from bonobo.util.term import CLEAR_EOL, MOVE_CURSOR_UP
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ from bonobo.util.term import CLEAR_EOL, MOVE_CURSOR_UP
|
|||||||
def memory_usage():
|
def memory_usage():
|
||||||
import os, psutil
|
import os, psutil
|
||||||
process = psutil.Process(os.getpid())
|
process = psutil.Process(os.getpid())
|
||||||
return process.get_memory_info()[0] / float(2**20)
|
return process.memory_info()[0] / float(2**20)
|
||||||
|
|
||||||
|
|
||||||
# @lru_cache(64)
|
# @lru_cache(64)
|
||||||
@ -50,15 +51,14 @@ class ConsoleOutputPlugin(Plugin):
|
|||||||
self.prefix = ''
|
self.prefix = ''
|
||||||
|
|
||||||
def _write(self, graph_context, rewind):
|
def _write(self, graph_context, rewind):
|
||||||
profile, debug = False, False
|
if settings.PROFILE:
|
||||||
if profile:
|
|
||||||
append = (
|
append = (
|
||||||
('Memory', '{0:.2f} Mb'.format(memory_usage())),
|
('Memory', '{0:.2f} Mb'.format(memory_usage())),
|
||||||
# ('Total time', '{0} s'.format(execution_time(harness))),
|
# ('Total time', '{0} s'.format(execution_time(harness))),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
append = ()
|
append = ()
|
||||||
self.write(graph_context, prefix=self.prefix, append=append, debug=debug, profile=profile, rewind=rewind)
|
self.write(graph_context, prefix=self.prefix, append=append, rewind=rewind)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if sys.stdout.isatty():
|
if sys.stdout.isatty():
|
||||||
@ -70,23 +70,24 @@ class ConsoleOutputPlugin(Plugin):
|
|||||||
self._write(self.context.parent, rewind=False)
|
self._write(self.context.parent, rewind=False)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def write(context, prefix='', rewind=True, append=None, debug=False, profile=False):
|
def write(context, prefix='', rewind=True, append=None):
|
||||||
t_cnt = len(context)
|
t_cnt = len(context)
|
||||||
|
|
||||||
for i in context.graph.topologically_sorted_indexes:
|
for i in context.graph.topologically_sorted_indexes:
|
||||||
node = context[i]
|
node = context[i]
|
||||||
|
name_suffix = '({})'.format(i) if settings.DEBUG else ''
|
||||||
if node.alive:
|
if node.alive:
|
||||||
_line = ''.join(
|
_line = ''.join(
|
||||||
(
|
(
|
||||||
' ', Style.BRIGHT, '+', Style.RESET_ALL, ' ', node.name, '(', str(i), ') ',
|
' ', Style.BRIGHT, '+', Style.RESET_ALL, ' ', node.name, name_suffix, ' ',
|
||||||
node.get_statistics_as_string(debug=debug, profile=profile), Style.RESET_ALL, ' ',
|
node.get_statistics_as_string(), Style.RESET_ALL, ' ',
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
_line = ''.join(
|
_line = ''.join(
|
||||||
(
|
(
|
||||||
' ', Fore.BLACK, '-', ' ', node.name, '(', str(i), ') ',
|
' ', Fore.BLACK, '-', ' ', node.name, name_suffix, ' ', node.get_statistics_as_string(),
|
||||||
node.get_statistics_as_string(debug=debug, profile=profile), Style.RESET_ALL, ' ',
|
Style.RESET_ALL, ' ',
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
print(prefix + _line + '\033[0K')
|
print(prefix + _line + '\033[0K')
|
||||||
|
|||||||
16
bonobo/settings.py
Normal file
16
bonobo/settings.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def to_bool(s):
|
||||||
|
if len(s):
|
||||||
|
if s.lower() in ('f', 'false', 'n', 'no', '0'):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# Debug mode.
|
||||||
|
DEBUG = to_bool(os.environ.get('BONOBO_DEBUG', 'f'))
|
||||||
|
|
||||||
|
# Profile mode.
|
||||||
|
PROFILE = to_bool(os.environ.get('BONOBO_PROFILE', 'f'))
|
||||||
Reference in New Issue
Block a user