xref: /llvm-project/mlir/utils/mbr/mlir-mbr.in (revision fa90c9d5e7a310ea87b7032c39c0ca657c794abc)
1#!@Python3_EXECUTABLE@
2# -*- coding: utf-8 -*-
3
4import argparse
5import datetime
6import json
7import os
8import sys
9
10from urllib import error as urlerror
11from urllib import parse as urlparse
12from urllib import request
13
14
15mlir_source_root = "@MLIR_SOURCE_DIR@"
16sys.path.insert(0, os.path.join(mlir_source_root, "utils", "mbr", "mbr"))
17
18from main import main
19
20
21if __name__ == "__main__":
22    parser = argparse.ArgumentParser()
23    parser.add_argument(
24        "--machine",
25        required=True,
26        help="A platform identifier on which the "
27             "benchmarks are run. For example"
28             " <hardware>-<arch>-<optimization level>-<branch-name>"
29    )
30    parser.add_argument(
31        "--revision",
32        required=True,
33        help="The key used to identify different runs. "
34             "Could be anything as long as it"
35             " can be sorted by python's sort function"
36    )
37    parser.add_argument(
38        "--url",
39        help="The lnt server url to send the results to",
40        default="http://localhost:8000/db_default/v4/nts/submitRun"
41    )
42    parser.add_argument(
43        "--result-stdout",
44        help="Print benchmarking results to stdout instead"
45             " of sending it to lnt",
46        default=False,
47        action=argparse.BooleanOptionalAction
48    )
49    parser.add_argument(
50        "top_level_path",
51        help="The top level path from which to search for benchmarks",
52        default=os.getcwd(),
53    )
54    parser.add_argument(
55        "--stop_on_error",
56        help="Should we stop the benchmark run on errors? Defaults to false",
57        default=False,
58    )
59    args = parser.parse_args()
60
61    complete_benchmark_start_time = datetime.datetime.utcnow().isoformat()
62    benchmark_function_dicts = main(args.top_level_path, args.stop_on_error)
63    complete_benchmark_end_time = datetime.datetime.utcnow().isoformat()
64    lnt_dict = {
65        "format_version": "2",
66        "machine": {"name": args.machine},
67        "run": {
68            "end_time": complete_benchmark_start_time,
69            "start_time": complete_benchmark_end_time,
70            "llvm_project_revision": args.revision
71        },
72        "tests": benchmark_function_dicts,
73        "name": "MLIR benchmark suite"
74    }
75    lnt_json = json.dumps(lnt_dict, indent=4)
76    if args.result_stdout is True:
77        print(lnt_json)
78    else:
79        request_data = urlparse.urlencode(
80            {"input_data": lnt_json}
81        ).encode("ascii")
82        req = request.Request(args.url, request_data)
83        try:
84            resp = request.urlopen(req)
85        except urlerror.HTTPError as e:
86            print(e)
87