##// END OF EJS Templates
ui: provide a mechanism to track and log blocked time...
Simon Farnsworth -
r30976:e92daf15 default
parent child Browse files
Show More
@@ -137,6 +137,9 b' def dispatch(req):'
137 finally:
137 finally:
138 duration = util.timer() - starttime
138 duration = util.timer() - starttime
139 req.ui.flush()
139 req.ui.flush()
140 if req.ui.logblockedtimes:
141 req.ui._blockedtimes['command_duration'] = duration * 1000
142 req.ui.log('uiblocked', 'ui blocked ms', **req.ui._blockedtimes)
140 req.ui.log("commandfinish", "%s exited %s after %0.2f seconds\n",
143 req.ui.log("commandfinish", "%s exited %s after %0.2f seconds\n",
141 msg, ret or 0, duration)
144 msg, ret or 0, duration)
142 return ret
145 return ret
@@ -7,6 +7,7 b''
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import collections
10 import contextlib
11 import contextlib
11 import errno
12 import errno
12 import getpass
13 import getpass
@@ -138,6 +139,8 b' class ui(object):'
138 self.callhooks = True
139 self.callhooks = True
139 # Insecure server connections requested.
140 # Insecure server connections requested.
140 self.insecureconnections = False
141 self.insecureconnections = False
142 # Blocked time
143 self.logblockedtimes = False
141
144
142 if src:
145 if src:
143 self.fout = src.fout
146 self.fout = src.fout
@@ -155,6 +158,7 b' class ui(object):'
155 self.fixconfig()
158 self.fixconfig()
156
159
157 self.httppasswordmgrdb = src.httppasswordmgrdb
160 self.httppasswordmgrdb = src.httppasswordmgrdb
161 self._blockedtimes = src._blockedtimes
158 else:
162 else:
159 self.fout = util.stdout
163 self.fout = util.stdout
160 self.ferr = util.stderr
164 self.ferr = util.stderr
@@ -164,6 +168,7 b' class ui(object):'
164 self.environ = encoding.environ
168 self.environ = encoding.environ
165
169
166 self.httppasswordmgrdb = httppasswordmgrdbproxy()
170 self.httppasswordmgrdb = httppasswordmgrdbproxy()
171 self._blockedtimes = collections.defaultdict(int)
167
172
168 allowed = self.configlist('experimental', 'exportableenviron')
173 allowed = self.configlist('experimental', 'exportableenviron')
169 if '*' in allowed:
174 if '*' in allowed:
@@ -192,6 +197,15 b' class ui(object):'
192 self._progbar.resetstate() # reset last-print time of progress bar
197 self._progbar.resetstate() # reset last-print time of progress bar
193 self.httppasswordmgrdb = httppasswordmgrdbproxy()
198 self.httppasswordmgrdb = httppasswordmgrdbproxy()
194
199
200 @contextlib.contextmanager
201 def timeblockedsection(self, key):
202 starttime = util.timer()
203 try:
204 yield
205 finally:
206 self._blockedtimes[key + '_blocked'] += \
207 (util.timer() - starttime) * 1000
208
195 def formatter(self, topic, opts):
209 def formatter(self, topic, opts):
196 return formatter.formatter(self, topic, opts)
210 return formatter.formatter(self, topic, opts)
197
211
@@ -295,6 +309,7 b' class ui(object):'
295 self._reportuntrusted = self.debugflag or self.configbool("ui",
309 self._reportuntrusted = self.debugflag or self.configbool("ui",
296 "report_untrusted", True)
310 "report_untrusted", True)
297 self.tracebackflag = self.configbool('ui', 'traceback', False)
311 self.tracebackflag = self.configbool('ui', 'traceback', False)
312 self.logblockedtimes = self.configbool('ui', 'logblockedtimes')
298
313
299 if section in (None, 'trusted'):
314 if section in (None, 'trusted'):
300 # update trust information
315 # update trust information
@@ -10,6 +10,7 b' Test if logtoprocess correctly captures '
10 > def foo(ui, repo):
10 > def foo(ui, repo):
11 > ui.log('foo', 'a message: %(bar)s\n', bar='spam')
11 > ui.log('foo', 'a message: %(bar)s\n', bar='spam')
12 > EOF
12 > EOF
13 $ cp $HGRCPATH $HGRCPATH.bak
13 $ cat >> $HGRCPATH << EOF
14 $ cat >> $HGRCPATH << EOF
14 > [extensions]
15 > [extensions]
15 > logtoprocess=
16 > logtoprocess=
@@ -52,3 +53,18 b' ordering issues between the various proc'
52 logtoprocess commandfinish output:
53 logtoprocess commandfinish output:
53 logtoprocess foo output:
54 logtoprocess foo output:
54 spam
55 spam
56
57 Confirm that logging blocked time catches stdio properly:
58 $ cp $HGRCPATH.bak $HGRCPATH
59 $ cat >> $HGRCPATH << EOF
60 > [extensions]
61 > logtoprocess=
62 > pager=
63 > [logtoprocess]
64 > uiblocked=echo "\$EVENT command \$OPT_COMMAND_DURATION ms"
65 > [ui]
66 > logblockedtimes=True
67 > EOF
68
69 $ hg log
70 uiblocked command [0-9]+.[0-9]* ms (re)
General Comments 0
You need to be logged in to leave comments. Login now