MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / Timer

Class Timer

_pydevd_bundle/pydevd_utils.py:439–491  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

437
438
439class Timer(object):
440 def __init__(self, min_diff=PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT):
441 self.min_diff = min_diff
442 self._curr_time = time.time()
443
444 def print_time(self, msg="Elapsed:"):
445 old = self._curr_time
446 new = self._curr_time = time.time()
447 diff = new - old
448 if diff >= self.min_diff:
449 print("%s: %.2fs" % (msg, diff))
450
451 def _report_slow(self, compute_msg, *args):
452 old = self._curr_time
453 new = self._curr_time = time.time()
454 diff = new - old
455 if diff >= self.min_diff:
456 py_db = get_global_debugger()
457 if py_db is not None:
458 msg = compute_msg(diff, *args)
459 py_db.writer.add_command(py_db.cmd_factory.make_warning_message(msg))
460
461 def report_if_compute_repr_attr_slow(self, attrs_tab_separated, attr_name, attr_type):
462 self._report_slow(self._compute_repr_slow, attrs_tab_separated, attr_name, attr_type)
463
464 def _compute_repr_slow(self, diff, attrs_tab_separated, attr_name, attr_type):
465 try:
466 attr_type = attr_type.__name__
467 except:
468 pass
469 if attrs_tab_separated:
470 return (
471 "pydevd warning: Computing repr of %s.%s (%s) was slow (took %.2fs).\n"
472 "Customize report timeout by setting the `PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT` environment variable to a higher timeout (default is: %ss)\n"
473 ) % (attrs_tab_separated.replace("\t", "."), attr_name, attr_type, diff, PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT)
474 else:
475 return (
476 "pydevd warning: Computing repr of %s (%s) was slow (took %.2fs)\n"
477 "Customize report timeout by setting the `PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT` environment variable to a higher timeout (default is: %ss)\n"
478 ) % (attr_name, attr_type, diff, PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT)
479
480 def report_if_getting_attr_slow(self, cls, attr_name):
481 self._report_slow(self._compute_get_attr_slow, cls, attr_name)
482
483 def _compute_get_attr_slow(self, diff, cls, attr_name):
484 try:
485 cls = cls.__name__
486 except:
487 pass
488 return (
489 "pydevd warning: Getting attribute %s.%s was slow (took %.2fs)\n"
490 "Customize report timeout by setting the `PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT` environment variable to a higher timeout (default is: %ss)\n"
491 ) % (cls, attr_name, diff, PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT)
492
493
494def import_attr_from_module(import_with_attr_access):

Callers 4

_get_dictionaryFunction · 0.90
_get_py_dictionaryMethod · 0.90
do_itMethod · 0.90
get_var_dataMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected