Mercurial > hg
annotate contrib/perf-utils/perf-revlog-write-plot.py @ 41730:19d8d6856338
tests: glob over quoting differences in test-blackbox.t for Windows
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 16 Feb 2019 21:49:55 -0500 |
parents | c3e5ce3a9483 |
children | 2372284d9457 |
rev | line source |
---|---|
40958
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
2 # |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
3 # Copyright 2018 Paul Morelle <Paul.Morelle@octobus.net> |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
4 # |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
7 # |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
8 # This script use the output of `hg perfrevlogwrite -T json --details` to draw |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
9 # various plot related to write performance in a revlog |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
10 # |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
11 # usage: perf-revlog-write-plot.py details.json |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
12 from __future__ import absolute_import, print_function |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
13 import json |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
14 import re |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
15 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
16 import numpy as np |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
17 import scipy.signal |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
18 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
19 from matplotlib import ( |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
20 pyplot as plt, |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
21 ticker as mticker, |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
22 ) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
23 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
24 |
41190
c3e5ce3a9483
contrib: update window title when possible in perf-revlog-write-plot.py
Boris Feld <boris.feld@octobus.net>
parents:
40958
diff
changeset
|
25 def plot(data, title=None): |
40958
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
26 items = {} |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
27 re_title = re.compile(r'^revisions #\d+ of \d+, rev (\d+)$') |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
28 for item in data: |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
29 m = re_title.match(item['title']) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
30 if m is None: |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
31 continue |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
32 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
33 rev = int(m.group(1)) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
34 items[rev] = item |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
35 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
36 min_rev = min(items.keys()) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
37 max_rev = max(items.keys()) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
38 ary = np.empty((2, max_rev - min_rev + 1)) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
39 for rev, item in items.items(): |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
40 ary[0][rev - min_rev] = rev |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
41 ary[1][rev - min_rev] = item['wall'] |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
42 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
43 fig = plt.figure() |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
44 comb_plt = fig.add_subplot(211) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
45 other_plt = fig.add_subplot(212) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
46 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
47 comb_plt.plot(ary[0], |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
48 np.cumsum(ary[1]), |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
49 color='red', |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
50 linewidth=1, |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
51 label='comb') |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
52 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
53 plots = [] |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
54 p = other_plt.plot(ary[0], |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
55 ary[1], |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
56 color='red', |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
57 linewidth=1, |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
58 label='wall') |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
59 plots.append(p) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
60 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
61 colors = { |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
62 10: ('green', 'xkcd:grass green'), |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
63 100: ('blue', 'xkcd:bright blue'), |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
64 1000: ('purple', 'xkcd:dark pink'), |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
65 } |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
66 for n, color in colors.items(): |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
67 avg_n = np.convolve(ary[1], np.full(n, 1. / n), 'valid') |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
68 p = other_plt.plot(ary[0][n - 1:], |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
69 avg_n, |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
70 color=color[0], |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
71 linewidth=1, |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
72 label='avg time last %d' % n) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
73 plots.append(p) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
74 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
75 med_n = scipy.signal.medfilt(ary[1], n + 1) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
76 p = other_plt.plot(ary[0], |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
77 med_n, |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
78 color=color[1], |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
79 linewidth=1, |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
80 label='median time last %d' % n) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
81 plots.append(p) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
82 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
83 formatter = mticker.ScalarFormatter() |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
84 formatter.set_scientific(False) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
85 formatter.set_useOffset(False) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
86 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
87 comb_plt.grid() |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
88 comb_plt.xaxis.set_major_formatter(formatter) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
89 comb_plt.legend() |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
90 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
91 other_plt.grid() |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
92 other_plt.xaxis.set_major_formatter(formatter) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
93 leg = other_plt.legend() |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
94 leg2plot = {} |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
95 for legline, plot in zip(leg.get_lines(), plots): |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
96 legline.set_picker(5) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
97 leg2plot[legline] = plot |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
98 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
99 def onpick(event): |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
100 legline = event.artist |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
101 plot = leg2plot[legline] |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
102 visible = not plot[0].get_visible() |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
103 for l in plot: |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
104 l.set_visible(visible) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
105 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
106 if visible: |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
107 legline.set_alpha(1.0) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
108 else: |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
109 legline.set_alpha(0.2) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
110 fig.canvas.draw() |
41190
c3e5ce3a9483
contrib: update window title when possible in perf-revlog-write-plot.py
Boris Feld <boris.feld@octobus.net>
parents:
40958
diff
changeset
|
111 if title is not None: |
c3e5ce3a9483
contrib: update window title when possible in perf-revlog-write-plot.py
Boris Feld <boris.feld@octobus.net>
parents:
40958
diff
changeset
|
112 fig.canvas.set_window_title(title) |
40958
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
113 fig.canvas.mpl_connect('pick_event', onpick) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
114 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
115 plt.show() |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
116 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
117 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
118 if __name__ == '__main__': |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
119 import sys |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
120 |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
121 if len(sys.argv) > 1: |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
122 print('reading from %r' % sys.argv[1]) |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
123 with open(sys.argv[1], 'r') as fp: |
41190
c3e5ce3a9483
contrib: update window title when possible in perf-revlog-write-plot.py
Boris Feld <boris.feld@octobus.net>
parents:
40958
diff
changeset
|
124 plot(json.load(fp), title=sys.argv[1]) |
40958
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
125 else: |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
126 print('reading from stdin') |
abd7b75e80bc
contrib: provide a small script that draw performance plot
Paul Morelle <paul.morelle@octobus.net>
parents:
diff
changeset
|
127 plot(json.load(sys.stdin)) |