command_line.py 3.82 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
Stefan Reif's avatar
Stefan Reif committed
6
import xlap.analyse.diff as difference
Stefan Reif's avatar
Stefan Reif committed
7
import xlap.analyse.e2e as e2e
8

9
tasks = {
10
    "jitter": None,
11
    "latency": None,
Stefan Reif's avatar
Stefan Reif committed
12
    "difference": None,
Stefan Reif's avatar
Stefan Reif committed
13
    "e2e": None,
14
    "capture": None
15 16
}

Andreas Schmidt's avatar
Andreas Schmidt committed
17

18 19 20 21
def main():
    config = parse_config()
    data_files = config["data_files"]

22
    parser = argparse.ArgumentParser()
Andreas Schmidt's avatar
Andreas Schmidt committed
23 24
    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.")
25 26 27 28 29 30
    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
31

32 33
        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
34

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

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

40 41 42 43 44 45 46 47
            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)
Stefan Reif's avatar
Stefan Reif committed
48 49 50
        elif command == "e2e":
            khz1 = 2000000
            khz2 = 3000000
Stefan Reif's avatar
...  
Stefan Reif committed
51
            path="../publications/rtn-18/eval/20180419_energy/"
Stefan Reif's avatar
Stefan Reif committed
52 53 54
            df_data1 = evaluate(path+"sender-"+str(khz1)+".csv", path+"receiver-"+str(khz1)+".csv", config=config, kind=0)
            df_data2 = evaluate(path+"sender-"+str(khz2)+".csv", path+"receiver-"+str(khz2)+".csv", config=config, kind=0)
            e2e.analyse(df_data1, df_data2, config)
55 56
        elif command == "latency":
            df_data = evaluate(data_files["sender"], data_files["receiver"], config=config, kind=0)
57 58
            a = latency.analyse(df_data, config)
            print(a.corr.sort_values(ascending=False))
Stefan Reif's avatar
Stefan Reif committed
59
        elif command == "difference":
Stefan Reif's avatar
...  
Stefan Reif committed
60
            path="../publications/rtn-18/eval/20180420_"
Stefan Reif's avatar
Stefan Reif committed
61 62
            khz = 3000000
            df_data1 = evaluate(path+"base1/sender-"+str(khz)+".csv", path+"base1/receiver-"+str(khz)+".csv", config=config, kind=0)
Stefan Reif's avatar
Stefan Reif committed
63 64 65 66 67
            # sanity check:
            #df_data2 = evaluate("../prrt/out/s.csv", "../prrt/out/r.csv", config=config, kind=0)
            # same setup, different measurement run:
            #df_data2 = evaluate("../prrt/out/s+same.csv", "../prrt/out/r+same.csv", config=config, kind=0)
            # different setup:
Stefan Reif's avatar
Stefan Reif committed
68 69 70
            #df_data2 = evaluate("../prrt/out/s+send.csv", "../prrt/out/r+send.csv", config=config, kind=0)
            df_data2 = evaluate(path+"base2/sender-"+str(khz)+".csv", path+"base2/receiver-"+str(khz)+".csv", config=config, kind=0)
            #df_data2 = evaluate(path+"changed/sender-"+str(khz)+".csv", path+"changed/receiver-"+str(khz)+".csv", config=config, kind=0)
Stefan Reif's avatar
Stefan Reif committed
71
            difference.analyse(df_data1, df_data2, config)
72 73 74 75 76 77 78 79 80 81 82 83 84 85
        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)
86 87 88

if __name__ == "__main__":
    main()