summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-01-02 11:28:39 -0500
committerNed Batchelder <ned@nedbatchelder.com>2017-01-02 11:28:39 -0500
commit279d71b0068a26c5c5233f057beef2967194b596 (patch)
tree9dd5fed371a1fdc940652813bd17d766f6dbd845
parent00ebc9756140d03b8ebc0f06b93c4f1183ad19dd (diff)
downloadpython-coveragepy-279d71b0068a26c5c5233f057beef2967194b596.tar.gz
Small improvements to the debug stuff
-rw-r--r--coverage/debug.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/coverage/debug.py b/coverage/debug.py
index c5c9924..91ccba7 100644
--- a/coverage/debug.py
+++ b/coverage/debug.py
@@ -132,6 +132,14 @@ def dump_stack_frames(limit=None, out=None, skip=0):
out.write("\n")
+def short_id(id64):
+ """Given a 64-bit id, make a shorter 16-bit one."""
+ id16 = 0
+ for offset in range(0, 64, 16):
+ id16 ^= id64 >> offset
+ return id16 & 0xFFFF
+
+
class DebugOutputFile(object): # pragma: debugging
"""A file-like object that includes pid and cwd information."""
def __init__(self, outfile):
@@ -171,17 +179,13 @@ class DebugOutputFile(object): # pragma: debugging
def _write(self, text, stack=False):
"""The raw text-writer, so that we can use it ourselves."""
# Thread ids are useful, but too long. Make a shorter one.
- tid = _thread.get_ident()
- stid = 0
- for byte in range(4):
- stid ^= tid >> (16 * byte)
- stid = "{0:04x}".format(stid & 0xFFFF)
+ tid = "{0:04x}".format(short_id(_thread.get_ident()))
# Aspectlib prints stack traces, but includes its own frames. Scrub those out:
# <<< aspectlib/__init__.py:257:function_wrapper < igor.py:143:run_tests < ...
text = re.sub(r"(?<= )aspectlib/[^.]+\.py:\d+:\w+ < ", "", text)
- self.outfile.write("{0:5d}.{1}: {2}".format(os.getpid(), stid, text))
+ self.outfile.write("{0:5d}.{1}: {2}".format(os.getpid(), tid, text))
self.outfile.flush()
if stack:
dump_stack_frames(out=self.outfile, skip=1)
@@ -213,7 +217,9 @@ def enable_aspectlib_maybe(): # pragma: debugging
import aspectlib.debug # pylint: disable=import-error
aspects_file = DebugOutputFile.the_one()
- aspect_log = aspectlib.debug.log(print_to=aspects_file, attributes=['id'], stacktrace=30, use_logging=False)
+ aspect_log = aspectlib.debug.log(
+ print_to=aspects_file, attributes=['id'], stacktrace=30, use_logging=False
+ )
public_methods = re.compile(r'^(__init__|[a-zA-Z].*)$')
for aspect in aspects.split(':'):
aspectlib.weave(aspect, aspect_log, methods=public_methods)