Show More
@@ -1,259 +1,261 b'' | |||||
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, *p |
|
43 | def perfstatus(ui, repo, **opts): | |
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(**opts)))) | |
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 | s = repo.store |
|
183 | s = repo.store | |
184 | def d(): |
|
184 | def d(): | |
185 | s.fncache._load() |
|
185 | s.fncache._load() | |
186 | timer(d) |
|
186 | timer(d) | |
187 |
|
187 | |||
188 | def perffncachewrite(ui, repo): |
|
188 | def perffncachewrite(ui, repo): | |
189 | s = repo.store |
|
189 | s = repo.store | |
190 | s.fncache._load() |
|
190 | s.fncache._load() | |
191 | def d(): |
|
191 | def d(): | |
192 | s.fncache._dirty = True |
|
192 | s.fncache._dirty = True | |
193 | s.fncache.write() |
|
193 | s.fncache.write() | |
194 | timer(d) |
|
194 | timer(d) | |
195 |
|
195 | |||
196 | def perffncacheencode(ui, repo): |
|
196 | def perffncacheencode(ui, repo): | |
197 | s = repo.store |
|
197 | s = repo.store | |
198 | s.fncache._load() |
|
198 | s.fncache._load() | |
199 | def d(): |
|
199 | def d(): | |
200 | for p in s.fncache.entries: |
|
200 | for p in s.fncache.entries: | |
201 | s.encode(p) |
|
201 | s.encode(p) | |
202 | timer(d) |
|
202 | timer(d) | |
203 |
|
203 | |||
204 | def perfdiffwd(ui, repo): |
|
204 | def perfdiffwd(ui, repo): | |
205 | """Profile diff of working directory changes""" |
|
205 | """Profile diff of working directory changes""" | |
206 | options = { |
|
206 | options = { | |
207 | 'w': 'ignore_all_space', |
|
207 | 'w': 'ignore_all_space', | |
208 | 'b': 'ignore_space_change', |
|
208 | 'b': 'ignore_space_change', | |
209 | 'B': 'ignore_blank_lines', |
|
209 | 'B': 'ignore_blank_lines', | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | for diffopt in ('', 'w', 'b', 'B', 'wB'): |
|
212 | for diffopt in ('', 'w', 'b', 'B', 'wB'): | |
213 | opts = dict((options[c], '1') for c in diffopt) |
|
213 | opts = dict((options[c], '1') for c in diffopt) | |
214 | def d(): |
|
214 | def d(): | |
215 | ui.pushbuffer() |
|
215 | ui.pushbuffer() | |
216 | commands.diff(ui, repo, **opts) |
|
216 | commands.diff(ui, repo, **opts) | |
217 | ui.popbuffer() |
|
217 | ui.popbuffer() | |
218 | title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none') |
|
218 | title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none') | |
219 | timer(d, title) |
|
219 | timer(d, title) | |
220 |
|
220 | |||
221 | def perfrevlog(ui, repo, file_, **opts): |
|
221 | def perfrevlog(ui, repo, file_, **opts): | |
222 | from mercurial import revlog |
|
222 | from mercurial import revlog | |
223 | dist = opts['dist'] |
|
223 | dist = opts['dist'] | |
224 | def d(): |
|
224 | def d(): | |
225 | r = revlog.revlog(lambda fn: open(fn, 'rb'), file_) |
|
225 | r = revlog.revlog(lambda fn: open(fn, 'rb'), file_) | |
226 | for x in xrange(0, len(r), dist): |
|
226 | for x in xrange(0, len(r), dist): | |
227 | r.revision(r.node(x)) |
|
227 | r.revision(r.node(x)) | |
228 |
|
228 | |||
229 | timer(d) |
|
229 | timer(d) | |
230 |
|
230 | |||
231 | cmdtable = { |
|
231 | cmdtable = { | |
232 | 'perfcca': (perfcca, []), |
|
232 | 'perfcca': (perfcca, []), | |
233 | 'perffncacheload': (perffncacheload, []), |
|
233 | 'perffncacheload': (perffncacheload, []), | |
234 | 'perffncachewrite': (perffncachewrite, []), |
|
234 | 'perffncachewrite': (perffncachewrite, []), | |
235 | 'perffncacheencode': (perffncacheencode, []), |
|
235 | 'perffncacheencode': (perffncacheencode, []), | |
236 | 'perflookup': (perflookup, []), |
|
236 | 'perflookup': (perflookup, []), | |
237 | 'perfrevrange': (perfrevrange, []), |
|
237 | 'perfrevrange': (perfrevrange, []), | |
238 | 'perfnodelookup': (perfnodelookup, []), |
|
238 | 'perfnodelookup': (perfnodelookup, []), | |
239 | 'perfparents': (perfparents, []), |
|
239 | 'perfparents': (perfparents, []), | |
240 | 'perfstartup': (perfstartup, []), |
|
240 | 'perfstartup': (perfstartup, []), | |
241 |
'perfstatus': (perfstatus, |
|
241 | 'perfstatus': (perfstatus, | |
|
242 | [('u', 'unknown', False, | |||
|
243 | 'ask status to look for unknown files')]), | |||
242 | 'perfwalk': (perfwalk, []), |
|
244 | 'perfwalk': (perfwalk, []), | |
243 | 'perfmanifest': (perfmanifest, []), |
|
245 | 'perfmanifest': (perfmanifest, []), | |
244 | 'perfchangeset': (perfchangeset, []), |
|
246 | 'perfchangeset': (perfchangeset, []), | |
245 | 'perfindex': (perfindex, []), |
|
247 | 'perfindex': (perfindex, []), | |
246 | 'perfheads': (perfheads, []), |
|
248 | 'perfheads': (perfheads, []), | |
247 | 'perftags': (perftags, []), |
|
249 | 'perftags': (perftags, []), | |
248 | 'perfancestors': (perfancestors, []), |
|
250 | 'perfancestors': (perfancestors, []), | |
249 | 'perfdirstate': (perfdirstate, []), |
|
251 | 'perfdirstate': (perfdirstate, []), | |
250 | 'perfdirstatedirs': (perfdirstate, []), |
|
252 | 'perfdirstatedirs': (perfdirstate, []), | |
251 | 'perfdirstatewrite': (perfdirstatewrite, []), |
|
253 | 'perfdirstatewrite': (perfdirstatewrite, []), | |
252 | 'perflog': (perflog, |
|
254 | 'perflog': (perflog, | |
253 | [('', 'rename', False, 'ask log to follow renames')]), |
|
255 | [('', 'rename', False, 'ask log to follow renames')]), | |
254 | 'perftemplating': (perftemplating, []), |
|
256 | 'perftemplating': (perftemplating, []), | |
255 | 'perfdiffwd': (perfdiffwd, []), |
|
257 | 'perfdiffwd': (perfdiffwd, []), | |
256 | 'perfrevlog': (perfrevlog, |
|
258 | 'perfrevlog': (perfrevlog, | |
257 | [('d', 'dist', 100, 'distance between the revisions')], |
|
259 | [('d', 'dist', 100, 'distance between the revisions')], | |
258 | "[INDEXFILE]"), |
|
260 | "[INDEXFILE]"), | |
259 | } |
|
261 | } |
General Comments 0
You need to be logged in to leave comments.
Login now