diff 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
line wrap: on
line diff
--- a/piecrust/baking/baker.py	Thu Jun 25 14:51:37 2015 -0700
+++ b/piecrust/baking/baker.py	Fri Jun 26 09:49:29 2015 -0700
@@ -543,14 +543,20 @@
             logger.error("  " + e)
 
     def _createWorkerPool(self):
+        import sys
         from piecrust.baking.worker import BakeWorkerContext, worker_func
 
+        main_module = sys.modules['__main__']
+        is_profiling = os.path.basename(main_module.__file__) in [
+                'profile.py', 'cProfile.py']
+
         pool = _WorkerPool()
         for i in range(self.num_workers):
             ctx = BakeWorkerContext(
                     self.app.root_dir, self.app.cache.base_dir, self.out_dir,
                     pool.queue, pool.results, pool.abort_event,
-                    force=self.force, debug=self.app.debug)
+                    force=self.force, debug=self.app.debug,
+                    is_profiling=is_profiling)
             w = multiprocessing.Process(
                     name='BakeWorker_%d' % i,
                     target=worker_func, args=(i, ctx))