|
35 | 35 |
|
36 | 36 | from powerapi import __version__ as powerapi_version |
37 | 37 | from powerapi.backend_supervisor import BackendSupervisor |
| 38 | +from powerapi.cli.common_cli_parsing_manager import CommonCLIParsingManager |
| 39 | +from powerapi.cli.config_parser import store_true |
38 | 40 | from powerapi.cli.generator import PusherGenerator, PullerGenerator |
39 | | -from powerapi.cli.parser import store_true |
40 | | -from powerapi.cli.tools import CommonCLIParser |
41 | 41 | from powerapi.dispatch_rule import HWPCDispatchRule, HWPCDepthLevel |
42 | 42 | from powerapi.dispatcher import DispatcherActor, RouteTable |
43 | | -from powerapi.exception import PowerAPIException |
| 43 | +from powerapi.exception import PowerAPIException, MissingArgumentException, NotAllowedArgumentValueException, \ |
| 44 | + FileDoesNotExistException |
44 | 45 | from powerapi.filter import Filter |
45 | 46 | from powerapi.report import HWPCReport |
46 | 47 |
|
|
51 | 52 | from smartwatts.model import CPUTopology |
52 | 53 |
|
53 | 54 |
|
54 | | -def generate_smartwatts_parser() -> CommonCLIParser: |
| 55 | +def generate_smartwatts_parser() -> CommonCLIParsingManager: |
55 | 56 | """ |
56 | 57 | Construct and returns the SmartWatts cli parameters parser. |
57 | 58 | :return: SmartWatts cli parameters parser |
58 | 59 | """ |
59 | | - parser = CommonCLIParser() |
| 60 | + parser_manager = CommonCLIParsingManager() |
60 | 61 |
|
61 | 62 | # Formula control parameters |
62 | | - parser.add_argument('disable-cpu-formula', help='Disable CPU formula', flag=True, type=bool, default=False, action=store_true) |
63 | | - parser.add_argument('disable-dram-formula', help='Disable DRAM formula', flag=True, type=bool, default=False, action=store_true) |
| 63 | + parser_manager.add_argument_to_cli_parser('disable-cpu-formula', help_text='Disable CPU formula', is_flag=True, |
| 64 | + argument_type=bool, default_value=False, action=store_true) |
| 65 | + parser_manager.add_argument_to_cli_parser('disable-dram-formula', help_text='Disable DRAM formula', is_flag=True, |
| 66 | + argument_type=bool, default_value=False, action=store_true) |
64 | 67 |
|
65 | 68 | # Formula RAPL reference event |
66 | | - parser.add_argument('cpu-rapl-ref-event', help='RAPL event used as reference for the CPU power models', default='RAPL_ENERGY_PKG') |
67 | | - parser.add_argument('dram-rapl-ref-event', help='RAPL event used as reference for the DRAM power models', default='RAPL_ENERGY_DRAM') |
| 69 | + parser_manager.add_argument_to_cli_parser('cpu-rapl-ref-event', |
| 70 | + help_text='RAPL event used as reference for the CPU power models', |
| 71 | + default_value='RAPL_ENERGY_PKG') |
| 72 | + parser_manager.add_argument_to_cli_parser('dram-rapl-ref-event', |
| 73 | + help_text='RAPL event used as reference for the DRAM power models', |
| 74 | + default_value='RAPL_ENERGY_DRAM') |
68 | 75 |
|
69 | 76 | # CPU topology information |
70 | | - parser.add_argument('cpu-tdp', help='CPU TDP (in Watt)', type=int, default=400) |
71 | | - parser.add_argument('cpu-base-clock', help='CPU base clock (in MHz)', type=int, default=100) |
72 | | - parser.add_argument('cpu-base-freq', help='CPU base frequency (in MHz)', type=int, default=2100) |
| 77 | + parser_manager.add_argument_to_cli_parser('cpu-tdp', help_text='CPU TDP (in Watt)', argument_type=int, |
| 78 | + default_value=400) |
| 79 | + parser_manager.add_argument_to_cli_parser('cpu-base-clock', help_text='CPU base clock (in MHz)', argument_type=int, |
| 80 | + default_value=100) |
| 81 | + parser_manager.add_argument_to_cli_parser('cpu-base-freq', help_text='CPU base frequency (in MHz)', |
| 82 | + argument_type=int, default_value=2100) |
73 | 83 |
|
74 | 84 | # Formula error threshold |
75 | | - parser.add_argument('cpu-error-threshold', help='Error threshold for the CPU power models (in Watt)', type=float, default=2.0) |
76 | | - parser.add_argument('dram-error-threshold', help='Error threshold for the DRAM power models (in Watt)', type=float, default=2.0) |
| 85 | + parser_manager.add_argument_to_cli_parser('cpu-error-threshold', |
| 86 | + help_text='Error threshold for the CPU power models (in Watt)', |
| 87 | + argument_type=float, default_value=2.0) |
| 88 | + parser_manager.add_argument_to_cli_parser('dram-error-threshold', |
| 89 | + help_text='Error threshold for the DRAM power models (in Watt)', |
| 90 | + argument_type=float, default_value=2.0) |
77 | 91 |
|
78 | 92 | # Sensor information |
79 | | - parser.add_argument('sensor-reports-frequency', help='The frequency with which measurements are made (in milliseconds)', type=int, default=1000) |
| 93 | + parser_manager.add_argument_to_cli_parser('sensor-reports-frequency', |
| 94 | + help_text='The frequency with which measurements are made (in milliseconds)', |
| 95 | + argument_type=int, default_value=1000) |
80 | 96 |
|
81 | 97 | # Learning parameters |
82 | | - parser.add_argument('learn-min-samples-required', help='Minimum amount of samples required before trying to learn a power model', type=int, default=10) |
83 | | - parser.add_argument('learn-history-window-size', help='Size of the history window used to keep samples to learn from', type=int, default=60) |
| 98 | + parser_manager.add_argument_to_cli_parser('learn-min-samples-required', |
| 99 | + help_text='Minimum amount of samples required before trying to learn a power model', |
| 100 | + argument_type=int, default_value=10) |
| 101 | + parser_manager.add_argument_to_cli_parser('learn-history-window-size', |
| 102 | + help_text='Size of the history window used to keep samples to learn from', |
| 103 | + argument_type=int, default_value=60) |
84 | 104 |
|
85 | | - return parser |
| 105 | + return parser_manager |
86 | 106 |
|
87 | 107 |
|
88 | 108 | def generate_formula_configuration(config: Dict, cpu_topology: CPUTopology, scope: SmartWattsFormulaScope) -> SmartWattsFormulaConfig: |
@@ -198,6 +218,15 @@ def term_handler(_, __): |
198 | 218 | except InvalidConfigurationParameterException as exn: |
199 | 219 | logging.error('Invalid configuration: %s', exn) |
200 | 220 | sys.exit(1) |
| 221 | + except MissingArgumentException as exn: |
| 222 | + logging.error('Missing argument: %s', exn) |
| 223 | + sys.exit(1) |
| 224 | + except NotAllowedArgumentValueException as exn: |
| 225 | + logging.error('Not Allowed Argument: %s', exn) |
| 226 | + sys.exit(1) |
| 227 | + except FileDoesNotExistException as exn: |
| 228 | + logging.error('File does not exist: %s', exn) |
| 229 | + sys.exit(1) |
201 | 230 |
|
202 | 231 | LOGGING_LEVEL = logging.DEBUG if args['verbose'] else logging.INFO |
203 | 232 | LOGGING_FORMAT = '%(asctime)s - %(process)d - %(processName)s - %(name)s - %(levelname)s - %(message)s' |
|
0 commit comments