Mercurial > hg
annotate contrib/debugcmdserver.py @ 41063:6603de284b0a
progress: avoid ui.configbool() lookup when progress bar is active
Profiling revealed that the ui.configbool('progress', 'debug') during
progress bar updates was consuming a significant amount of overhead.
This commit adds an attribute on progress bar instances that caches
this config option.
The impact on `hg perfprogress` with default options is significant:
before: ! wall 4.641942 comb 4.580000 user 4.210000 sys 0.370000 (best of 3)
after: ! wall 1.948626 comb 1.950000 user 1.950000 sys 0.000000 (best of 5)
After this change, profiling reveals that progress.progbar.progress()
is now consuming ~73% of time.
This change does not improve the execution time if the progress bar
is disabled. We may want a more comprehensive solution for that case,
as the progress bar won't be enabled in a number of scenarios (e.g.
servers and processes not attached to an interactive TTY).
I also think that overhead of ~2.0s for 1M updates is a bit high.
I suspect further refactoring of the progress bar can significantly
reduce overhead. I don't have plans to do this, however.
Differential Revision: https://phab.mercurial-scm.org/D5408
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 10 Dec 2018 20:06:58 +0000 |
parents | cd03fbd5ab57 |
children | 2372284d9457 |
rev | line source |
---|---|
15259
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
2 # |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
3 # Dumps output generated by Mercurial's command server in a formatted style to a |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
4 # given file or stderr if '-' is specified. Output is also written in its raw |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
5 # format to stdout. |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
6 # |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
7 # $ ./hg serve --cmds pipe | ./contrib/debugcmdserver.py - |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
8 # o, 52 -> 'capabilities: getencoding runcommand\nencoding: UTF-8' |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
9 |
28353
cd03fbd5ab57
debugcmdserver: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
16687
diff
changeset
|
10 from __future__ import absolute_import, print_function |
cd03fbd5ab57
debugcmdserver: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
16687
diff
changeset
|
11 import struct |
cd03fbd5ab57
debugcmdserver: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
16687
diff
changeset
|
12 import sys |
15259
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
13 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
14 if len(sys.argv) != 2: |
28353
cd03fbd5ab57
debugcmdserver: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
16687
diff
changeset
|
15 print('usage: debugcmdserver.py FILE') |
15259
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
16 sys.exit(1) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
17 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
18 outputfmt = '>cI' |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
19 outputfmtsize = struct.calcsize(outputfmt) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
20 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
21 if sys.argv[1] == '-': |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
22 log = sys.stderr |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
23 else: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
24 log = open(sys.argv[1], 'a') |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
25 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
26 def read(size): |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
27 data = sys.stdin.read(size) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
28 if not data: |
16687
e34106fa0dc3
cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents:
15259
diff
changeset
|
29 raise EOFError |
15259
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
30 sys.stdout.write(data) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
31 sys.stdout.flush() |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
32 return data |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
33 |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
34 try: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
35 while True: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
36 header = read(outputfmtsize) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
37 channel, length = struct.unpack(outputfmt, header) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
38 log.write('%s, %-4d' % (channel, length)) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
39 if channel in 'IL': |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
40 log.write(' -> waiting for input\n') |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
41 else: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
42 data = read(length) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
43 log.write(' -> %r\n' % data) |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
44 log.flush() |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
45 except EOFError: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
46 pass |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
47 finally: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
48 if log != sys.stderr: |
1d1f6dff9364
contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff
changeset
|
49 log.close() |