Mercurial > piecrust2
comparison piecrust/commands/builtin/baking.py @ 692:c11a4339fccb
bake: Show more stats.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 21 Mar 2016 22:29:18 -0700 |
parents | 61d606fbc313 |
children | 33ab9badfd7a |
comparison
equal
deleted
inserted
replaced
691:9ae9390192da | 692:c11a4339fccb |
---|---|
126 if name not in target: | 126 if name not in target: |
127 target[name] = ExecutionStats() | 127 target[name] = ExecutionStats() |
128 target[name].mergeStats(val) | 128 target[name].mergeStats(val) |
129 | 129 |
130 | 130 |
131 def _show_stats(stats, full=False): | 131 def _show_stats(stats, *, full=False): |
132 indent = ' ' | 132 indent = ' ' |
133 for name in sorted(stats.keys()): | 133 for name in sorted(stats.keys()): |
134 logger.info('%s:' % name) | 134 logger.info('%s:' % name) |
135 s = stats[name] | 135 s = stats[name] |
136 | 136 |
137 logger.info(' Timers:') | 137 logger.info(' Timers:') |
138 for name, val in s.timers.items(): | 138 for name in sorted(s.timers.keys()): |
139 val_str = '%8.1f s' % val | 139 val_str = '%8.1f s' % s.timers[name] |
140 logger.info( | 140 logger.info( |
141 "%s[%s%s%s] %s" % | 141 "%s[%s%s%s] %s" % |
142 (indent, Fore.GREEN, val_str, Fore.RESET, name)) | 142 (indent, Fore.GREEN, val_str, Fore.RESET, name)) |
143 | 143 |
144 logger.info(' Counters:') | 144 logger.info(' Counters:') |
145 for name, val in s.counters.items(): | 145 for name in sorted(s.counters.keys()): |
146 val_str = '%8d ' % val | 146 val_str = '%8d ' % s.counters[name] |
147 logger.info( | 147 logger.info( |
148 "%s[%s%s%s] %s" % | 148 "%s[%s%s%s] %s" % |
149 (indent, Fore.GREEN, val_str, Fore.RESET, name)) | 149 (indent, Fore.GREEN, val_str, Fore.RESET, name)) |
150 | 150 |
151 logger.info(' Manifests:') | 151 logger.info(' Manifests:') |
152 for name, val in s.manifests.items(): | 152 for name in sorted(s.manifests.keys()): |
153 val = s.manifests[name] | |
153 logger.info( | 154 logger.info( |
154 "%s[%s%s%s] [%d entries]" % | 155 "%s[%s%s%s] [%d entries]" % |
155 (indent, Fore.CYAN, name, Fore.RESET, len(val))) | 156 (indent, Fore.CYAN, name, Fore.RESET, len(val))) |
156 if full: | 157 if full: |
157 for v in val: | 158 for v in val: |
191 "pipeline).") | 192 "pipeline).") |
192 parser.add_argument( | 193 parser.add_argument( |
193 '--assets-only', | 194 '--assets-only', |
194 action='store_true', | 195 action='store_true', |
195 help="Only show records for assets (not from pages).") | 196 help="Only show records for assets (not from pages).") |
197 parser.add_argument( | |
198 '--show-stats', | |
199 action='store_true', | |
200 help="Show stats from the record.") | |
196 | 201 |
197 def run(self, ctx): | 202 def run(self, ctx): |
198 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter') | 203 out_dir = ctx.args.output or os.path.join(ctx.app.root_dir, '_counter') |
199 record_id = hashlib.md5(out_dir.encode('utf8')).hexdigest() | 204 record_id = hashlib.md5(out_dir.encode('utf8')).hexdigest() |
200 suffix = '' if ctx.args.last == 0 else '.%d' % ctx.args.last | 205 suffix = '' if ctx.args.last == 0 else '.%d' % ctx.args.last |
206 | 211 |
207 out_pattern = None | 212 out_pattern = None |
208 if ctx.args.out: | 213 if ctx.args.out: |
209 out_pattern = '*%s*' % ctx.args.out.strip('*') | 214 out_pattern = '*%s*' % ctx.args.out.strip('*') |
210 | 215 |
216 bake_rec = None | |
211 if not ctx.args.assets_only: | 217 if not ctx.args.assets_only: |
212 self._showBakeRecord(ctx, record_name, pattern, out_pattern) | 218 bake_rec = self._showBakeRecord( |
219 ctx, record_name, pattern, out_pattern) | |
220 proc_rec = None | |
213 if not ctx.args.html_only: | 221 if not ctx.args.html_only: |
214 self._showProcessingRecord(ctx, record_name, pattern, out_pattern) | 222 proc_rec = self._showProcessingRecord( |
223 ctx, record_name, pattern, out_pattern) | |
224 | |
225 if ctx.args.show_stats: | |
226 stats = {} | |
227 if bake_rec: | |
228 _merge_stats(bake_rec.stats, stats) | |
229 if proc_rec: | |
230 _merge_stats(proc_rec.stats, stats) | |
231 _show_stats(stats, full=True) | |
215 | 232 |
216 def _showBakeRecord(self, ctx, record_name, pattern, out_pattern): | 233 def _showBakeRecord(self, ctx, record_name, pattern, out_pattern): |
217 # Show the bake record. | 234 # Show the bake record. |
218 record_cache = ctx.app.cache.getCache('baker') | 235 record_cache = ctx.app.cache.getCache('baker') |
219 if not record_cache.has(record_name): | 236 if not record_cache.has(record_name): |
286 if sub.render_info: | 303 if sub.render_info: |
287 pass_names = { | 304 pass_names = { |
288 PASS_FORMATTING: 'formatting pass', | 305 PASS_FORMATTING: 'formatting pass', |
289 PASS_RENDERING: 'rendering pass'} | 306 PASS_RENDERING: 'rendering pass'} |
290 for p, ri in sub.render_info.items(): | 307 for p, ri in sub.render_info.items(): |
291 logging.info(" - %s" % p) | 308 logging.info(" - %s" % pass_names[p]) |
292 logging.info(" used sources: %s" % | 309 logging.info(" used sources: %s" % |
293 _join(ri.used_source_names)) | 310 _join(ri.used_source_names)) |
294 pgn_info = 'no' | 311 pgn_info = 'no' |
295 if ri.used_pagination: | 312 if ri.used_pagination: |
296 pgn_info = 'yes' | 313 pgn_info = 'yes' |
307 else: | 324 else: |
308 logging.info(" no render info") | 325 logging.info(" no render info") |
309 | 326 |
310 if sub.errors: | 327 if sub.errors: |
311 logging.error(" errors: %s" % sub.errors) | 328 logging.error(" errors: %s" % sub.errors) |
329 | |
330 return record | |
312 | 331 |
313 def _showProcessingRecord(self, ctx, record_name, pattern, out_pattern): | 332 def _showProcessingRecord(self, ctx, record_name, pattern, out_pattern): |
314 record_cache = ctx.app.cache.getCache('proc') | 333 record_cache = ctx.app.cache.getCache('proc') |
315 if not record_cache.has(record_name): | 334 if not record_cache.has(record_name): |
316 raise Exception("No record has been created for this output path. " | 335 raise Exception("No record has been created for this output path. " |
352 entry.proc_tree, 14*' ')) | 371 entry.proc_tree, 14*' ')) |
353 | 372 |
354 if entry.errors: | 373 if entry.errors: |
355 logger.error(" errors: %s" % entry.errors) | 374 logger.error(" errors: %s" % entry.errors) |
356 | 375 |
376 return record | |
377 | |
357 | 378 |
358 def _join(items, sep=', ', text_if_none='none'): | 379 def _join(items, sep=', ', text_if_none='none'): |
359 if items: | 380 if items: |
360 return sep.join(items) | 381 return sep.join(items) |
361 return text_if_none | 382 return text_if_none |