Skip to content

Commit 9ab00b1

Browse files
remove old bench & revert the frame-weight-template (#7362)
- remove old bench from cmd.py and left alias for backward compatibility - reverted the frame-wight-template as the problem was that it umbrella template wasn't picked correctly in the old benchmarks, in frame-omni-bench it correctly identifies the dependencies and uses correct template --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 0dcb580 commit 9ab00b1

File tree

4 files changed

+110
-295
lines changed

4 files changed

+110
-295
lines changed

.github/scripts/cmd/cmd.py

Lines changed: 17 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,6 @@ def setup_logging():
4444
BENCH
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-
7547
bench_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

9163
for 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"

.github/workflows/runtimes-matrix.json

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"bench_features": "runtime-benchmarks",
99
"bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic,pallet_nomination_pools,pallet_remark,pallet_transaction_storage",
1010
"uri": null,
11-
"old_package": "staging-node-cli",
12-
"old_bin": "substrate-node",
1311
"is_relay": false
1412
},
1513
{
@@ -21,8 +19,6 @@
2119
"bench_flags": "",
2220
"bench_features": "runtime-benchmarks",
2321
"uri": "wss://try-runtime-westend.polkadot.io:443",
24-
"old_package": "polkadot",
25-
"old_bin": "polkadot",
2622
"is_relay": true
2723
},
2824
{
@@ -34,8 +30,6 @@
3430
"bench_features": "runtime-benchmarks",
3531
"bench_flags": "",
3632
"uri": "wss://try-runtime-rococo.polkadot.io:443",
37-
"old_package": "polkadot",
38-
"old_bin": "polkadot",
3933
"is_relay": true
4034
},
4135
{
@@ -47,8 +41,6 @@
4741
"bench_features": "runtime-benchmarks",
4842
"bench_flags": "",
4943
"uri": "wss://westend-asset-hub-rpc.polkadot.io:443",
50-
"old_package": "polkadot-parachain-bin",
51-
"old_bin": "polkadot-parachain",
5244
"is_relay": false
5345
},
5446
{
@@ -60,8 +52,6 @@
6052
"bench_features": "runtime-benchmarks",
6153
"bench_flags": "",
6254
"uri": "wss://rococo-asset-hub-rpc.polkadot.io:443",
63-
"old_package": "polkadot-parachain-bin",
64-
"old_bin": "polkadot-parachain",
6555
"is_relay": false
6656
},
6757
{
@@ -73,8 +63,6 @@
7363
"bench_features": "runtime-benchmarks",
7464
"bench_flags": "",
7565
"uri": "wss://rococo-bridge-hub-rpc.polkadot.io:443",
76-
"old_package": "polkadot-parachain-bin",
77-
"old_bin": "polkadot-parachain",
7866
"is_relay": false
7967
},
8068
{
@@ -86,8 +74,6 @@
8674
"bench_features": "runtime-benchmarks",
8775
"bench_flags": "",
8876
"uri": "wss://westend-bridge-hub-rpc.polkadot.io:443",
89-
"old_package": "polkadot-parachain-bin",
90-
"old_bin": "polkadot-parachain",
9177
"is_relay": false
9278
},
9379
{
@@ -99,8 +85,6 @@
9985
"bench_features": "runtime-benchmarks",
10086
"bench_flags": "",
10187
"uri": "wss://westend-collectives-rpc.polkadot.io:443",
102-
"old_package": "polkadot-parachain-bin",
103-
"old_bin": "polkadot-parachain",
10488
"is_relay": false
10589
},
10690
{
@@ -112,8 +96,6 @@
11296
"bench_features": "runtime-benchmarks",
11397
"bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm",
11498
"uri": "wss://rococo-contracts-rpc.polkadot.io:443",
115-
"old_package": "polkadot-parachain-bin",
116-
"old_bin": "polkadot-parachain",
11799
"is_relay": false
118100
},
119101
{
@@ -125,8 +107,6 @@
125107
"bench_features": "runtime-benchmarks",
126108
"bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic",
127109
"uri": "wss://rococo-coretime-rpc.polkadot.io:443",
128-
"old_package": "polkadot-parachain-bin",
129-
"old_bin": "polkadot-parachain",
130110
"is_relay": false
131111
},
132112
{
@@ -138,8 +118,6 @@
138118
"bench_features": "runtime-benchmarks",
139119
"bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic",
140120
"uri": "wss://westend-coretime-rpc.polkadot.io:443",
141-
"old_package": "polkadot-parachain-bin",
142-
"old_bin": "polkadot-parachain",
143121
"is_relay": false
144122
},
145123
{
@@ -151,8 +129,6 @@
151129
"bench_features": "runtime-benchmarks",
152130
"bench_flags": "--genesis-builder-policy=none",
153131
"uri": null,
154-
"old_package": "polkadot-parachain-bin",
155-
"old_bin": "polkadot-parachain",
156132
"is_relay": false
157133
},
158134
{
@@ -164,8 +140,6 @@
164140
"bench_features": "runtime-benchmarks",
165141
"bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic",
166142
"uri": "wss://rococo-people-rpc.polkadot.io:443",
167-
"old_package": "polkadot-parachain-bin",
168-
"old_bin": "polkadot-parachain",
169143
"is_relay": false
170144
},
171145
{
@@ -177,8 +151,6 @@
177151
"bench_features": "runtime-benchmarks",
178152
"bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic",
179153
"uri": "wss://westend-people-rpc.polkadot.io:443",
180-
"old_package": "polkadot-parachain-bin",
181-
"old_bin": "polkadot-parachain",
182154
"is_relay": false
183155
}
184156
]

substrate/.maintain/frame-weight-template.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
#![allow(unused_imports)]
1818
#![allow(missing_docs)]
1919

20-
use frame::weights_prelude::*;
20+
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
21+
use core::marker::PhantomData;
2122

2223
/// Weight functions needed for `{{pallet}}`.
2324
pub trait WeightInfo {

0 commit comments

Comments
 (0)