Coverage for mlos_bench/mlos_bench/config/environments/os/linux/runtime/scripts/local/generate_kernel_config_script.py: 21%
14 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-22 01:18 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-22 01:18 +0000
1#!/usr/bin/env python3
2#
3# Copyright (c) Microsoft Corporation.
4# Licensed under the MIT License.
5#
6"""
7Helper script to generate a script to update kernel parameters from tunables JSON.
9Run:
10 ./generate_kernel_config_script.py \
11 ./kernel-params.json ./kernel-params-meta.json \
12 ./config-kernel.sh
13"""
15import argparse
16import json
19def _main(fname_input: str, fname_meta: str, fname_output: str) -> None:
21 with open(fname_input, "rt", encoding="utf-8") as fh_tunables:
22 tunables_data = json.load(fh_tunables)
24 with open(fname_meta, "rt", encoding="utf-8") as fh_meta:
25 tunables_meta = json.load(fh_meta)
27 with open(fname_output, "wt", encoding="utf-8", newline="") as fh_config:
28 for key, val in tunables_data.items():
29 meta = tunables_meta.get(key, {})
30 name_prefix = meta.get("name_prefix", "")
31 line = f'echo "{val}" > {name_prefix}{key}'
32 fh_config.write(line + "\n")
33 print(line)
36if __name__ == "__main__":
38 parser = argparse.ArgumentParser(
39 description="generate a script to update kernel parameters from tunables JSON."
40 )
42 parser.add_argument("input", help="JSON file with tunable parameters.")
43 parser.add_argument("meta", help="JSON file with tunable parameters metadata.")
44 parser.add_argument("output", help="Output shell script to configure Linux kernel.")
46 args = parser.parse_args()
48 _main(args.input, args.meta, args.output)