Mercurial > piecrust2
diff piecrust/baking/baker.py @ 1011:c4cf3cfe2726
bake: Better performance stats, and add callback to preload templates.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 26 Nov 2017 22:23:03 -0800 |
parents | 09dc0240f08a |
children | 071f30aa04bb |
line wrap: on
line diff
--- a/piecrust/baking/baker.py Sun Nov 26 22:21:33 2017 -0800 +++ b/piecrust/baking/baker.py Sun Nov 26 22:23:03 2017 -0800 @@ -54,8 +54,7 @@ stats = self.app.env.stats stats.registerTimer('LoadSourceContents', raise_if_registered=False) - stats.registerTimer('MasterTaskPut_1', raise_if_registered=False) - stats.registerTimer('MasterTaskPut_2+', raise_if_registered=False) + stats.registerTimer('CacheTemplates', raise_if_registered=False) # Make sure the output directory exists. if not os.path.isdir(self.out_dir): @@ -98,8 +97,9 @@ # Done with all the setup, let's start the actual work. logger.info(format_timed(start_time, "setup baker")) - # Load all sources. + # Load all sources, pre-cache templates. self._loadSources(ppmngr) + self._populateTemplateCaches() # Bake the realms. self._bakeRealms(pool, ppmngr, record_histories) @@ -216,10 +216,19 @@ rec.addEntry(e) stats = self.app.env.stats - stats.stepTimer('LoadSourceContents', - time.perf_counter() - start_time) + stats.stepTimer('LoadSourceContents', time.perf_counter() - start_time) logger.info(format_timed(start_time, "loaded site content")) + def _populateTemplateCaches(self): + start_time = time.perf_counter() + + for eng in self.app.plugin_loader.getTemplateEngines(): + eng.populateCache() + + stats = self.app.env.stats + stats.stepTimer('CacheTemplates', time.perf_counter() - start_time) + logger.info(format_timed(start_time, "cache templates")) + def _bakeRealms(self, pool, ppmngr, record_histories): # Bake the realms -- user first, theme second, so that a user item # can override a theme item. @@ -272,8 +281,6 @@ "(%s, step 0)." % (new_job_count, src.name, pp.PIPELINE_NAME, realm_name)) - stats.stepTimer('MasterTaskPut_1', time.perf_counter() - start_time) - if job_count == 0: logger.debug("No jobs queued! Bailing out of this bake pass.") return @@ -315,8 +322,6 @@ pool.queueJobs(jobs) participating_source_names.append(sn) - stats.stepTimer('MasterTaskPut_2+', time.perf_counter() - start_time) - if job_count == 0: break