[importreport] Allow specifying additional run information to include in the submission (#151) Fixes #150
diff --git a/docs/importing_data.rst b/docs/importing_data.rst index 2168d80..4d9043e 100644 --- a/docs/importing_data.rst +++ b/docs/importing_data.rst
@@ -23,6 +23,16 @@ lnt importreport --machine=my-machine-name --order=1234 --testsuite=nts results.txt report.json lnt submit http://mylnt.com/db_default/submitRun report.json +Additional information can also be included in runs. This can be useful to include e.g. the +commit information associated to the version of the code being benchmarked or other information +relevant to the run like the system load, etc. This information can be provided to ``lnt importreport`` +as key-value pairs, passing ``--run-info`` as many times as necessary:: + + lnt importreport --machine=my-machine-name --order=1234 --testsuite=nts \ + --run-info commit="COMMIT INFORMATION" \ + --run-info machine_load="LOAD INFORMATION" \ + results.txt report.json + .. _json_format: LNT Report File Format
diff --git a/lnt/lnttool/import_report.py b/lnt/lnttool/import_report.py index b0a3842..4c6d3d2 100644 --- a/lnt/lnttool/import_report.py +++ b/lnt/lnttool/import_report.py
@@ -12,10 +12,15 @@ "Ex: a svn revision, or timestamp.") @click.option("--machine", required=True, help="the name of the machine to submit under") -def action_importreport(input, output, suite, order, machine): +@click.option("--run-info", multiple=True, type=str, + help="Optional additional run information to include in the submission. " + "If provided, this must be a key-value pair separated by '='. This " + "argument may be repeated multiple times to provide multiple keys " + "and values in the run information.") +def action_importreport(input, output, suite, order, machine, run_info): """Import simple data into LNT. This takes a space separated key value file and creates an LNT report file, which can be submitted to - an LNT server. Example input file: + an LNT server. Example input file: \b foo.exec 123 @@ -30,10 +35,19 @@ machine = lnt.testing.Machine(machine, report_version=2) + parsed_info = {} + for s in run_info: + if '=' not in s: + raise click.BadParameter(f"--run-info must be in 'key=value' format, got: {s}") + k, v = s.split('=', 1) # Split only on the first '=' in case there are several in the string + parsed_info[k] = v + run_info = parsed_info + run_info.update({'llvm_project_revision': order}) + ctime = os.path.getctime(input.name) mtime = os.path.getmtime(input.name) run = lnt.testing.Run(start_time=ctime, end_time=mtime, - info={'llvm_project_revision': order}, + info=run_info, report_version=2) tests = {} # name => lnt.testing.Test
diff --git a/tests/lnttool/importreport.run-info.shtest b/tests/lnttool/importreport.run-info.shtest new file mode 100644 index 0000000..eae2e37 --- /dev/null +++ b/tests/lnttool/importreport.run-info.shtest
@@ -0,0 +1,71 @@ +# +# Ensure that we can pass additional run information with `lnt importreport`. +# + +# Pass one run information. +# +# RUN: lnt importreport --testsuite nts --order 123 --machine foo --run-info commit=abc123 %S/Inputs/example_metrics.lnt %t.1.json +# RUN: filecheck --check-prefix=CHECK-1 --input-file %t.1.json %s +# CHECK-1: { +# CHECK-1-NEXT: "format_version": "2", +# CHECK-1-NEXT: "machine": { +# CHECK-1-NEXT: "name": "foo" +# CHECK-1-NEXT: }, +# CHECK-1-NEXT: "run": { +# CHECK-1-NEXT: "commit": "abc123", +# CHECK-1-NEXT: "end_time": "{{.+}}", +# CHECK-1-NEXT: "llvm_project_revision": "123", +# CHECK-1-NEXT: "start_time": "{{.+}}" +# CHECK-1-NEXT: }, +# CHECK-1-NEXT: "tests": [ +# CHECK-1-NEXT: { +# CHECK-1-NEXT: "execution_time": [ +# CHECK-1-NEXT: 10.0, +# CHECK-1-NEXT: 11.0 +# CHECK-1-NEXT: ], +# CHECK-1-NEXT: "hash": "d7", +# CHECK-1-NEXT: "name": "foo" +# CHECK-1-NEXT: }, +# CHECK-1-NEXT: { +# CHECK-1-NEXT: "execution_time": 20.0, +# CHECK-1-NEXT: "name": "bar", +# CHECK-1-NEXT: "profile": "Xz6/" +# CHECK-1-NEXT: } +# CHECK-1-NEXT: ] +# CHECK-1-NEXT: } + +# Pass multiple run informations. +# +# RUN: lnt importreport --testsuite nts --order 123 --machine foo \ +# RUN: --run-info commit=abc123 --run-info load_factor="10%" --run-info something_else="info" \ +# RUN: %S/Inputs/example_metrics.lnt %t.2.json +# RUN: filecheck --check-prefix=CHECK-2 --input-file %t.2.json %s +# CHECK-2: { +# CHECK-2-NEXT: "format_version": "2", +# CHECK-2-NEXT: "machine": { +# CHECK-2-NEXT: "name": "foo" +# CHECK-2-NEXT: }, +# CHECK-2-NEXT: "run": { +# CHECK-2-NEXT: "commit": "abc123", +# CHECK-2-NEXT: "end_time": "{{.+}}", +# CHECK-2-NEXT: "llvm_project_revision": "123", +# CHECK-2-NEXT: "load_factor": "10%", +# CHECK-2-NEXT: "something_else": "info", +# CHECK-2-NEXT: "start_time": "{{.+}}" +# CHECK-2-NEXT: }, +# CHECK-2-NEXT: "tests": [ +# CHECK-2-NEXT: { +# CHECK-2-NEXT: "execution_time": [ +# CHECK-2-NEXT: 10.0, +# CHECK-2-NEXT: 11.0 +# CHECK-2-NEXT: ], +# CHECK-2-NEXT: "hash": "d7", +# CHECK-2-NEXT: "name": "foo" +# CHECK-2-NEXT: }, +# CHECK-2-NEXT: { +# CHECK-2-NEXT: "execution_time": 20.0, +# CHECK-2-NEXT: "name": "bar", +# CHECK-2-NEXT: "profile": "Xz6/" +# CHECK-2-NEXT: } +# CHECK-2-NEXT: ] +# CHECK-2-NEXT: }