summaryrefslogtreecommitdiffstats
path: root/scripts/qmlbenchrunner/run.py
blob: 73f426f10cbedf8a0e0fcab0b0ca3d37df40b198 (plain)
1
2
3
4
5
6
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
67
68
69
70
71
72
73
#!/usr/bin/env python3
# Copyright (C) 2021 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

import os
import sys
import subprocess
import logging
import requests
import json
import platform

HOSTNAME = "testresults.qt.io/influxdb"

def submit_output(output, branch, hardwareId):
    tree = json.loads(output)
    for key in tree:
        if key.endswith(".qml"):
            mean = 0
            standardDeviation = 0
            coefficientOfVariation = 0

            # key is foo/bar/benchmarks/auto/<important_thing_here>/stuff.qml
            # dirname will trim off the last part, leaving us
            # foo/bar/benchmarks/auto/<important_thing_here>
            benchmarkSuite = os.path.dirname(key)

            # now cut off everything before <important_thing_here>.
            cutPos = benchmarkSuite.find("/benchmarks/auto/")
            benchmarkSuite = benchmarkSuite[cutPos + len("/benchmarks/auto/"):]

            try:
                mean = tree[key]["average"]
                standardDeviation = tree[key]["standard-deviation-all-samples"]
                coefficientOfVariation = tree[key]["coefficient-of-variation"]
            except:
                # probably means that the test didn't run properly.
                # (empty object). record it anyway, so it shows up,
                # and catch the exception so that other test results
                # are recorded.
                print("Test %s was malformed (empty run?)" % key)
                pass

            basename = key.split("/")[-1]
            tags = ('branch=' + branch, 'benchmark=' + basename, 'hardwareId=' + hardwareId, 'suite=' + benchmarkSuite)
            fields = ('mean=' + str(mean),
                      'coefficientOfVariation=' + str(coefficientOfVariation),
                      )

            data = 'benchmarks,%s %s' % (','.join(tags), ','.join(fields))
            result = requests.post("https://%s/write?db=qmlbench" % HOSTNAME,
                                   auth=requests.auth.HTTPBasicAuth(os.environ["INFLUXDBUSER"], os.environ["INFLUXDBPASSWORD"]),
                                   data=data.encode('utf-8'))
            print(data)
            print(result)

def run_benchmark(filename, branch, hardwareId):
    print("Loading %s" % filename)
    if (platform.system() == 'Windows'):
        output = subprocess.check_output(["Powershell.exe", "type", filename])
    else:
        output = subprocess.check_output(["cat", filename])
    submit_output(output.decode("utf-8"), branch, hardwareId)

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("filename", help = "The .json file to post")
    parser.add_argument("branch", help = "The Qt branch tested")
    parser.add_argument("hardwareId", help = "Our unique hardware ID (e.g. linux_imx6_eskil)")
    args = parser.parse_args(sys.argv[1:])
    print("Posting results: " + args.filename)
    run_benchmark(args.filename, args.branch, args.hardwareId)