command_line.py 2.29 KB
Newer Older
1
2
import argparse

3
from xlap.parse import evaluate, parse_config
4
import xlap.analyse.jitter as jitter
5
import xlap.analyse.latency as latency
6

7
tasks = {
8
    "jitter": None,
9
    "latency": None,
10
    "capture": None
11
12
}

Andreas Schmidt's avatar
Andreas Schmidt committed
13

14
15
16
17
def main():
    config = parse_config()
    data_files = config["data_files"]

18
    parser = argparse.ArgumentParser()
Andreas Schmidt's avatar
Andreas Schmidt committed
19
20
    parser.add_argument("tasks", metavar="T", type=str, nargs="+", help="Analysis tasks to execute")
    parser.add_argument("-e", "--export", dest="export", action="store_true", default=False, help="Output pdf files.")
21
22
23
24
25
26
    args = parser.parse_args()

    for command in args.tasks:
        if command not in tasks.keys():
            print("{} is not a known analysis task.".format(command))
            continue
27

28
29
        if command == "capture":
            types = ",\n".join(["     ts_{}_packet = {}".format(k.lower(),v) for k,v in config["packet_types"].items()])
Andreas Schmidt's avatar
Andreas Schmidt committed
30

31
            typedef = "typedef enum XlapTimestampPacketKind {{\n{}\n}} XlapTimestampPacketKind".format(types)
Andreas Schmidt's avatar
Andreas Schmidt committed
32

33
34
            timestamp = "#define TIMESTAMP_ID_LIST \\\n"
            timestamp += ", \\\n".join([" " * 8 + x for x in config["stamps"].keys()])
Andreas Schmidt's avatar
Andreas Schmidt committed
35

36
37
38
39
40
41
42
43
            output = "#ifndef {0}\n#define {0}\n\n{1}\n\n{2}\n\n#endif // {0}".format("XLAP_CAPTURE_H", typedef, timestamp)

            if args.export:
                with open("xlap_capture.h", "w") as f:
                    f.write(output)
                    f.write("\n")
            else:
                print(output)
44
45
        elif command == "latency":
            df_data = evaluate(data_files["sender"], data_files["receiver"], config=config, kind=0)
46
47
            a = latency.analyse(df_data, config)
            print(a.corr.sort_values(ascending=False))
48
49
50
51
52
53
54
55
56
57
58
59
60
61
        else:
            df_data = evaluate(data_files["sender"], data_files["receiver"], config=config, kind=0)

            params = {"export": args.export}

            if command == "jitter":
                params1 = dict(params)
                params1.update({"file_name": "TraceJitter.pdf"})
                params2 = dict(params)
                params2.update({"file_name": "JitterCauses.pdf"})

                df = jitter.prep(df_data, config)
                jitter.trace_jitter(df, **params1)
                jitter.jitter_causes(df, config["durations"], **params2)
62
63
64

if __name__ == "__main__":
    main()