contrib/debugcmdserver.py
author Mads Kiilerich <madski@unity3d.com>
Fri, 06 Feb 2015 02:52:10 +0100
branchstable
changeset 24159 5b4ed033390b
parent 16687 e34106fa0dc3
child 28353 cd03fbd5ab57
permissions -rwxr-xr-x
revisionbranchcache: fall back to slow path if starting readonly (issue4531) Transitioning to Mercurial versions with revision branch cache could be slow as long as all operations were readonly (revset queries) and the cache would be populated but not written back. Instead, fall back to using the consistently slow path when readonly and the cache doesn't exist yet. That avoids the overhead of populating the cache without writing it back. If not readonly, it will still populate all missing entries initially. That avoids repeated writing of the cache file with small updates, and it also makes sure a fully populated cache available for the readonly operations.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    10
import sys, struct
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    11
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    12
if len(sys.argv) != 2:
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    13
    print 'usage: debugcmdserver.py FILE'
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    14
    sys.exit(1)
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    15
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    16
outputfmt = '>cI'
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    17
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
    18
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    19
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
    20
    log = sys.stderr
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    21
else:
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    22
    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
    23
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    24
def read(size):
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    25
    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
    26
    if not data:
16687
e34106fa0dc3 cleanup: "raise SomeException()" -> "raise SomeException"
Brodie Rao <brodie@sf.io>
parents: 15259
diff changeset
    27
        raise EOFError
15259
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    28
    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
    29
    sys.stdout.flush()
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    30
    return data
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    31
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    32
try:
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    33
    while True:
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    34
        header = read(outputfmtsize)
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    35
        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
    36
        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
    37
        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
    38
            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
    39
        else:
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    40
            data = read(length)
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    41
            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
    42
        log.flush()
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    43
except EOFError:
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    44
    pass
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    45
finally:
1d1f6dff9364 contrib: add a script to help diagnose raw output of the cmdserver
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
    46
    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
    47
        log.close()