diff options
author | Ned Batchelder <nedbat@gmail.com> | 2014-10-01 07:32:19 -0400 |
---|---|---|
committer | Ned Batchelder <nedbat@gmail.com> | 2014-10-01 07:32:19 -0400 |
commit | 9af6bd3df6db9288199b2dbf9e243d14e6dc6e01 (patch) | |
tree | ce58d9307ea15167ffb9e8b40fa9e743bd430c04 /coverage/collector.py | |
parent | 866c1262f241641768c21f328048164fe56ca331 (diff) | |
parent | db8836e5d6c69b8861b1e5ffaf90e8215c02cad2 (diff) | |
download | python-coveragepy-9af6bd3df6db9288199b2dbf9e243d14e6dc6e01.tar.gz |
Merged in alex_gaynor/coveragepy/alex_gaynor/improve-performance-of-coverage-under-py-1411425050845 (pull request #40)
Improve performance of coverage under PyPy.
Diffstat (limited to 'coverage/collector.py')
-rw-r--r-- | coverage/collector.py | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/coverage/collector.py b/coverage/collector.py index c571cb0..66de8b6 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -51,7 +51,7 @@ class Collector(object): _collectors = [] def __init__(self, - should_trace, check_include, timid, branch, warn, coroutine, + should_trace, check_include, timid, branch, warn, concurrency, ): """Create a collector. @@ -73,7 +73,9 @@ class Collector(object): `warn` is a warning function, taking a single string message argument, to be used if a warning needs to be issued. - TODO: `coroutine` + `concurrency` is a string indicating the concurrency library in use. + Valid values are "greenlet", "eventlet", "gevent", or "thread" (the + default). """ self.should_trace = should_trace @@ -81,21 +83,21 @@ class Collector(object): self.warn = warn self.branch = branch self.threading = None - self.coroutine = coroutine + self.concurrency = concurrency - self.coroutine_id_func = None + self.concur_id_func = None try: - if coroutine == "greenlet": - import greenlet - self.coroutine_id_func = greenlet.getcurrent - elif coroutine == "eventlet": - import eventlet.greenthread - self.coroutine_id_func = eventlet.greenthread.getcurrent - elif coroutine == "gevent": - import gevent - self.coroutine_id_func = gevent.getcurrent - elif coroutine == "thread" or not coroutine: + if concurrency == "greenlet": + import greenlet # pylint: disable=import-error + self.concur_id_func = greenlet.getcurrent + elif concurrency == "eventlet": + import eventlet.greenthread # pylint: disable=import-error + self.concur_id_func = eventlet.greenthread.getcurrent + elif concurrency == "gevent": + import gevent # pylint: disable=import-error + self.concur_id_func = gevent.getcurrent + elif concurrency == "thread" or not concurrency: # It's important to import threading only if we need it. If # it's imported early, and the program being measured uses # gevent, then gevent's monkey-patching won't work properly. @@ -103,12 +105,12 @@ class Collector(object): self.threading = threading else: raise CoverageException( - "Don't understand coroutine=%s" % coroutine + "Don't understand concurrency=%s" % concurrency ) except ImportError: raise CoverageException( - "Couldn't trace with coroutine=%s, " - "the module isn't installed." % coroutine + "Couldn't trace with concurrency=%s, " + "the module isn't installed." % concurrency ) self.reset() @@ -156,13 +158,13 @@ class Collector(object): tracer.should_trace_cache = self.should_trace_cache tracer.warn = self.warn - if hasattr(tracer, 'coroutine_id_func'): - tracer.coroutine_id_func = self.coroutine_id_func - elif self.coroutine_id_func: + if hasattr(tracer, 'concur_id_func'): + tracer.concur_id_func = self.concur_id_func + elif self.concur_id_func: raise CoverageException( - "Can't support coroutine=%s with %s, " + "Can't support concurrency=%s with %s, " "only threads are supported" % ( - self.coroutine, self.tracer_name(), + self.concurrency, self.tracer_name(), ) ) @@ -212,6 +214,7 @@ class Collector(object): # Install the tracer on this thread. fn = self._start_tracer() + # Replay all the events from fullcoverage into the new trace function. for args in traces0: (frame, event, arg), lineno = args try: |