コード例 #1
0
def smff_test(filename, outfile, plot, verbose):

    options.init_pycpa()

    print "loading", filename
    loader = smff_loader.SMFFLoader()
    s = loader.parse(filename)


    if plot == True:
        # graph the smff system
        graph_file = string.replace(os.path.basename(filename), ".xml", "") + ".pdf"
        graph.graph_system(s, sched_param=True, exec_times=True, filename=graph_file)

    try:
        # analyze the system
        results = analysis.analyze_system(s)

        # print some analysis results

        print("Result:")
        for r in sorted(s.resources, key=str):
            print "results for resource %s" % r.name
            for t in sorted(r.tasks, key=str):
                print("%s - %d " % (str(t.name) , results[t].wcrt))

        if outfile is not None:
            # backannotate the xml
            loader.annotate_results()

            # write it
            loader.write(filename=outfile)

    except analysis.NotSchedulableException as (e):
        print str(e)
コード例 #2
0
def sampling_test(wclat_results):

    options.init_pycpa()

    # generate an new system
    s = model.System()

    # add two resources to the system
    # register two schedulers
    r1 = s.bind_resource(model.Resource("R1", schedulers.SPPScheduler()))

    # add a task
    t11 = r1.bind_task(model.Task(name="T11", wcet=3, bcet=1, scheduling_parameter=1))
    # register input event model
    t11.in_event_model = model.PJdEventModel(P=30, J=15)

    # add three more tasks, these will be triggered by other tasks
    t12 = r1.bind_task(model.Task(name="T12", wcet=3, bcet=2, scheduling_parameter=2))

    # add a sampling junction
    j1 = s.bind_junction(model.Junction(name="J1", strategy=junctions.SampledInput()))
    j1.strategy.set_trigger_event_model(model.PJdEventModel(P=50, J=0))

    # register a task chain as a stream: t11->j1->t12
    s1 = s.bind_path(model.Path("S1", [t11, j1, t12]))

    # graph the system
    graph.graph_system(s, "sampling_example.pdf")

    # analyze the system
    print("Performing analysis")
    results = analysis.analyze_system(s)

    # print the results
    print("Result:")
    for r in sorted(s.resources, key=str):
        print "load on resource %s: %0.2f" % (r.name, r.load())
        for t in sorted(r.tasks, key=str):
            print "  task %s - wcrt: %d" % (t.name, results[t].wcrt)

    # calculate the latency for the first 10 events
    for n in range(1, 11):
        best_case_latency, worst_case_latency = path_analysis.end_to_end_latency(s1, results, n)
        print("stream S1 e2e latency. best case: %d, worst case: %d" % (best_case_latency, worst_case_latency))
        assert(worst_case_latency == wclat_results[n-1])
コード例 #3
0
ファイル: spp_test.py プロジェクト: jiankangren/pyCPA
def spp_test():
    # init pycpa and trigger command line parsing
    options.init_pycpa()

    # generate an new system
    s = model.System()

    # add two resources (CPUs) to the system
    # and register the static priority preemptive scheduler
    r1 = s.bind_resource(model.Resource("R1", schedulers.SPPScheduler()))
    r2 = s.bind_resource(model.Resource("R2", schedulers.SPPScheduler()))

    # create and bind tasks to r1
    t11 = r1.bind_task(
        model.Task("T11", wcet=10, bcet=5, scheduling_parameter=1))
    t12 = r1.bind_task(
        model.Task("T12", wcet=3, bcet=1, scheduling_parameter=2))

    # create and bind tasks to r2
    t21 = r2.bind_task(
        model.Task("T21", wcet=2, bcet=2, scheduling_parameter=1))
    t22 = r2.bind_task(
        model.Task("T22", wcet=9, bcet=4, scheduling_parameter=2))

    # specify precedence constraints: T11 -> T21; T12-> T22
    t11.link_dependent_task(t21)
    t12.link_dependent_task(t22)

    # register a periodic with jitter event model for T11 and T12
    t11.in_event_model = model.PJdEventModel(P=30, J=5)
    t12.in_event_model = model.PJdEventModel(P=15, J=6)

    # plot the system graph to visualize the architecture
    g = graph.graph_system(s, 'spp_graph.pdf', dotout='spp_graph.dot')

    # perform the analysis
    print("Performing analysis")
    task_results = analysis.analyze_system(s)

    # print the worst case response times (WCRTs)
    print("Result:")
    for r in sorted(s.resources, key=str):
        for t in sorted(r.tasks, key=str):
            print("%s: wcrt=%d" % (t.name, task_results[t].wcrt))
            print("    b_wcrt=%s" % (task_results[t].b_wcrt_str()))

    expected_wcrt = dict()
    expected_wcrt[t11] = 10
    expected_wcrt[t12] = 13
    expected_wcrt[t21] = 2
    expected_wcrt[t22] = 19

    for t in expected_wcrt.keys():
        assert (expected_wcrt[t] == task_results[t].wcrt)
