File: commit-impact.py

package info (click to toggle)
haskell-futhark 0.25.32-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 18,236 kB
  • sloc: haskell: 100,484; ansic: 12,100; python: 3,440; yacc: 785; sh: 561; javascript: 558; lisp: 399; makefile: 277
file content (76 lines) | stat: -rwxr-xr-x 1,977 bytes parent folder | download | duplicates (2)
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
74
75
76
#!/usr/bin/env python3
#
# See the impact of a Futhark commit compared to the previous one we
# have benchmarking for.

import sys
import subprocess
from urllib.request import urlopen
from urllib.error import HTTPError
import json
import tempfile
import os
import gzip


def url_for(backend, system, commit):
    return (
        "https://futhark-lang.org/benchmark-results/futhark-"
        "{}-{}-{}.json.gz"
    ).format(backend, system, commit)


def results_for_commit(backend, system, commit):
    try:
        url = url_for(backend, system, commit)
        print("Fetching {}...".format(url))
        return json.loads(gzip.decompress(urlopen(url).read()))
    except HTTPError:
        return None


def first_commit_with_results(backend, system, commits):
    for commit in commits:
        res = results_for_commit(backend, system, commit)
        if res:
            return commit, res


def find_commits(start):
    return (
        subprocess.check_output(["git", "rev-list", start])
        .decode("utf-8")
        .splitlines()
    )


if __name__ == "__main__":
    backend, system, commit = sys.argv[1:4]

    now = results_for_commit(backend, system, commit)

    if not now:
        print("No results found")
        sys.exit(1)

    if len(sys.argv) == 5:
        commits = find_commits(sys.argv[4])
    else:
        commits = find_commits(commit)[1:]

    then_commit, then = first_commit_with_results(backend, system, commits[1:])

    print("Comparing {}".format(commit))
    print("     with {}".format(then_commit))

    with tempfile.NamedTemporaryFile(prefix=commit, mode="w") as now_file:
        with tempfile.NamedTemporaryFile(
            prefix=then_commit, mode="w"
        ) as then_file:
            json.dump(now, now_file)
            json.dump(then, then_file)
            now_file.flush()
            then_file.flush()
            os.system(
                "futhark benchcmp {} {}".format(then_file.name, now_file.name)
            )