trace.py 2.09 KB
Newer Older
1
2
3
import numpy as np
import matplotlib.pyplot as plt

Andreas Schmidt's avatar
Andreas Schmidt committed
4
from xlap.analyse.util import extract_durations
5
6
from ipywidgets import interact
import ipywidgets as widgets
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66


def _create_line(config):
    tr = config["time_reference"]
    color = {
        "sender": "#AAAAAA",
        "receiver": "#888888",
        "e2e": "black"
    }

    def _creator(duration_name):
        if duration_name == "EndToEnd":
            return [tr["sender"]["Start"] + "_T", tr["receiver"]["Stop"] + "_T", color["e2e"], "EndToEnd"]
        elif duration_name == "Sender":
            return [tr["sender"]["Start"] + "_T", tr["sender"]["Stop"] + "_T", color["sender"], "Sender"]
        elif duration_name == "Receiver":
            return [tr["receiver"]["Start"] + "_T", tr["receiver"]["Stop"] + "_T", color["receiver"], "Receiver"]
        else:
            duration = config["durations"][duration_name]
            return [duration["Start"] + "_T", duration["Stop"] + "_T", color[duration["Source"]], duration_name]

    return _creator


def trace(data_frame, config, export=False, file_name="TraceJitter.pdf"):
    """

    :param data_frame:
    :param config:
    :param export:
    :param file_name:
    :return:
    """

    fig, ax = plt.subplots(figsize=(8, 4.5))
    plt.grid()

    line_creator = _create_line(config)

    durations = [line_creator(x) for x in extract_durations(config)]

    series = np.transpose(np.array(durations))
    n = series.shape[1]

    # Starts and Ends
    tr = config["time_reference"]
    base = data_frame[tr["sender"]["Start"] + "_T"]
    starts = data_frame[series[0]] - base
    ends = data_frame[series[1]] - base

    plt.hlines(range(n), starts, ends, series[2], linewidths=[5])
    plt.xlabel("Time [us]")
    fig.canvas.draw()

    ax.set_yticklabels(series[3])
    ax.yaxis.set_ticks(np.arange(0, n, 1))

    if export:
        plt.savefig(file_name)
    plt.show()
67
68
69
70
71
72
73
74

def traces(df, config):
    """
    Display a slider to select sequence numbers and the respective trace.
    """
    @interact(seq_no=widgets.IntSlider(min=1,max=len(df),step=1,value=47))
    def _f(seq_no):
        trace(df.ix[seq_no],config)