コード例 #4
0
ファイル: cparpc.py プロジェクト: jiankangren/pyCPA
    def xmlrpc_graph_system(self, system_id, filename):
        """ Generate a graph of the system (in server directory).
        It uses graphviz for plotting, so the 'dot' command must be in the PATH
        of the server environment.

        :param system_id: ID of the system to analyze
        :type system_id: string
        :param filename: File name (relative to server working directory) to which to store the graph.
        :type filename: string
        :returns: 0

        """
        try:
            import pygraphviz
        except ImportError:
            raise xmlrpc.Fault(GENERAL_ERROR,
                               "graph not supported on this platform.")

        s = self._obj_from_id(system_id, model.System)

        graph.graph_system(s, filename)
        return 0
コード例 #5
0
ファイル: simple.py プロジェクト: jiankangren/pyCPA
def simple_test():
    # initialyze pycpa. (e.g. read command line switches and set up default options)
    options.init_pycpa()

    # generate an new system
    s = model.System()

    # instantiate a resource
    r1 = s.bind_resource(model.Resource("R1", schedulers.SPPScheduler()))

    # create and bind tasks to r1
    t11 = r1.bind_task(
        model.Task("T11", wcet=5, bcet=5, scheduling_parameter=1))
    t12 = r1.bind_task(
        model.Task("T12", wcet=9, bcet=1, scheduling_parameter=2))

    # connect communicating tasks: T11 -> T12
    t11.link_dependent_task(t12)

    # register a PJd event model
    t11.in_event_model = model.PJdEventModel(P=30, J=60)

    # create a path
    p1 = model.Path("P1", [t11, t12])

    # add constraints to task t11
    s.constraints.add_backlog_constraint(t11, 5)

    # add constraints to task t12
    s.constraints.add_wcrt_constraint(t12, 90)

    try:
        # plot the system graph to visualize the architecture
        g = graph.graph_system(s, 'simple_graph.pdf')
    except Exception:
        # gracefully pass for machines without matplotlib
        pass

    # perform the analysis
    print("Performing analysis")
    results = analysis.analyze_system(s)

    # print the worst case response times (WCRTs)
    print("Result:")
    for r in sorted(s.resources, key=str):
        for t in sorted(r.tasks, key=str):
            print("%s: wcrt=%d" % (t.name, results[t].wcrt))

    bcl, wcl = path_analysis.end_to_end_latency(p1, results, 2)
    print "bcl: %d, wcl: %d" % (bcl, wcl)
コード例 #6
0
def rr_test():

    options.init_pycpa()

    s = model.System()
    r1 = s.bind_resource(model.Resource("R1",
                                        schedulers.RoundRobinScheduler()))
    r2 = s.bind_resource(model.Resource("R2",
                                        schedulers.RoundRobinScheduler()))

    # create and bind tasks
    # the scheduling_parameter denotes the slot size
    t11 = r1.bind_task(
        model.Task(name="T11", wcet=1, bcet=1, scheduling_parameter=1))
    t12 = r1.bind_task(
        model.Task(name="T12", wcet=1, bcet=1, scheduling_parameter=1))
    t21 = r2.bind_task(
        model.Task(name="T21", wcet=1, bcet=1, scheduling_parameter=1))
    t22 = r2.bind_task(
        model.Task(name="T22", wcet=1, bcet=1, scheduling_parameter=1))

    t11.link_dependent_task(t21)
    t22.link_dependent_task(t12)

    t11.in_event_model = model.CTEventModel(c=1, T=5)
    t22.in_event_model = model.CTEventModel(c=5, T=17)

    print("Performing analysis")
    results = analysis.analyze_system(s)

    print("Result:")
    for r in sorted(s.resources, key=str):
        for t in sorted(r.tasks, key=str):
            print(t, " - ", results[t].wcrt)
            print("    b_wcrt=%s" % (results[t].b_wcrt_str()))

    graph.graph_system(s, show=options.get_opt('show'))
