Mercurial > piecrust2
comparison piecrust/baking/baker.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 |
---|---|
541 logger.error("Errors found in %s:" % rel_path) | 541 logger.error("Errors found in %s:" % rel_path) |
542 for e in errors: | 542 for e in errors: |
543 logger.error(" " + e) | 543 logger.error(" " + e) |
544 | 544 |
545 def _createWorkerPool(self): | 545 def _createWorkerPool(self): |
546 import sys | |
546 from piecrust.baking.worker import BakeWorkerContext, worker_func | 547 from piecrust.baking.worker import BakeWorkerContext, worker_func |
548 | |
549 main_module = sys.modules['__main__'] | |
550 is_profiling = os.path.basename(main_module.__file__) in [ | |
551 'profile.py', 'cProfile.py'] | |
547 | 552 |
548 pool = _WorkerPool() | 553 pool = _WorkerPool() |
549 for i in range(self.num_workers): | 554 for i in range(self.num_workers): |
550 ctx = BakeWorkerContext( | 555 ctx = BakeWorkerContext( |
551 self.app.root_dir, self.app.cache.base_dir, self.out_dir, | 556 self.app.root_dir, self.app.cache.base_dir, self.out_dir, |
552 pool.queue, pool.results, pool.abort_event, | 557 pool.queue, pool.results, pool.abort_event, |
553 force=self.force, debug=self.app.debug) | 558 force=self.force, debug=self.app.debug, |
559 is_profiling=is_profiling) | |
554 w = multiprocessing.Process( | 560 w = multiprocessing.Process( |
555 name='BakeWorker_%d' % i, | 561 name='BakeWorker_%d' % i, |
556 target=worker_func, args=(i, ctx)) | 562 target=worker_func, args=(i, ctx)) |
557 w.start() | 563 w.start() |
558 pool.workers.append(w) | 564 pool.workers.append(w) |