comparison piecrust/commands/builtin/baking.py @ 421:4a43d7015b75

bake: Improve performance timers reports. Add timers per-worker, and separate bake and pipeline workers.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 20 Jun 2015 23:27:39 -0700
parents 0e9a94b7fdfa
children 04abc97dd3b6
comparison
equal deleted inserted replaced
420:f1b759c188b0 421:4a43d7015b75
2 import os.path 2 import os.path
3 import logging 3 import logging
4 import hashlib 4 import hashlib
5 import fnmatch 5 import fnmatch
6 import datetime 6 import datetime
7 from colorama import Fore
7 from piecrust.baking.baker import Baker 8 from piecrust.baking.baker import Baker
8 from piecrust.baking.records import ( 9 from piecrust.baking.records import (
9 BakeRecord, BakeRecordEntry, SubPageBakeInfo) 10 BakeRecord, BakeRecordEntry, SubPageBakeInfo)
10 from piecrust.chefutil import format_timed 11 from piecrust.chefutil import format_timed
11 from piecrust.commands.base import ChefCommand 12 from piecrust.commands.base import ChefCommand
69 if not ctx.args.html_only: 70 if not ctx.args.html_only:
70 success = success & self._bakeAssets(ctx, out_dir) 71 success = success & self._bakeAssets(ctx, out_dir)
71 72
72 # Show merged timers. 73 # Show merged timers.
73 if ctx.args.show_timers: 74 if ctx.args.show_timers:
74 from colorama import Fore
75 logger.info("-------------------") 75 logger.info("-------------------")
76 logger.info("Timing information:") 76 logger.info("Timing information:")
77 for name in sorted(ctx.timers.keys()): 77 _show_timers(ctx.timers)
78 val_str = '%8.1f s' % ctx.timers[name]
79 logger.info(
80 "[%s%s%s] %s" %
81 (Fore.GREEN, val_str, Fore.RESET, name))
82 78
83 # All done. 79 # All done.
84 logger.info('-------------------------') 80 logger.info('-------------------------')
85 logger.info(format_timed(start_time, 'done baking')) 81 logger.info(format_timed(start_time, 'done baking'))
86 return 0 if success else 1 82 return 0 if success else 1
113 def _merge_timers(source, target): 109 def _merge_timers(source, target):
114 if source is None: 110 if source is None:
115 return 111 return
116 112
117 for name, val in source.items(): 113 for name, val in source.items():
118 if name not in target: 114 if isinstance(val, float):
119 target[name] = 0 115 if name not in target:
120 target[name] += val 116 target[name] = 0
117 target[name] += val
118 elif isinstance(val, dict):
119 if name not in target:
120 target[name] = {}
121 _merge_timers(val, target[name])
122
123
124 def _show_timers(timers, indent=''):
125 sub_timer_names = []
126 for name in sorted(timers.keys()):
127 if isinstance(timers[name], float):
128 val_str = '%8.1f s' % timers[name]
129 logger.info(
130 "%s[%s%s%s] %s" %
131 (indent, Fore.GREEN, val_str, Fore.RESET, name))
132 else:
133 sub_timer_names.append(name)
134
135 for name in sub_timer_names:
136 logger.info('%s:' % name)
137 _show_timers(timers[name], indent + ' ')
121 138
122 139
123 class ShowRecordCommand(ChefCommand): 140 class ShowRecordCommand(ChefCommand):
124 def __init__(self): 141 def __init__(self):
125 super(ShowRecordCommand, self).__init__() 142 super(ShowRecordCommand, self).__init__()