How to use the powerapi.dispatcher.DispatcherActor function in powerapi

To help you get started, we’ve selected a few powerapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github powerapi-ng / powerapi / tests / integration / dispatcher / test_integration_dispatcher.py View on Github external
def dispatcher2(request, route_table):
    """
    return an instance of a second DispatcherActor with the same name that the
    first dispatcher that is not launched the teardown of this fixtures
    terminate the actor (in case it was started and close its socket)
    """
    dispatcher_actor = DispatcherActor(
        'test_dispatcher-',
        lambda name, log: FakeFormulaActor(name, FORMULA_SOCKET_ADDR,
                                           level_logger=log),
        route_table,
        level_logger=LOG_LEVEL)
    yield dispatcher_actor
    dispatcher_actor.socket_interface.close()
    dispatcher_actor.terminate()
    dispatcher_actor.join()
github powerapi-ng / powerapi / test / .test_dispatcher_actor.py View on Github external
def create_formula_dispatcher():
    """Create the formula dispatcher and initialize its group_by rules"""
    formula_dispatcher = DispatcherActor('fd', None, None)
    formula_dispatcher.group_by(Report1, FakeGroupBy1(primary=True))
    formula_dispatcher.group_by(Report2, FakeGroupBy2())
    return formula_dispatcher
github powerapi-ng / powerapi / tests / acceptation / test_crash_dispatcher.py View on Github external
stream_mode = True
        supervisor = BackendSupervisor(stream_mode)

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

        # Formula
        formula_factory = (lambda name, verbose:
                           DummyFormulaActor(name, {'id_pusher': 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')
        report_filter = Filter()
        report_filter.filter(lambda msg: True, dispatcher)
        puller = PullerActor("puller_mongodb", input_mongodb,
                             report_filter, HWPCModel(), stream_mode=stream_mode, 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)
github powerapi-ng / powerapi / test / .test_dispatcher_actor.py View on Github external
def formula_dispatcher(request, message_interceptor):
    """Initialize the formula dispatcher

    The formula dispatcher is reinitialized for each test function

    It use the group_by rule contained in group_by_list attribute of the test
    class used

    """
    dispatcher = DispatcherActor('fd', lambda name, verbose:
                                 MockedFormula(name, message_interceptor, verbose=verbose),
                                 verbose=True)

    group_by_list = getattr(request.instance, 'group_by_list', None)
    for report_class, group_by_rule in group_by_list:
        dispatcher.group_by(report_class, group_by_rule)

    context = zmq.Context()
    dispatcher.start()
    dispatcher.connect(context)
    yield dispatcher
    dispatcher.kill()
    message_interceptor.clear_message()
    time.sleep(0.2)
github powerapi-ng / powerapi / tests / integration / dispatcher / test_integration_dispatcher.py View on Github external
def dispatcher(request, route_table):
    """
    return an instance of a DispatcherActor that is not launched
    """
    dispatcher_actor = DispatcherActor(
        'test_dispatcher-',
        lambda name, log: FakeFormulaActor(name, FORMULA_SOCKET_ADDR,
                                           level_logger=log),
        route_table,
        level_logger=LOG_LEVEL)
    return dispatcher_actor
github powerapi-ng / powerapi / tests / acceptation / test_hight_load.py View on Github external
Test if:
      - each 50 ms, reports are writen in the output database
    """
    # Pusher
    output_mongodb = MongoDB(DB_URI, 'MongoDB1', 'test_result')
    pusher = PusherActor("pusher_mongodb", PowerModel(), output_mongodb, level_logger=LOG_LEVEL)

    # Formula
    formula_factory = (lambda name, verbose:
                       DummyFormulaActor(name, {'my_pusher': pusher}, level_logger=verbose))

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

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

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

    supervisor.launch_actor(pusher)
    supervisor.launch_actor(dispatcher)
    supervisor.launch_actor(puller)


    t = time.time()
    number_of_output_reports = 0
    for i in range(3):
        time.sleep(0.2)
github powerapi-ng / powerapi / powerapi / backendsupervisor / backend_supervisor.py View on Github external
def join(self):
        """
        wait until all actor are terminated
        """
        # List the different kind of actor
        for actor in self.supervised_actors:
            if isinstance(actor, PullerActor):
                self.pullers.append(actor)
            elif isinstance(actor, DispatcherActor):
                self.dispatchers.append(actor)
            else:
                self.pushers.append(actor)

        if self.stream_mode:
            self.join_stream_mode_on()
        else:
            self.join_stream_mode_off()
github powerapi-ng / powerapi / powerapi-cli.py View on Github external
output_mongodb = MongoDB(args.output_uri,
                             args.output_db, args.output_collection,
                             HWPCModel())
    pusher = PusherActor("pusher_mongodb", PowerReport, output_mongodb,
                         level_logger=args.verbose)

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

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

    dispatcher = DispatcherActor('dispatcher', formula_factory, route_table,
                                 level_logger=args.verbose)

    # Puller
    input_mongodb = MongoDB(args.input_uri,
                            args.input_db, args.input_collection,
                            HWPCModel(), stream_mode=args.stream_mode)
    report_filter = Filter()
    report_filter.filter(lambda msg: True, dispatcher)
    puller = PullerActor("puller_mongodb", input_mongodb,
                         report_filter, level_logger=args.verbose)

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

    # Setup signal handler
    def term_handler(_, __):