コード例 #1
0
    def run(self):
        # Setup signal handler
        def term_handler(_, __):
            puller.send_kill()
            dispatcher.send_kill()
            pusher.send_kill()
            exit(0)

        signal.signal(signal.SIGTERM, term_handler)
        signal.signal(signal.SIGINT, term_handler)

        stream_mode = True
        supervisor = BackendSupervisor(stream_mode)

        # Pusher
        output_mongodb = MongoDB(DB_URI, 'MongoDB1', 'test_result',
                                 HWPCModel())
        pusher = PusherActor("pusher_mongodb",
                             PowerReport,
                             output_mongodb,
                             level_logger=LOG_LEVEL)

        # Formula
        formula_factory = (lambda name, verbose: RAPLFormulaActor(
            name, pusher, level_logger=verbose))

        # Dispatcher
        route_table = RouteTable()
        route_table.dispatch_rule(
            HWPCReport,
            HWPCDispatchRule(getattr(HWPCDepthLevel, 'ROOT'), primary=True))

        dispatcher = DispatcherActor('dispatcher',
                                     formula_factory,
                                     route_table,
                                     level_logger=LOG_LEVEL)

        # Puller
        input_mongodb = MongoDB(DB_URI,
                                'MongoDB1',
                                'test_hwrep',
                                HWPCModel(),
                                stream_mode=stream_mode)
        report_filter = Filter()
        report_filter.filter(lambda msg: True, dispatcher)
        puller = PullerActor("puller_mongodb",
                             input_mongodb,
                             report_filter,
                             level_logger=LOG_LEVEL)

        supervisor.launch_actor(pusher)
        supervisor.launch_actor(dispatcher)
        supervisor.launch_actor(puller)
        time.sleep(1)

        os.kill(dispatcher.pid, signal.SIGKILL)

        supervisor.join()
コード例 #2
0
def run_selfwatts(args) -> None:
    """
    Run PowerAPI with the SelfWatts formula.
    :param args: CLI arguments namespace
    """
    fconf = args['formula']['selfwatts']

    logging.info('SelfWatts version %s using PowerAPI version %s', selfwatts_version, powerapi_version)

    if fconf['disable-cpu-formula'] and fconf['disable-dram-formula']:
        logging.error('You need to enable at least one formula')
        return

    route_table = RouteTable()
    route_table.dispatch_rule(HWPCReport, HWPCDispatchRule(HWPCDepthLevel.SOCKET, primary=True))

    cpu_topology = CPUTopology(fconf['cpu-tdp'], fconf['cpu-base-clock'], fconf['cpu-ratio-min'],
                               fconf['cpu-ratio-base'], fconf['cpu-ratio-max'],
                               fconf['cpu-num-fixed-counters'], fconf['cpu-num-general-counters'])

    report_filter = Filter()
    pullers = PullerGenerator(report_filter).generate(args)

    pushers = PusherGenerator().generate(args)

    dispatchers = {}

    logging.info('CPU formula is %s' % ('DISABLED' if fconf['disable-cpu-formula'] else 'ENABLED'))
    if not fconf['disable-cpu-formula']:
        logging.info('CPU formula parameters: RAPL_REF=%s ERROR_THRESHOLD=%sW' % (fconf['cpu-rapl-ref-event'], fconf['cpu-error-threshold']))
        dispatchers['cpu'] = setup_cpu_formula_actor(fconf, route_table, report_filter, cpu_topology, pushers)

    logging.info('DRAM formula is %s' % ('DISABLED' if fconf['disable-dram-formula'] else 'ENABLED'))
    if not fconf['disable-dram-formula']:
        logging.info('DRAM formula parameters: RAPL_REF=%s ERROR_THRESHOLD=%sW' % (fconf['dram-rapl-ref-event'], fconf['dram-error-threshold']))
        dispatchers['dram'] = setup_dram_formula_actor(fconf, route_table, report_filter, cpu_topology, pushers)

    actors = OrderedDict(**pushers, **dispatchers, **pullers)

    def term_handler(_, __):
        for _, actor in actors.items():
            actor.soft_kill()
        exit(0)

    signal.signal(signal.SIGTERM, term_handler)
    signal.signal(signal.SIGINT, term_handler)

    supervisor = BackendSupervisor(config['stream'])
    try:
        logging.info('Starting SelfWatts actors...')
        for _, actor in actors.items():
            supervisor.launch_actor(actor)
    except ActorInitError as exn:
        logging.error('Actor initialization error: ' + exn.message)
        supervisor.kill_actors()

    logging.info('SelfWatts is now running...')
    supervisor.join()
    logging.info('SelfWatts is shutting down...')
コード例 #3
0
def launch_powerapi(config, logger):
    ##########################################################################
    # Actor Creation

    # Pusher
    pushers = generate_pushers(config)

    # Formula
    formula_factory = (lambda name, verbose: RAPLFormulaActor(
        name, pushers, level_logger=verbose))

    # Dispatcher
    route_table = RouteTable()
    route_table.dispatch_rule(
        HWPCReport,
        HWPCDispatchRule(getattr(HWPCDepthLevel, 'ROOT'), primary=True))

    dispatcher = DispatcherActor('dispatcher',
                                 formula_factory,
                                 route_table,
                                 level_logger=config['verbose'])

    # Puller
    report_filter = Filter()
    report_filter.filter(lambda msg: True, dispatcher)
    pullers = generate_pullers(config, report_filter)

    ##########################################################################
    # Actor start step

    # Setup signal handler
    def term_handler(_, __):
        for _, puller in pullers.items():
            puller.send_kill()

        dispatcher.send_kill()

        for _, pusher in pushers.items():
            pusher.send_kill()
        exit(0)

    signal.signal(signal.SIGTERM, term_handler)
    signal.signal(signal.SIGINT, term_handler)

    supervisor = BackendSupervisor(config['stream'])
    try:
        for _, pusher in pushers.items():
            supervisor.launch_actor(pusher)

        supervisor.launch_actor(dispatcher)

        for _, puller in pullers.items():
            supervisor.launch_actor(puller)

    except zmq.error.ZMQError as exn:
        logger.error('Communication error, ZMQError code : ' + str(exn.errno) +
                     ' reason : ' + exn.strerror)
        supervisor.kill_actors()
    except ActorInitError as exn:
        logger.error('Actor initialisation error, reason : ' + exn.message)
        supervisor.kill_actors()

    ##########################################################################
    # Actor run step

    # wait
    supervisor.join()
コード例 #4
0
def supervisor(database, stream_mode):
    """
    Create a supervisor
    """
    supervisor = BackendSupervisor(stream_mode)
    yield supervisor
コード例 #5
0
def supervisor(stream_mode):
    """
    Create a supervisor
    """
    return BackendSupervisor(stream_mode)
コード例 #6
0
def supervisor(database):
    """
    Create a supervisor
    """
    supervisor = BackendSupervisor(True)
    yield supervisor
コード例 #7
0
def supervisor():
    s = BackendSupervisor(False)
    yield s
    s.kill_actors()