nrmd 5 KB
Newer Older
1 2
#!/usr/bin/env python2

3 4 5 6 7 8 9 10 11 12
###############################################################################
# Copyright 2019 UChicago Argonne, LLC.
# (c.f. AUTHORS, LICENSE)
#
# This file is part of the NRM project.
# For more info, see https://xgitlab.cels.anl.gov/argo/nrm
#
# SPDX-License-Identifier: BSD-3-Clause
###############################################################################

13 14 15
import argparse
import json
import sys
16 17
import nrm
import nrm.daemon
18 19
import os

20

21
def main(argv=None):
22 23
    if argv is None:
        argv = sys.argv
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    conf_parser = argparse.ArgumentParser(
      description=__doc__,
      formatter_class=argparse.RawDescriptionHelpFormatter,
      add_help=False
      )
    conf_parser.add_argument(
            "-c",
            "--configuration",
            help="Specify a config json-formatted config file to override "
                 "any of the available CLI options. If an option is "
                 "actually provided on the command-line, it overrides "
                 "its corresponding value from the configuration file.",
            metavar="FILE")
    conf_parser.add_argument("-d", "--print_defaults", action='store_true',
                             help="Print the default configuration file.")
    args, remaining_argv = conf_parser.parse_known_args()
41

42 43 44
    defaults = {"nrm_log": "/tmp/nrm.log",
                "hwloc": "hwloc",
                "perf": "perf",
45
                "argo_perf_wrapper": "nrm-perfwrapper",
46 47
                "argo_nodeos_config": "argo_nodeos_config",
                "pmpi_lib": "/usr/lib/libnrm-pmpi.so",
48 49
                "singularity": "singularity",
                "container_runtime": "nodeos",
50
                }
51

52
    if args.print_defaults:
53
        print(defaults)
54
        return(0)
55

56 57 58 59 60
    if args.configuration:
        defaults.update(json.load(open(args.configuration)))

    parser = argparse.ArgumentParser(parents=[conf_parser])
    parser.set_defaults(**defaults)
61 62
    parser.add_argument("-v", "--verbose", help="increase output verbosity",
                        action="store_true")
63 64
    parser.add_argument(
           "--nrm_log",
65
           help="Main log file. Override default with the NRM_LOG "
66 67 68
                "environment variable",
           default=os.environ.get('NRM_LOG',
                                  '/tmp/nrm.log'))
69 70 71 72
    parser.add_argument(
            '--msr_safe',
            help="Whether to use msr_safe instead of RAPL",
            default=True)
73 74 75
    parser.add_argument(
            '--hwloc',
            help="Path to the hwloc to use. This path can be "
76 77
                 "relative and makes uses of the $PATH if necessary. "
                 "Override default with the HWLOC environment "
78 79 80 81 82 83 84 85 86 87 88 89 90
                 "variable.",
            default=os.environ.get('HWLOC',
                                   'hwloc'))
    parser.add_argument(
            '--argo_nodeos_config',
            help="Path to the argo_nodeos_config to use. This path "
                 "can be relative and makes uses of the $PATH if "
                 "necessary. Override default with the "
                 "ARGO_NODEOS_CONFIG environment variable.",
            default=os.environ.get('ARGO_NODEOS_CONFIG',
                                   'argo_nodeos_config'))
    parser.add_argument(
            '--perf',
91 92 93
            help="Path to the linux perf tool to use. This path can be "
                 "relative and makes uses of the $PATH if necessary. "
                 "Override default with the PERF environment "
94 95 96
                 "variable.",
            default=os.environ.get('PERF',
                                   'perf'))
97 98
    parser.add_argument(
            '--pmpi_lib',
99
            help="Path to the libnrm PMPI library used for the power policy. "
100 101
                 "Override default with the PMPI environment variable.",
            default=os.environ.get('PMPI', defaults['pmpi_lib']))
102 103
    parser.add_argument(
            '--argo_perf_wrapper',
104
            help="Path to the linux perf tool to use. This path can "
105 106 107 108
                 "be relative and makes uses of the $PATH if "
                 "necessary. Override default with the PERFWRAPPER "
                 "environment variable.",
            default=os.environ.get('ARGO_PERF_WRAPPER',
109
                                   'nrm-perfwrapper'))
110 111 112 113 114 115 116 117 118 119 120 121 122 123
    parser.add_argument(
            '--singularity',
            help="Path to the singularity command. "
                 "Override default with the SINGULARITY environment variable.",
            default=os.environ.get('SINGULARITY', defaults['singularity']))
    parser.add_argument(
            '--container-runtime',
            help="Choice of container runtime. "
                 "Override default with the ARGO_CONTAINER_RUNTIME "
                 "environment variable.",
            choices=['nodeos', 'singularity'],
            default=os.environ.get('ARGO_CONTAINER_RUNTIME',
                                   defaults['container_runtime']))

124 125 126
    args = parser.parse_args(remaining_argv)
    nrm.daemon.runner(config=args)
    return(0)
127

128 129

if __name__ == "__main__":
130
    sys.exit(main())