comparison piecrust/baking/worker.py @ 426:ed5ccd4cce49

performance: Quick and dirty profiling support for bake workers.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 26 Jun 2015 09:49:29 -0700
parents afeebdd9f767
children 21e26ed867b6
comparison
equal deleted inserted replaced
425:afeebdd9f767 426:ed5ccd4cce49
11 11
12 logger = logging.getLogger(__name__) 12 logger = logging.getLogger(__name__)
13 13
14 14
15 def worker_func(wid, ctx): 15 def worker_func(wid, ctx):
16 if ctx.is_profiling:
17 try:
18 import cProfile as profile
19 except ImportError:
20 import profile
21
22 ctx.is_profiling = False
23 profile.runctx('_real_worker_func(wid, ctx)',
24 globals(), locals(),
25 filename='BakeWorker-%d.prof' % wid)
26 else:
27 _real_worker_func(wid, ctx)
28
29
30 def _real_worker_func(wid, ctx):
16 logger.debug("Worker %d booting up..." % wid) 31 logger.debug("Worker %d booting up..." % wid)
17 w = BakeWorker(wid, ctx) 32 w = BakeWorker(wid, ctx)
18 w.run() 33 w.run()
19 34
20 35
21 class BakeWorkerContext(object): 36 class BakeWorkerContext(object):
22 def __init__(self, root_dir, sub_cache_dir, out_dir, 37 def __init__(self, root_dir, sub_cache_dir, out_dir,
23 work_queue, results, abort_event, 38 work_queue, results, abort_event,
24 force=False, debug=False): 39 force=False, debug=False, is_profiling=False):
25 self.root_dir = root_dir 40 self.root_dir = root_dir
26 self.sub_cache_dir = sub_cache_dir 41 self.sub_cache_dir = sub_cache_dir
27 self.out_dir = out_dir 42 self.out_dir = out_dir
28 self.work_queue = work_queue 43 self.work_queue = work_queue
29 self.results = results 44 self.results = results
30 self.abort_event = abort_event 45 self.abort_event = abort_event
31 self.force = force 46 self.force = force
32 self.debug = debug 47 self.debug = debug
48 self.is_profiling = is_profiling
33 49
34 50
35 JOB_LOAD, JOB_RENDER_FIRST, JOB_BAKE = range(0, 3) 51 JOB_LOAD, JOB_RENDER_FIRST, JOB_BAKE = range(0, 3)
36 52
37 53