File: plot_timings.py

package info (click to toggle)
pymol 3.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 74,084 kB
  • sloc: cpp: 482,660; python: 89,328; ansic: 29,512; javascript: 6,792; sh: 84; makefile: 25
file content (95 lines) | stat: -rw-r--r-- 2,550 bytes parent folder | download
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
Create plots for timings

Will create a temporary directory and put plots in PNG format there,
together with an index.html file.

"""

from __future__ import print_function

import os, sys, tempfile, re, socket, time
import datetime
from optparse import OptionParser
from collections import defaultdict
from matplotlib import pyplot, rcParams, dates

# plot setup
rcParams['figure.figsize'] = 5.0, 2.5
rcParams['font.size'] = 9

# command line options
parser = OptionParser()
parser.add_option("-b", "--browse", action="store_true", dest="browse")
parser.add_option("-q", "--quiet", action="store_true", dest="quiet")
options = parser.parse_args()[0]

# file with timing results
tabname = os.getenv("PYMOLTESTTIMINGS", "timings.tab")

# read file
db = defaultdict(lambda: defaultdict(list))
for line in open(tabname):
    a = line.rstrip('\n').split("\t")
    timestamp = float(a[0])
    try:
        mac = a[9] + a[5]
    except:
        mac = a[1]
        mac = ':'.join(mac[i:i+2] for i in range(0, len(mac), 2))
    value = float(a[2])
    key = '%s(%s)' % (a[3], a[4])
    db[key][mac].append((timestamp, value))

# helper function for unique PNG filenames
used_png = set()
def get_unused_png(key):
    r = key = re.sub(r'[^-\w.]', '_', key)
    i = 0
    while r in used_png:
        i += 1
        r = key + '-%d' % i
    return r + '.png'

# create output dir
outdir = tempfile.mkdtemp()
htmlout = open(os.path.join(outdir, "index.html"), "w")
print("<h1>PyMOL Benchmarks,", socket.gethostname(), file=htmlout)
print(time.strftime("%D-%T"), "</h1>", file=htmlout)

# make plots
for key in sorted(db):
    data = db[key]
    pyplot.clf()
    fig, ax = pyplot.subplots(1)
    maxy = 0.0
    for mac in data:
        x, y = zip(*data[mac])
        x = list(map(datetime.datetime.fromtimestamp, x))
        maxy = max(maxy, max(y))
        ax.plot(x, y, "o-", label=mac[:290])

    fig.autofmt_xdate()
    ax.xaxis.set_major_formatter(dates.DateFormatter('%Y-%m-%d'))
    ax.yaxis.set_label_text("Seconds")
    ax.set_title(key)

    pyplot.grid(True)
    pyplot.ylim(0, maxy * 1.1)
    pyplot.legend(loc="best")
    pngname = get_unused_png(key)
    pyplot.savefig(os.path.join(outdir, pngname), dpi=70)
    print("<img src='%s'>" % (pngname), file=htmlout)

# done
if not options.quiet:
    print(outdir)

# open index.html
if options.browse:
    outhtml = os.path.join(outdir, "index.html")
    if sys.platform.startswith("darwin"):
        os.system("open " + outhtml)
    else:
        import webbrowser
        webbrowser.open(outhtml)