@@ -44,34 +44,6 @@ def setup_logging():
4444BENCH
4545"""
4646
47- bench_example = '''**Examples**:
48- Runs all benchmarks
49- %(prog)s
50-
51- Runs benchmarks for pallet_balances and pallet_multisig for all runtimes which have these pallets. **--quiet** makes it to output nothing to PR but reactions
52- %(prog)s --pallet pallet_balances pallet_xcm_benchmarks::generic --quiet
53-
54- Runs bench for all pallets for westend runtime and fails fast on first failed benchmark
55- %(prog)s --runtime westend --fail-fast
56-
57- Does not output anything and cleans up the previous bot's & author command triggering comments in PR
58- %(prog)s --runtime westend rococo --pallet pallet_balances pallet_multisig --quiet --clean
59- '''
60-
61- parser_bench = subparsers .add_parser ('bench' , help = 'Runs benchmarks (old CLI)' , epilog = bench_example , formatter_class = argparse .RawDescriptionHelpFormatter )
62-
63- for arg , config in common_args .items ():
64- parser_bench .add_argument (arg , ** config )
65-
66- parser_bench .add_argument ('--runtime' , help = 'Runtime(s) space separated' , choices = runtimeNames , nargs = '*' , default = runtimeNames )
67- parser_bench .add_argument ('--pallet' , help = 'Pallet(s) space separated' , nargs = '*' , default = [])
68- parser_bench .add_argument ('--fail-fast' , help = 'Fail fast on first failed benchmark' , action = 'store_true' )
69-
70-
71- """
72- BENCH OMNI
73- """
74-
7547bench_example = '''**Examples**:
7648 Runs all benchmarks
7749 %(prog)s
@@ -86,14 +58,14 @@ def setup_logging():
8658 %(prog)s --runtime westend rococo --pallet pallet_balances pallet_multisig --quiet --clean
8759'''
8860
89- parser_bench_old = subparsers .add_parser ('bench-omni' , help = 'Runs benchmarks (frame omni bencher)' , epilog = bench_example , formatter_class = argparse .RawDescriptionHelpFormatter )
61+ parser_bench = subparsers .add_parser ('bench' , aliases = [ 'bench -omni'] , help = 'Runs benchmarks (frame omni bencher)' , epilog = bench_example , formatter_class = argparse .RawDescriptionHelpFormatter )
9062
9163for arg , config in common_args .items ():
92- parser_bench_old .add_argument (arg , ** config )
64+ parser_bench .add_argument (arg , ** config )
9365
94- parser_bench_old .add_argument ('--runtime' , help = 'Runtime(s) space separated' , choices = runtimeNames , nargs = '*' , default = runtimeNames )
95- parser_bench_old .add_argument ('--pallet' , help = 'Pallet(s) space separated' , nargs = '*' , default = [])
96- parser_bench_old .add_argument ('--fail-fast' , help = 'Fail fast on first failed benchmark' , action = 'store_true' )
66+ parser_bench .add_argument ('--runtime' , help = 'Runtime(s) space separated' , choices = runtimeNames , nargs = '*' , default = runtimeNames )
67+ parser_bench .add_argument ('--pallet' , help = 'Pallet(s) space separated' , nargs = '*' , default = [])
68+ parser_bench .add_argument ('--fail-fast' , help = 'Fail fast on first failed benchmark' , action = 'store_true' )
9769
9870
9971"""
@@ -127,7 +99,7 @@ def main():
12799
128100 print (f'args: { args } ' )
129101
130- if args .command == 'bench-omni' :
102+ if args .command == 'bench' or args . command == 'bench -omni' :
131103 runtime_pallets_map = {}
132104 failed_benchmarks = {}
133105 successful_benchmarks = {}
@@ -144,7 +116,14 @@ def main():
144116 for runtime in runtimesMatrix .values ():
145117 build_command = f"forklift cargo build -p { runtime ['package' ]} --profile { profile } --features={ runtime ['bench_features' ]} "
146118 print (f'-- building "{ runtime ["name" ]} " with `{ build_command } `' )
147- os .system (build_command )
119+ build_status = os .system (build_command )
120+ if build_status != 0 :
121+ print_and_log (f'❌ Failed to build { runtime ["name" ]} ' )
122+ if args .fail_fast :
123+ sys .exit (1 )
124+ else :
125+ continue
126+
148127 print (f'-- listing pallets for benchmark for { runtime ["name" ]} ' )
149128 wasm_file = f"target/{ profile } /wbuild/{ runtime ['package' ]} /{ runtime ['package' ].replace ('-' , '_' )} .wasm"
150129 list_command = f"frame-omni-bencher v1 benchmark pallet " \
@@ -219,12 +198,15 @@ def main():
219198 # TODO: we can remove once all pallets in dev runtime are migrated to polkadot-sdk-frame
220199 try :
221200 uses_polkadot_sdk_frame = "true" in os .popen (f"cargo metadata --locked --format-version 1 --no-deps | jq -r '.packages[] | select(.name == \" { pallet .replace ('_' , '-' )} \" ) | .dependencies | any(.name == \" polkadot-sdk-frame\" )'" ).read ()
201+ print (f'uses_polkadot_sdk_frame: { uses_polkadot_sdk_frame } ' )
222202 # Empty output from the previous os.popen command
223203 except StopIteration :
204+ print (f'Error: { pallet } not found in dev runtime' )
224205 uses_polkadot_sdk_frame = False
225206 template = config ['template' ]
226207 if uses_polkadot_sdk_frame and re .match (r"frame-(:?umbrella-)?weight-template\.hbs" , os .path .normpath (template ).split (os .path .sep )[- 1 ]):
227208 template = "substrate/.maintain/frame-umbrella-weight-template.hbs"
209+ print (f'template: { template } ' )
228210 else :
229211 default_path = f"./{ config ['path' ]} /src/weights"
230212 xcm_path = f"./{ config ['path' ]} /src/weights/xcm"
@@ -270,149 +252,6 @@ def main():
270252 print_and_log ('✅ Successful benchmarks of runtimes/pallets:' )
271253 for runtime , pallets in successful_benchmarks .items ():
272254 print_and_log (f'-- { runtime } : { pallets } ' )
273-
274- if args .command == 'bench' :
275- runtime_pallets_map = {}
276- failed_benchmarks = {}
277- successful_benchmarks = {}
278-
279- profile = "production"
280-
281- print (f'Provided runtimes: { args .runtime } ' )
282- # convert to mapped dict
283- runtimesMatrix = list (filter (lambda x : x ['name' ] in args .runtime , runtimesMatrix ))
284- runtimesMatrix = {x ['name' ]: x for x in runtimesMatrix }
285- print (f'Filtered out runtimes: { runtimesMatrix } ' )
286-
287- # loop over remaining runtimes to collect available pallets
288- for runtime in runtimesMatrix .values ():
289- build_command = f"forklift cargo build -p { runtime ['old_package' ]} --profile { profile } --features={ runtime ['bench_features' ]} --locked"
290- print (f'-- building { runtime ["name" ]} with `{ build_command } `' )
291- os .system (build_command )
292-
293- chain = runtime ['name' ] if runtime ['name' ] == 'dev' else f"{ runtime ['name' ]} -dev"
294-
295- machine_test = f"target/{ profile } /{ runtime ['old_bin' ]} benchmark machine --chain={ chain } "
296- print (f"Running machine test for `{ machine_test } `" )
297- os .system (machine_test )
298-
299- print (f'-- listing pallets for benchmark for { chain } ' )
300- list_command = f"target/{ profile } /{ runtime ['old_bin' ]} " \
301- f"benchmark pallet " \
302- f"--no-csv-header " \
303- f"--no-storage-info " \
304- f"--no-min-squares " \
305- f"--no-median-slopes " \
306- f"--all " \
307- f"--list " \
308- f"--chain={ chain } "
309- print (f'-- running: { list_command } ' )
310- output = os .popen (list_command ).read ()
311- raw_pallets = output .strip ().split ('\n ' )
312-
313- all_pallets = set ()
314- for pallet in raw_pallets :
315- if pallet :
316- all_pallets .add (pallet .split (',' )[0 ].strip ())
317-
318- pallets = list (all_pallets )
319- print (f'Pallets in { runtime ["name" ]} : { pallets } ' )
320- runtime_pallets_map [runtime ['name' ]] = pallets
321-
322- print (f'\n ' )
323-
324- # filter out only the specified pallets from collected runtimes/pallets
325- if args .pallet :
326- print (f'Pallets: { args .pallet } ' )
327- new_pallets_map = {}
328- # keep only specified pallets if they exist in the runtime
329- for runtime in runtime_pallets_map :
330- if set (args .pallet ).issubset (set (runtime_pallets_map [runtime ])):
331- new_pallets_map [runtime ] = args .pallet
332-
333- runtime_pallets_map = new_pallets_map
334-
335- print (f'Filtered out runtimes & pallets: { runtime_pallets_map } \n ' )
336-
337- if not runtime_pallets_map :
338- if args .pallet and not args .runtime :
339- print (f"No pallets { args .pallet } found in any runtime" )
340- elif args .runtime and not args .pallet :
341- print (f"{ args .runtime } runtime does not have any pallets" )
342- elif args .runtime and args .pallet :
343- print (f"No pallets { args .pallet } found in { args .runtime } " )
344- else :
345- print ('No runtimes found' )
346- sys .exit (1 )
347-
348- for runtime in runtime_pallets_map :
349- for pallet in runtime_pallets_map [runtime ]:
350- config = runtimesMatrix [runtime ]
351- header_path = os .path .abspath (config ['header' ])
352- template = None
353-
354- chain = config ['name' ] if runtime == 'dev' else f"{ config ['name' ]} -dev"
355-
356- print (f'-- config: { config } ' )
357- if runtime == 'dev' :
358- # to support sub-modules (https://github.com/paritytech/command-bot/issues/275)
359- search_manifest_path = f"cargo metadata --locked --format-version 1 --no-deps | jq -r '.packages[] | select(.name == \" { pallet .replace ('_' , '-' )} \" ) | .manifest_path'"
360- print (f'-- running: { search_manifest_path } ' )
361- manifest_path = os .popen (search_manifest_path ).read ()
362- if not manifest_path :
363- print (f'-- pallet { pallet } not found in dev runtime' )
364- if args .fail_fast :
365- print_and_log (f'Error: { pallet } not found in dev runtime' )
366- sys .exit (1 )
367- package_dir = os .path .dirname (manifest_path )
368- print (f'-- package_dir: { package_dir } ' )
369- print (f'-- manifest_path: { manifest_path } ' )
370- output_path = os .path .join (package_dir , "src" , "weights.rs" )
371- template = config ['template' ]
372- else :
373- default_path = f"./{ config ['path' ]} /src/weights"
374- xcm_path = f"./{ config ['path' ]} /src/weights/xcm"
375- output_path = default_path
376- if pallet .startswith ("pallet_xcm_benchmarks" ):
377- template = config ['template' ]
378- output_path = xcm_path
379-
380- print (f'-- benchmarking { pallet } in { runtime } into { output_path } ' )
381- cmd = f"target/{ profile } /{ config ['old_bin' ]} benchmark pallet " \
382- f"--extrinsic=* " \
383- f"--chain={ chain } " \
384- f"--pallet={ pallet } " \
385- f"--header={ header_path } " \
386- f"--output={ output_path } " \
387- f"--wasm-execution=compiled " \
388- f"--steps=50 " \
389- f"--repeat=20 " \
390- f"--heap-pages=4096 " \
391- f"{ f'--template={ template } ' if template else '' } " \
392- f"--no-storage-info --no-min-squares --no-median-slopes "
393- print (f'-- Running: { cmd } \n ' )
394- status = os .system (cmd )
395-
396- if status != 0 and args .fail_fast :
397- print_and_log (f'❌ Failed to benchmark { pallet } in { runtime } ' )
398- sys .exit (1 )
399-
400- # Otherwise collect failed benchmarks and print them at the end
401- # push failed pallets to failed_benchmarks
402- if status != 0 :
403- failed_benchmarks [f'{ runtime } ' ] = failed_benchmarks .get (f'{ runtime } ' , []) + [pallet ]
404- else :
405- successful_benchmarks [f'{ runtime } ' ] = successful_benchmarks .get (f'{ runtime } ' , []) + [pallet ]
406-
407- if failed_benchmarks :
408- print_and_log ('❌ Failed benchmarks of runtimes/pallets:' )
409- for runtime , pallets in failed_benchmarks .items ():
410- print_and_log (f'-- { runtime } : { pallets } ' )
411-
412- if successful_benchmarks :
413- print_and_log ('✅ Successful benchmarks of runtimes/pallets:' )
414- for runtime , pallets in successful_benchmarks .items ():
415- print_and_log (f'-- { runtime } : { pallets } ' )
416255
417256 elif args .command == 'fmt' :
418257 command = f"cargo +nightly fmt"
0 commit comments