Mercurial > piecrust2
diff piecrust/processing/worker.py @ 442:171dde4f61dc
performance: Add profiling to the asset pipeline workers.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 28 Jun 2015 14:52:58 -0700 |
parents | 5ceb86818dc5 |
children | aefe70229fdd |
line wrap: on
line diff
--- a/piecrust/processing/worker.py Sun Jun 28 14:52:37 2015 -0700 +++ b/piecrust/processing/worker.py Sun Jun 28 14:52:58 2015 -0700 @@ -23,6 +23,21 @@ def worker_func(wid, ctx): + if ctx.is_profiling: + try: + import cProfile as profile + except ImportError: + import profile + + ctx.is_profiling = False + profile.runctx('_real_worker_func(wid, ctx)', + globals(), locals(), + filename='PipelineWorker-%d.prof' % wid) + else: + _real_worker_func(wid, ctx) + + +def _real_worker_func(wid, ctx): logger.debug("Worker %d booting up..." % wid) w = ProcessingWorker(wid, ctx) w.run() @@ -40,6 +55,7 @@ self.abort_event = abort_event self.force = force self.debug = debug + self.is_profiling = False self.enabled_processors = None self.additional_processors = None