comparison 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
comparison
equal deleted inserted replaced
441:dc8518c51cbe 442:171dde4f61dc
21 split_processor_names_re = re.compile(r'[ ,]+') 21 split_processor_names_re = re.compile(r'[ ,]+')
22 re_ansicolors = re.compile('\033\\[\d+m') 22 re_ansicolors = re.compile('\033\\[\d+m')
23 23
24 24
25 def worker_func(wid, ctx): 25 def worker_func(wid, ctx):
26 if ctx.is_profiling:
27 try:
28 import cProfile as profile
29 except ImportError:
30 import profile
31
32 ctx.is_profiling = False
33 profile.runctx('_real_worker_func(wid, ctx)',
34 globals(), locals(),
35 filename='PipelineWorker-%d.prof' % wid)
36 else:
37 _real_worker_func(wid, ctx)
38
39
40 def _real_worker_func(wid, ctx):
26 logger.debug("Worker %d booting up..." % wid) 41 logger.debug("Worker %d booting up..." % wid)
27 w = ProcessingWorker(wid, ctx) 42 w = ProcessingWorker(wid, ctx)
28 w.run() 43 w.run()
29 44
30 45
38 self.work_queue = work_queue 53 self.work_queue = work_queue
39 self.results = results 54 self.results = results
40 self.abort_event = abort_event 55 self.abort_event = abort_event
41 self.force = force 56 self.force = force
42 self.debug = debug 57 self.debug = debug
58 self.is_profiling = False
43 self.enabled_processors = None 59 self.enabled_processors = None
44 self.additional_processors = None 60 self.additional_processors = None
45 61
46 62
47 class ProcessingWorkerJob(object): 63 class ProcessingWorkerJob(object):