Show More
@@ -1,152 +1,152 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, match, commands |
|
4 | from mercurial import cmdutil, 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 1: |
|
11 | while 1: | |
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 = cmdutil.match(repo, pats, {}) |
|
34 | m = cmdutil.match(repo, 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: |
|
36 | except: | |
37 | try: |
|
37 | try: | |
38 | m = cmdutil.match(repo, pats, {}) |
|
38 | m = cmdutil.match(repo, 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: |
|
40 | except: | |
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, False)))) |
|
45 | #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False, False)))) | |
46 | timer(lambda: sum(map(len, repo.status()))) |
|
46 | timer(lambda: sum(map(len, repo.status()))) | |
47 |
|
47 | |||
48 | def perfheads(ui, repo): |
|
48 | def perfheads(ui, repo): | |
49 | timer(lambda: len(repo.changelog.heads())) |
|
49 | timer(lambda: len(repo.changelog.heads())) | |
50 |
|
50 | |||
51 | def perftags(ui, repo): |
|
51 | def perftags(ui, repo): | |
52 | import mercurial.changelog, mercurial.manifest |
|
52 | import mercurial.changelog, mercurial.manifest | |
53 | def t(): |
|
53 | def t(): | |
54 | repo.changelog = mercurial.changelog.changelog(repo.sopener) |
|
54 | repo.changelog = mercurial.changelog.changelog(repo.sopener) | |
55 | repo.manifest = mercurial.manifest.manifest(repo.sopener) |
|
55 | repo.manifest = mercurial.manifest.manifest(repo.sopener) | |
56 | repo._tags = None |
|
56 | repo._tags = None | |
57 | return len(repo.tags()) |
|
57 | return len(repo.tags()) | |
58 | timer(t) |
|
58 | timer(t) | |
59 |
|
59 | |||
60 | def perfdirstate(ui, repo): |
|
60 | def perfdirstate(ui, repo): | |
61 | "a" in repo.dirstate |
|
61 | "a" in repo.dirstate | |
62 | def d(): |
|
62 | def d(): | |
63 | repo.dirstate.invalidate() |
|
63 | repo.dirstate.invalidate() | |
64 | "a" in repo.dirstate |
|
64 | "a" in repo.dirstate | |
65 | timer(d) |
|
65 | timer(d) | |
66 |
|
66 | |||
67 | def perfdirstatedirs(ui, repo): |
|
67 | def perfdirstatedirs(ui, repo): | |
68 | "a" in repo.dirstate |
|
68 | "a" in repo.dirstate | |
69 | def d(): |
|
69 | def d(): | |
70 | "a" in repo.dirstate._dirs |
|
70 | "a" in repo.dirstate._dirs | |
71 | del repo.dirstate._dirs |
|
71 | del repo.dirstate._dirs | |
72 | timer(d) |
|
72 | timer(d) | |
73 |
|
73 | |||
74 | def perfmanifest(ui, repo): |
|
74 | def perfmanifest(ui, repo): | |
75 | def d(): |
|
75 | def d(): | |
76 | t = repo.manifest.tip() |
|
76 | t = repo.manifest.tip() | |
77 | m = repo.manifest.read(t) |
|
77 | m = repo.manifest.read(t) | |
78 | repo.manifest.mapcache = None |
|
78 | repo.manifest.mapcache = None | |
79 | repo.manifest._cache = None |
|
79 | repo.manifest._cache = None | |
80 | timer(d) |
|
80 | timer(d) | |
81 |
|
81 | |||
82 | def perfindex(ui, repo): |
|
82 | def perfindex(ui, repo): | |
83 | import mercurial.changelog |
|
83 | import mercurial.changelog | |
84 | def d(): |
|
84 | def d(): | |
85 | t = repo.changelog.tip() |
|
85 | t = repo.changelog.tip() | |
86 | repo.changelog = mercurial.changelog.changelog(repo.sopener) |
|
86 | repo.changelog = mercurial.changelog.changelog(repo.sopener) | |
87 | repo.changelog._loadindexmap() |
|
87 | repo.changelog._loadindexmap() | |
88 | timer(d) |
|
88 | timer(d) | |
89 |
|
89 | |||
90 | def perfstartup(ui, repo): |
|
90 | def perfstartup(ui, repo): | |
91 | cmd = sys.argv[0] |
|
91 | cmd = sys.argv[0] | |
92 | def d(): |
|
92 | def d(): | |
93 | os.system("HGRCPATH= %s version -q > /dev/null" % cmd) |
|
93 | os.system("HGRCPATH= %s version -q > /dev/null" % cmd) | |
94 | timer(d) |
|
94 | timer(d) | |
95 |
|
95 | |||
96 | def perfparents(ui, repo): |
|
96 | def perfparents(ui, repo): | |
97 | nl = [repo.changelog.node(i) for i in xrange(1000)] |
|
97 | nl = [repo.changelog.node(i) for i in xrange(1000)] | |
98 | def d(): |
|
98 | def d(): | |
99 | for n in nl: |
|
99 | for n in nl: | |
100 | repo.changelog.parents(n) |
|
100 | repo.changelog.parents(n) | |
101 | timer(d) |
|
101 | timer(d) | |
102 |
|
102 | |||
103 | def perflookup(ui, repo, rev): |
|
103 | def perflookup(ui, repo, rev): | |
104 | timer(lambda: len(repo.lookup(rev))) |
|
104 | timer(lambda: len(repo.lookup(rev))) | |
105 |
|
105 | |||
106 | def perflog(ui, repo, **opts): |
|
106 | def perflog(ui, repo, **opts): | |
107 | ui.pushbuffer() |
|
107 | ui.pushbuffer() | |
108 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', |
|
108 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', | |
109 | copies=opts.get('rename'))) |
|
109 | copies=opts.get('rename'))) | |
110 | ui.popbuffer() |
|
110 | ui.popbuffer() | |
111 |
|
111 | |||
112 | def perftemplating(ui, repo): |
|
112 | def perftemplating(ui, repo): | |
113 | ui.pushbuffer() |
|
113 | ui.pushbuffer() | |
114 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', |
|
114 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', | |
115 | template='{date|shortdate} [{rev}:{node|short}]' |
|
115 | template='{date|shortdate} [{rev}:{node|short}]' | |
116 | ' {author|person}: {desc|firstline}\n')) |
|
116 | ' {author|person}: {desc|firstline}\n')) | |
117 | ui.popbuffer() |
|
117 | ui.popbuffer() | |
118 |
|
118 | |||
119 | def perfdiffwd(ui, repo): |
|
119 | def perfdiffwd(ui, repo): | |
120 | """Profile diff of working directory changes""" |
|
120 | """Profile diff of working directory changes""" | |
121 | options = { |
|
121 | options = { | |
122 | 'w': 'ignore_all_space', |
|
122 | 'w': 'ignore_all_space', | |
123 | 'b': 'ignore_space_change', |
|
123 | 'b': 'ignore_space_change', | |
124 | 'B': 'ignore_blank_lines', |
|
124 | 'B': 'ignore_blank_lines', | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | for diffopt in ('', 'w', 'b', 'B', 'wB'): |
|
127 | for diffopt in ('', 'w', 'b', 'B', 'wB'): | |
128 | opts = dict((options[c], '1') for c in diffopt) |
|
128 | opts = dict((options[c], '1') for c in diffopt) | |
129 | def d(): |
|
129 | def d(): | |
130 | ui.pushbuffer() |
|
130 | ui.pushbuffer() | |
131 | commands.diff(ui, repo, **opts) |
|
131 | commands.diff(ui, repo, **opts) | |
132 | ui.popbuffer() |
|
132 | ui.popbuffer() | |
133 | title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none') |
|
133 | title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none') | |
134 | timer(d, title) |
|
134 | timer(d, title) | |
135 |
|
135 | |||
136 | cmdtable = { |
|
136 | cmdtable = { | |
137 | 'perflookup': (perflookup, []), |
|
137 | 'perflookup': (perflookup, []), | |
138 | 'perfparents': (perfparents, []), |
|
138 | 'perfparents': (perfparents, []), | |
139 | 'perfstartup': (perfstartup, []), |
|
139 | 'perfstartup': (perfstartup, []), | |
140 | 'perfstatus': (perfstatus, []), |
|
140 | 'perfstatus': (perfstatus, []), | |
141 | 'perfwalk': (perfwalk, []), |
|
141 | 'perfwalk': (perfwalk, []), | |
142 | 'perfmanifest': (perfmanifest, []), |
|
142 | 'perfmanifest': (perfmanifest, []), | |
143 | 'perfindex': (perfindex, []), |
|
143 | 'perfindex': (perfindex, []), | |
144 | 'perfheads': (perfheads, []), |
|
144 | 'perfheads': (perfheads, []), | |
145 | 'perftags': (perftags, []), |
|
145 | 'perftags': (perftags, []), | |
146 | 'perfdirstate': (perfdirstate, []), |
|
146 | 'perfdirstate': (perfdirstate, []), | |
147 | 'perfdirstatedirs': (perfdirstate, []), |
|
147 | 'perfdirstatedirs': (perfdirstate, []), | |
148 | 'perflog': (perflog, |
|
148 | 'perflog': (perflog, | |
149 | [('', 'rename', False, 'ask log to follow renames')]), |
|
149 | [('', 'rename', False, 'ask log to follow renames')]), | |
150 | 'perftemplating': (perftemplating, []), |
|
150 | 'perftemplating': (perftemplating, []), | |
151 | 'perfdiffwd': (perfdiffwd, []), |
|
151 | 'perfdiffwd': (perfdiffwd, []), | |
152 | } |
|
152 | } |
@@ -1,86 +1,86 b'' | |||||
1 | # __init__.py - inotify-based status acceleration for Linux |
|
1 | # __init__.py - inotify-based status acceleration for Linux | |
2 | # |
|
2 | # | |
3 | # Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com> |
|
3 | # Copyright 2006, 2007, 2008 Bryan O'Sullivan <bos@serpentine.com> | |
4 | # Copyright 2007, 2008 Brendan Cully <brendan@kublai.com> |
|
4 | # Copyright 2007, 2008 Brendan Cully <brendan@kublai.com> | |
5 | # |
|
5 | # | |
6 | # This software may be used and distributed according to the terms of the |
|
6 | # This software may be used and distributed according to the terms of the | |
7 | # GNU General Public License version 2 or any later version. |
|
7 | # GNU General Public License version 2 or any later version. | |
8 |
|
8 | |||
9 | '''accelerate status report using Linux's inotify service''' |
|
9 | '''accelerate status report using Linux's inotify service''' | |
10 |
|
10 | |||
11 | # todo: socket permissions |
|
11 | # todo: socket permissions | |
12 |
|
12 | |||
13 | from mercurial.i18n import _ |
|
13 | from mercurial.i18n import _ | |
14 | import server |
|
14 | import server | |
15 | from client import client, QueryFailed |
|
15 | from client import client, QueryFailed | |
16 |
|
16 | |||
17 | def serve(ui, repo, **opts): |
|
17 | def serve(ui, repo, **opts): | |
18 | '''start an inotify server for this repository''' |
|
18 | '''start an inotify server for this repository''' | |
19 | server.start(ui, repo.dirstate, repo.root, opts) |
|
19 | server.start(ui, repo.dirstate, repo.root, opts) | |
20 |
|
20 | |||
21 | def debuginotify(ui, repo, **opts): |
|
21 | def debuginotify(ui, repo, **opts): | |
22 | '''debugging information for inotify extension |
|
22 | '''debugging information for inotify extension | |
23 |
|
23 | |||
24 | Prints the list of directories being watched by the inotify server. |
|
24 | Prints the list of directories being watched by the inotify server. | |
25 | ''' |
|
25 | ''' | |
26 | cli = client(ui, repo) |
|
26 | cli = client(ui, repo) | |
27 | response = cli.debugquery() |
|
27 | response = cli.debugquery() | |
28 |
|
28 | |||
29 | ui.write(_('directories being watched:\n')) |
|
29 | ui.write(_('directories being watched:\n')) | |
30 | for path in response: |
|
30 | for path in response: | |
31 | ui.write((' %s/\n') % path) |
|
31 | ui.write((' %s/\n') % path) | |
32 |
|
32 | |||
33 | def reposetup(ui, repo): |
|
33 | def reposetup(ui, repo): | |
34 | if not hasattr(repo, 'dirstate'): |
|
34 | if not hasattr(repo, 'dirstate'): | |
35 | return |
|
35 | return | |
36 |
|
36 | |||
37 | class inotifydirstate(repo.dirstate.__class__): |
|
37 | class inotifydirstate(repo.dirstate.__class__): | |
38 |
|
38 | |||
39 | # We'll set this to false after an unsuccessful attempt so that |
|
39 | # We'll set this to false after an unsuccessful attempt so that | |
40 | # next calls of status() within the same instance don't try again |
|
40 | # next calls of status() within the same instance don't try again | |
41 | # to start an inotify server if it won't start. |
|
41 | # to start an inotify server if it won't start. | |
42 | _inotifyon = True |
|
42 | _inotifyon = True | |
43 |
|
43 | |||
44 | def status(self, match, subrepos, ignored, clean, unknown=True): |
|
44 | def status(self, match, subrepos, ignored, clean, unknown=True): | |
45 | files = match.files() |
|
45 | files = match.files() | |
46 | if '.' in files: |
|
46 | if '.' in files: | |
47 | files = [] |
|
47 | files = [] | |
48 | if self._inotifyon and not ignored and not subrepos and not self._dirty: |
|
48 | if self._inotifyon and not ignored and not subrepos and not self._dirty: | |
49 | cli = client(ui, repo) |
|
49 | cli = client(ui, repo) | |
50 | try: |
|
50 | try: | |
51 | result = cli.statusquery(files, match, False, |
|
51 | result = cli.statusquery(files, match, False, | |
52 | clean, unknown) |
|
52 | clean, unknown) | |
53 | except QueryFailed, instr: |
|
53 | except QueryFailed, instr: | |
54 | ui.debug(str(instr)) |
|
54 | ui.debug(str(instr)) | |
55 | # don't retry within the same hg instance |
|
55 | # don't retry within the same hg instance | |
56 | inotifydirstate._inotifyon = False |
|
56 | inotifydirstate._inotifyon = False | |
57 | pass |
|
57 | pass | |
58 | else: |
|
58 | else: | |
59 | if ui.config('inotify', 'debug'): |
|
59 | if ui.config('inotify', 'debug'): | |
60 | r2 = super(inotifydirstate, self).status( |
|
60 | r2 = super(inotifydirstate, self).status( | |
61 | match, False, clean, unknown) |
|
61 | match, [], False, clean, unknown) | |
62 | for c, a, b in zip('LMARDUIC', result, r2): |
|
62 | for c, a, b in zip('LMARDUIC', result, r2): | |
63 | for f in a: |
|
63 | for f in a: | |
64 | if f not in b: |
|
64 | if f not in b: | |
65 | ui.warn('*** inotify: %s +%s\n' % (c, f)) |
|
65 | ui.warn('*** inotify: %s +%s\n' % (c, f)) | |
66 | for f in b: |
|
66 | for f in b: | |
67 | if f not in a: |
|
67 | if f not in a: | |
68 | ui.warn('*** inotify: %s -%s\n' % (c, f)) |
|
68 | ui.warn('*** inotify: %s -%s\n' % (c, f)) | |
69 | result = r2 |
|
69 | result = r2 | |
70 | return result |
|
70 | return result | |
71 | return super(inotifydirstate, self).status( |
|
71 | return super(inotifydirstate, self).status( | |
72 | match, subrepos, ignored, clean, unknown) |
|
72 | match, subrepos, ignored, clean, unknown) | |
73 |
|
73 | |||
74 | repo.dirstate.__class__ = inotifydirstate |
|
74 | repo.dirstate.__class__ = inotifydirstate | |
75 |
|
75 | |||
76 | cmdtable = { |
|
76 | cmdtable = { | |
77 | 'debuginotify': |
|
77 | 'debuginotify': | |
78 | (debuginotify, [], ('hg debuginotify')), |
|
78 | (debuginotify, [], ('hg debuginotify')), | |
79 | '^inserve': |
|
79 | '^inserve': | |
80 | (serve, |
|
80 | (serve, | |
81 | [('d', 'daemon', None, _('run server in background')), |
|
81 | [('d', 'daemon', None, _('run server in background')), | |
82 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
82 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), | |
83 | ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), |
|
83 | ('t', 'idle-timeout', '', _('minutes to sit idle before exiting')), | |
84 | ('', 'pid-file', '', _('name of file to write process ID to'))], |
|
84 | ('', 'pid-file', '', _('name of file to write process ID to'))], | |
85 | _('hg inserve [OPTION]...')), |
|
85 | _('hg inserve [OPTION]...')), | |
86 | } |
|
86 | } |
General Comments 0
You need to be logged in to leave comments.
Login now