コード例 #7
0
ファイル: cparpc.py プロジェクト: jiankangren/pyCPA
    def xmlrpc_graph_system_dot(self, system_id, filename):
        """ Generate a graph of the system in dot file format (in server directory).
        The resulting file can be converted using graphviz.
        E.g. to create a PDF, run:
           dot -Tpdf <filename> -o out.pdf

        :param system_id: ID of the system to analyze
        :type system_id: string
        :param filename: File name (relative to server working directory) to which to write to. If empty, return dot file as string only.
        :type filename: string
        :returns: string representation of graph in dot format
        :rtype: string
        """

        s = self._obj_from_id(system_id, model.System)

        if filename == '':
            filename = None

        g = graph.graph_system(s, dotout=filename)
        return g.string()
コード例 #8
0
ファイル: tdma_test.py プロジェクト: jiankangren/pyCPA
def tdma_test():

    options.init_pycpa()

    s = model.System()
    r1 = s.bind_resource(model.Resource("R1", schedulers.TDMAScheduler()))
    r2 = s.bind_resource(model.Resource("R2", schedulers.TDMAScheduler()))

    # scheduling_parameter denotes the slotsize
    t11 = r1.bind_task(
        model.Task("T11", wcet=10, bcet=5, scheduling_parameter=2))
    t12 = r1.bind_task(
        model.Task("T12", wcet=3, bcet=1, scheduling_parameter=2))

    t21 = r2.bind_task(
        model.Task("T21", wcet=2, bcet=2, scheduling_parameter=2))
    t22 = r2.bind_task(
        model.Task("T22", wcet=3, bcet=3, scheduling_parameter=2))

    t11.link_dependent_task(t21)
    t12.link_dependent_task(t22)

    t11.in_event_model = model.PJdEventModel()
    t11.in_event_model.set_PJd(30, 5)

    t12.in_event_model = model.PJdEventModel()
    t12.in_event_model.set_PJd(15, 6)

    g = graph.graph_system(s, 'tdma_graph.pdf')

    print("Performing analysis")
    results = analysis.analyze_system(s)

    print("Result:")
    for r in sorted(s.resources, key=str):
        for t in sorted(r.tasks, key=str):
            print str(t), " - ", results[t].wcrt
            print "    ", results[t].b_wcrt_str()
コード例 #9
0
        "ytick.labelsize": 6,
        "lines.markersize": 3.5
    }
    mpl.rcParams.update(settings)

def generate_charts_for_paper(dir='.'):
    """Generate the charts for the ECRTS paper."""
    plt.close()
    configure_mpl_for_tex()
    plot_e2e_per_alpha()
    plt.savefig(dir + '/latency_per_budget.pdf', bbox_inches='tight')

    plt.cla()
    plot_e2e_per_jitter()
    plt.savefig(dir + '/latency_per_jitter.pdf', bbox_inches='tight')

def generate_chart_for_talk(dir='.'):
    """Generate the chart for the ECRTS presentation"""
    plt.close()
    mpl.rc('figure', figsize=(10.9,4.32))
    plot_e2e_per_jitter(add_disabled_chain=False)
    plt.savefig(dir + '/e2e_per_jitter.png', dpi=600, bbox_inches='tight', transparent=True)
if __name__ == "__main__":
    for num_res in [1, 2]:
        for mname, m in models.items():
            s = m(num_res)
            graph_system(s, filename='{}-{}.pdf'.format(mname, num_res),
                         dotout='{}-{}.dot'.format(mname, num_res), show=False)

    generate_charts_for_paper()