Show More
@@ -1,263 +1,259 | |||||
1 | # perf.py - performance test routines |
|
1 | # perf.py - performance test routines | |
2 | '''helper extension to measure performance''' |
|
2 | '''helper extension to measure performance''' | |
3 |
|
3 | |||
4 | from mercurial import cmdutil, scmutil, util, match, commands |
|
4 | from mercurial import cmdutil, scmutil, util, match, commands | |
5 | import time, os, sys |
|
5 | import time, os, sys | |
6 |
|
6 | |||
7 | def timer(func, title=None): |
|
7 | def timer(func, title=None): | |
8 | results = [] |
|
8 | results = [] | |
9 | begin = time.time() |
|
9 | begin = time.time() | |
10 | count = 0 |
|
10 | count = 0 | |
11 | while True: |
|
11 | while True: | |
12 | ostart = os.times() |
|
12 | ostart = os.times() | |
13 | cstart = time.time() |
|
13 | cstart = time.time() | |
14 | r = func() |
|
14 | r = func() | |
15 | cstop = time.time() |
|
15 | cstop = time.time() | |
16 | ostop = os.times() |
|
16 | ostop = os.times() | |
17 | count += 1 |
|
17 | count += 1 | |
18 | a, b = ostart, ostop |
|
18 | a, b = ostart, ostop | |
19 | results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) |
|
19 | results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) | |
20 | if cstop - begin > 3 and count >= 100: |
|
20 | if cstop - begin > 3 and count >= 100: | |
21 | break |
|
21 | break | |
22 | if cstop - begin > 10 and count >= 3: |
|
22 | if cstop - begin > 10 and count >= 3: | |
23 | break |
|
23 | break | |
24 | if title: |
|
24 | if title: | |
25 | sys.stderr.write("! %s\n" % title) |
|
25 | sys.stderr.write("! %s\n" % title) | |
26 | if r: |
|
26 | if r: | |
27 | sys.stderr.write("! result: %s\n" % r) |
|
27 | sys.stderr.write("! result: %s\n" % r) | |
28 | m = min(results) |
|
28 | m = min(results) | |
29 | sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n" |
|
29 | sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n" | |
30 | % (m[0], m[1] + m[2], m[1], m[2], count)) |
|
30 | % (m[0], m[1] + m[2], m[1], m[2], count)) | |
31 |
|
31 | |||
32 | def perfwalk(ui, repo, *pats): |
|
32 | def perfwalk(ui, repo, *pats): | |
33 | try: |
|
33 | try: | |
34 | m = scmutil.match(repo[None], pats, {}) |
|
34 | m = scmutil.match(repo[None], pats, {}) | |
35 | timer(lambda: len(list(repo.dirstate.walk(m, [], True, False)))) |
|
35 | timer(lambda: len(list(repo.dirstate.walk(m, [], True, False)))) | |
36 | except Exception: |
|
36 | except Exception: | |
37 | try: |
|
37 | try: | |
38 | m = scmutil.match(repo[None], pats, {}) |
|
38 | m = scmutil.match(repo[None], pats, {}) | |
39 | timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)])) |
|
39 | timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)])) | |
40 | except Exception: |
|
40 | except Exception: | |
41 | timer(lambda: len(list(cmdutil.walk(repo, pats, {})))) |
|
41 | timer(lambda: len(list(cmdutil.walk(repo, pats, {})))) | |
42 |
|
42 | |||
43 | def perfstatus(ui, repo, *pats): |
|
43 | def perfstatus(ui, repo, *pats): | |
44 | #m = match.always(repo.root, repo.getcwd()) |
|
44 | #m = match.always(repo.root, repo.getcwd()) | |
45 | #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False, |
|
45 | #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False, | |
46 | # False)))) |
|
46 | # False)))) | |
47 | timer(lambda: sum(map(len, repo.status()))) |
|
47 | timer(lambda: sum(map(len, repo.status()))) | |
48 |
|
48 | |||
49 | def clearcaches(cl): |
|
49 | def clearcaches(cl): | |
50 | # behave somewhat consistently across internal API changes |
|
50 | # behave somewhat consistently across internal API changes | |
51 | if util.safehasattr(cl, 'clearcaches'): |
|
51 | if util.safehasattr(cl, 'clearcaches'): | |
52 | cl.clearcaches() |
|
52 | cl.clearcaches() | |
53 | elif util.safehasattr(cl, '_nodecache'): |
|
53 | elif util.safehasattr(cl, '_nodecache'): | |
54 | from mercurial.node import nullid, nullrev |
|
54 | from mercurial.node import nullid, nullrev | |
55 | cl._nodecache = {nullid: nullrev} |
|
55 | cl._nodecache = {nullid: nullrev} | |
56 | cl._nodepos = None |
|
56 | cl._nodepos = None | |
57 |
|
57 | |||
58 | def perfheads(ui, repo): |
|
58 | def perfheads(ui, repo): | |
59 | cl = repo.changelog |
|
59 | cl = repo.changelog | |
60 | def d(): |
|
60 | def d(): | |
61 | len(cl.headrevs()) |
|
61 | len(cl.headrevs()) | |
62 | clearcaches(cl) |
|
62 | clearcaches(cl) | |
63 | timer(d) |
|
63 | timer(d) | |
64 |
|
64 | |||
65 | def perftags(ui, repo): |
|
65 | def perftags(ui, repo): | |
66 | import mercurial.changelog, mercurial.manifest |
|
66 | import mercurial.changelog, mercurial.manifest | |
67 | def t(): |
|
67 | def t(): | |
68 | repo.changelog = mercurial.changelog.changelog(repo.sopener) |
|
68 | repo.changelog = mercurial.changelog.changelog(repo.sopener) | |
69 | repo.manifest = mercurial.manifest.manifest(repo.sopener) |
|
69 | repo.manifest = mercurial.manifest.manifest(repo.sopener) | |
70 | repo._tags = None |
|
70 | repo._tags = None | |
71 | return len(repo.tags()) |
|
71 | return len(repo.tags()) | |
72 | timer(t) |
|
72 | timer(t) | |
73 |
|
73 | |||
74 | def perfancestors(ui, repo): |
|
74 | def perfancestors(ui, repo): | |
75 | heads = repo.changelog.headrevs() |
|
75 | heads = repo.changelog.headrevs() | |
76 | def d(): |
|
76 | def d(): | |
77 | for a in repo.changelog.ancestors(heads): |
|
77 | for a in repo.changelog.ancestors(heads): | |
78 | pass |
|
78 | pass | |
79 | timer(d) |
|
79 | timer(d) | |
80 |
|
80 | |||
81 | def perfdirstate(ui, repo): |
|
81 | def perfdirstate(ui, repo): | |
82 | "a" in repo.dirstate |
|
82 | "a" in repo.dirstate | |
83 | def d(): |
|
83 | def d(): | |
84 | repo.dirstate.invalidate() |
|
84 | repo.dirstate.invalidate() | |
85 | "a" in repo.dirstate |
|
85 | "a" in repo.dirstate | |
86 | timer(d) |
|
86 | timer(d) | |
87 |
|
87 | |||
88 | def perfdirstatedirs(ui, repo): |
|
88 | def perfdirstatedirs(ui, repo): | |
89 | "a" in repo.dirstate |
|
89 | "a" in repo.dirstate | |
90 | def d(): |
|
90 | def d(): | |
91 | "a" in repo.dirstate._dirs |
|
91 | "a" in repo.dirstate._dirs | |
92 | del repo.dirstate._dirs |
|
92 | del repo.dirstate._dirs | |
93 | timer(d) |
|
93 | timer(d) | |
94 |
|
94 | |||
95 | def perfdirstatewrite(ui, repo): |
|
95 | def perfdirstatewrite(ui, repo): | |
96 | ds = repo.dirstate |
|
96 | ds = repo.dirstate | |
97 | "a" in ds |
|
97 | "a" in ds | |
98 | def d(): |
|
98 | def d(): | |
99 | ds._dirty = True |
|
99 | ds._dirty = True | |
100 | ds.write() |
|
100 | ds.write() | |
101 | timer(d) |
|
101 | timer(d) | |
102 |
|
102 | |||
103 | def perfmanifest(ui, repo): |
|
103 | def perfmanifest(ui, repo): | |
104 | def d(): |
|
104 | def d(): | |
105 | t = repo.manifest.tip() |
|
105 | t = repo.manifest.tip() | |
106 | m = repo.manifest.read(t) |
|
106 | m = repo.manifest.read(t) | |
107 | repo.manifest.mapcache = None |
|
107 | repo.manifest.mapcache = None | |
108 | repo.manifest._cache = None |
|
108 | repo.manifest._cache = None | |
109 | timer(d) |
|
109 | timer(d) | |
110 |
|
110 | |||
111 | def perfchangeset(ui, repo, rev): |
|
111 | def perfchangeset(ui, repo, rev): | |
112 | n = repo[rev].node() |
|
112 | n = repo[rev].node() | |
113 | def d(): |
|
113 | def d(): | |
114 | c = repo.changelog.read(n) |
|
114 | c = repo.changelog.read(n) | |
115 | #repo.changelog._cache = None |
|
115 | #repo.changelog._cache = None | |
116 | timer(d) |
|
116 | timer(d) | |
117 |
|
117 | |||
118 | def perfindex(ui, repo): |
|
118 | def perfindex(ui, repo): | |
119 | import mercurial.revlog |
|
119 | import mercurial.revlog | |
120 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg |
|
120 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg | |
121 | n = repo["tip"].node() |
|
121 | n = repo["tip"].node() | |
122 | def d(): |
|
122 | def d(): | |
123 | cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i") |
|
123 | cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i") | |
124 | cl.rev(n) |
|
124 | cl.rev(n) | |
125 | timer(d) |
|
125 | timer(d) | |
126 |
|
126 | |||
127 | def perfstartup(ui, repo): |
|
127 | def perfstartup(ui, repo): | |
128 | cmd = sys.argv[0] |
|
128 | cmd = sys.argv[0] | |
129 | def d(): |
|
129 | def d(): | |
130 | os.system("HGRCPATH= %s version -q > /dev/null" % cmd) |
|
130 | os.system("HGRCPATH= %s version -q > /dev/null" % cmd) | |
131 | timer(d) |
|
131 | timer(d) | |
132 |
|
132 | |||
133 | def perfparents(ui, repo): |
|
133 | def perfparents(ui, repo): | |
134 | nl = [repo.changelog.node(i) for i in xrange(1000)] |
|
134 | nl = [repo.changelog.node(i) for i in xrange(1000)] | |
135 | def d(): |
|
135 | def d(): | |
136 | for n in nl: |
|
136 | for n in nl: | |
137 | repo.changelog.parents(n) |
|
137 | repo.changelog.parents(n) | |
138 | timer(d) |
|
138 | timer(d) | |
139 |
|
139 | |||
140 | def perflookup(ui, repo, rev): |
|
140 | def perflookup(ui, repo, rev): | |
141 | timer(lambda: len(repo.lookup(rev))) |
|
141 | timer(lambda: len(repo.lookup(rev))) | |
142 |
|
142 | |||
143 | def perfrevrange(ui, repo, *specs): |
|
143 | def perfrevrange(ui, repo, *specs): | |
144 | revrange = scmutil.revrange |
|
144 | revrange = scmutil.revrange | |
145 | timer(lambda: len(revrange(repo, specs))) |
|
145 | timer(lambda: len(revrange(repo, specs))) | |
146 |
|
146 | |||
147 | def perfnodelookup(ui, repo, rev): |
|
147 | def perfnodelookup(ui, repo, rev): | |
148 | import mercurial.revlog |
|
148 | import mercurial.revlog | |
149 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg |
|
149 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg | |
150 | n = repo[rev].node() |
|
150 | n = repo[rev].node() | |
151 | def d(): |
|
151 | def d(): | |
152 | cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i") |
|
152 | cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i") | |
153 | cl.rev(n) |
|
153 | cl.rev(n) | |
154 | timer(d) |
|
154 | timer(d) | |
155 |
|
155 | |||
156 | def perfnodelookup(ui, repo, rev): |
|
156 | def perfnodelookup(ui, repo, rev): | |
157 | import mercurial.revlog |
|
157 | import mercurial.revlog | |
158 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg |
|
158 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg | |
159 | n = repo[rev].node() |
|
159 | n = repo[rev].node() | |
160 | cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i") |
|
160 | cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i") | |
161 | def d(): |
|
161 | def d(): | |
162 | cl.rev(n) |
|
162 | cl.rev(n) | |
163 | clearcaches(cl) |
|
163 | clearcaches(cl) | |
164 | timer(d) |
|
164 | timer(d) | |
165 |
|
165 | |||
166 | def perflog(ui, repo, **opts): |
|
166 | def perflog(ui, repo, **opts): | |
167 | ui.pushbuffer() |
|
167 | ui.pushbuffer() | |
168 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', |
|
168 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', | |
169 | copies=opts.get('rename'))) |
|
169 | copies=opts.get('rename'))) | |
170 | ui.popbuffer() |
|
170 | ui.popbuffer() | |
171 |
|
171 | |||
172 | def perftemplating(ui, repo): |
|
172 | def perftemplating(ui, repo): | |
173 | ui.pushbuffer() |
|
173 | ui.pushbuffer() | |
174 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', |
|
174 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', | |
175 | template='{date|shortdate} [{rev}:{node|short}]' |
|
175 | template='{date|shortdate} [{rev}:{node|short}]' | |
176 | ' {author|person}: {desc|firstline}\n')) |
|
176 | ' {author|person}: {desc|firstline}\n')) | |
177 | ui.popbuffer() |
|
177 | ui.popbuffer() | |
178 |
|
178 | |||
179 | def perfcca(ui, repo): |
|
179 | def perfcca(ui, repo): | |
180 | timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate)) |
|
180 | timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate)) | |
181 |
|
181 | |||
182 | def perffncacheload(ui, repo): |
|
182 | def perffncacheload(ui, repo): | |
183 | from mercurial import scmutil, store |
|
183 | s = repo.store | |
184 | s = store.store(set(['store','fncache']), repo.path, scmutil.opener) |
|
|||
185 | def d(): |
|
184 | def d(): | |
186 | s.fncache._load() |
|
185 | s.fncache._load() | |
187 | timer(d) |
|
186 | timer(d) | |
188 |
|
187 | |||
189 | def perffncachewrite(ui, repo): |
|
188 | def perffncachewrite(ui, repo): | |
190 | from mercurial import scmutil, store |
|
189 | s = repo.store | |
191 | s = store.store(set(['store','fncache']), repo.path, scmutil.opener) |
|
|||
192 | s.fncache._load() |
|
190 | s.fncache._load() | |
193 | def d(): |
|
191 | def d(): | |
194 | s.fncache._dirty = True |
|
192 | s.fncache._dirty = True | |
195 | s.fncache.write() |
|
193 | s.fncache.write() | |
196 | timer(d) |
|
194 | timer(d) | |
197 |
|
195 | |||
198 | def perffncacheencode(ui, repo): |
|
196 | def perffncacheencode(ui, repo): | |
199 | from mercurial import store |
|
197 | s = repo.store | |
200 | s = store.store(set(['store','fncache','dotencode']), |
|
|||
201 | repo.path, scmutil.opener) |
|
|||
202 | s.fncache._load() |
|
198 | s.fncache._load() | |
203 | def d(): |
|
199 | def d(): | |
204 | for p in s.fncache.entries: |
|
200 | for p in s.fncache.entries: | |
205 | s.encode(p) |
|
201 | s.encode(p) | |
206 | timer(d) |
|
202 | timer(d) | |
207 |
|
203 | |||
208 | def perfdiffwd(ui, repo): |
|
204 | def perfdiffwd(ui, repo): | |
209 | """Profile diff of working directory changes""" |
|
205 | """Profile diff of working directory changes""" | |
210 | options = { |
|
206 | options = { | |
211 | 'w': 'ignore_all_space', |
|
207 | 'w': 'ignore_all_space', | |
212 | 'b': 'ignore_space_change', |
|
208 | 'b': 'ignore_space_change', | |
213 | 'B': 'ignore_blank_lines', |
|
209 | 'B': 'ignore_blank_lines', | |
214 | } |
|
210 | } | |
215 |
|
211 | |||
216 | for diffopt in ('', 'w', 'b', 'B', 'wB'): |
|
212 | for diffopt in ('', 'w', 'b', 'B', 'wB'): | |
217 | opts = dict((options[c], '1') for c in diffopt) |
|
213 | opts = dict((options[c], '1') for c in diffopt) | |
218 | def d(): |
|
214 | def d(): | |
219 | ui.pushbuffer() |
|
215 | ui.pushbuffer() | |
220 | commands.diff(ui, repo, **opts) |
|
216 | commands.diff(ui, repo, **opts) | |
221 | ui.popbuffer() |
|
217 | ui.popbuffer() | |
222 | title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none') |
|
218 | title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none') | |
223 | timer(d, title) |
|
219 | timer(d, title) | |
224 |
|
220 | |||
225 | def perfrevlog(ui, repo, file_, **opts): |
|
221 | def perfrevlog(ui, repo, file_, **opts): | |
226 | from mercurial import revlog |
|
222 | from mercurial import revlog | |
227 | dist = opts['dist'] |
|
223 | dist = opts['dist'] | |
228 | def d(): |
|
224 | def d(): | |
229 | r = revlog.revlog(lambda fn: open(fn, 'rb'), file_) |
|
225 | r = revlog.revlog(lambda fn: open(fn, 'rb'), file_) | |
230 | for x in xrange(0, len(r), dist): |
|
226 | for x in xrange(0, len(r), dist): | |
231 | r.revision(r.node(x)) |
|
227 | r.revision(r.node(x)) | |
232 |
|
228 | |||
233 | timer(d) |
|
229 | timer(d) | |
234 |
|
230 | |||
235 | cmdtable = { |
|
231 | cmdtable = { | |
236 | 'perfcca': (perfcca, []), |
|
232 | 'perfcca': (perfcca, []), | |
237 | 'perffncacheload': (perffncacheload, []), |
|
233 | 'perffncacheload': (perffncacheload, []), | |
238 | 'perffncachewrite': (perffncachewrite, []), |
|
234 | 'perffncachewrite': (perffncachewrite, []), | |
239 | 'perffncacheencode': (perffncacheencode, []), |
|
235 | 'perffncacheencode': (perffncacheencode, []), | |
240 | 'perflookup': (perflookup, []), |
|
236 | 'perflookup': (perflookup, []), | |
241 | 'perfrevrange': (perfrevrange, []), |
|
237 | 'perfrevrange': (perfrevrange, []), | |
242 | 'perfnodelookup': (perfnodelookup, []), |
|
238 | 'perfnodelookup': (perfnodelookup, []), | |
243 | 'perfparents': (perfparents, []), |
|
239 | 'perfparents': (perfparents, []), | |
244 | 'perfstartup': (perfstartup, []), |
|
240 | 'perfstartup': (perfstartup, []), | |
245 | 'perfstatus': (perfstatus, []), |
|
241 | 'perfstatus': (perfstatus, []), | |
246 | 'perfwalk': (perfwalk, []), |
|
242 | 'perfwalk': (perfwalk, []), | |
247 | 'perfmanifest': (perfmanifest, []), |
|
243 | 'perfmanifest': (perfmanifest, []), | |
248 | 'perfchangeset': (perfchangeset, []), |
|
244 | 'perfchangeset': (perfchangeset, []), | |
249 | 'perfindex': (perfindex, []), |
|
245 | 'perfindex': (perfindex, []), | |
250 | 'perfheads': (perfheads, []), |
|
246 | 'perfheads': (perfheads, []), | |
251 | 'perftags': (perftags, []), |
|
247 | 'perftags': (perftags, []), | |
252 | 'perfancestors': (perfancestors, []), |
|
248 | 'perfancestors': (perfancestors, []), | |
253 | 'perfdirstate': (perfdirstate, []), |
|
249 | 'perfdirstate': (perfdirstate, []), | |
254 | 'perfdirstatedirs': (perfdirstate, []), |
|
250 | 'perfdirstatedirs': (perfdirstate, []), | |
255 | 'perfdirstatewrite': (perfdirstatewrite, []), |
|
251 | 'perfdirstatewrite': (perfdirstatewrite, []), | |
256 | 'perflog': (perflog, |
|
252 | 'perflog': (perflog, | |
257 | [('', 'rename', False, 'ask log to follow renames')]), |
|
253 | [('', 'rename', False, 'ask log to follow renames')]), | |
258 | 'perftemplating': (perftemplating, []), |
|
254 | 'perftemplating': (perftemplating, []), | |
259 | 'perfdiffwd': (perfdiffwd, []), |
|
255 | 'perfdiffwd': (perfdiffwd, []), | |
260 | 'perfrevlog': (perfrevlog, |
|
256 | 'perfrevlog': (perfrevlog, | |
261 | [('d', 'dist', 100, 'distance between the revisions')], |
|
257 | [('d', 'dist', 100, 'distance between the revisions')], | |
262 | "[INDEXFILE]"), |
|
258 | "[INDEXFILE]"), | |
263 | } |
|
259 | } |
General Comments 0
You need to be logged in to leave comments.
Login now