tests/blackbox-readonly-dispatch.py
author Jun Wu <quark@fb.com>
Fri, 02 Sep 2016 15:20:59 +0100
branchstable
changeset 29861 2f6d5c60f6fc
parent 28406 0767c2f624c6
child 35724 853bf7d90804
permissions -rw-r--r--
annotate: pre-calculate the "needed" dictionary (issue5360) The "needed" dict is used as a reference counter to free items in the giant "hist" dict. However, currently it is not very accurate and can lead to dropping "hist" items unnecessarily, for example, with the following DAG, -3- / \ 0--1--2--4-- The current algorithm will visit and calculate rev 1 twice, undesired. And it tries to be smart by clearing rev 1's parents: "pcache[1] = []" at the time hist[1] being accessed (note: hist[1] needs to be used twice, by rev 2 and rev 3). It can result in incorrect results if p1 of rev 4 deletes chunks belonging to rev 0. However, simply removing "needed" is not okay, because it will consume 10x memory: # without any change % HGRCPATH= lrun ./hg annotate mercurial/commands.py -r d130a38 3>&2 [1] MEMORY 49074176 CPUTIME 9.213 REALTIME 9.270 # with "needed" removed MEMORY 637673472 CPUTIME 8.164 REALTIME 8.249 This patch moves "needed" (and "pcache") calculation to a separate DFS to address the issue. It improves perf and fixes issue5360 by correctly reusing hist, while maintaining low memory usage. Some additional attempt has been made to further reduce memory usage, like changing "pcache[f] = []" to "del pcache[f]". Therefore the result can be both faster and lower memory usage: # with this patch applied MEMORY 47575040 CPUTIME 7.870 REALTIME 7.926 [1]: lrun is a lightweight sandbox built on Linux cgroup and namespace. It's used to measure CPU and memory usage here. Source code is available at github.com/quark-zju/lrun.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28405
1d9d29d4813a tests: test-dispatch use print_function
timeless <timeless@mozdev.org>
parents: 28404
diff changeset
     1
from __future__ import absolute_import, print_function
5095
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     2
import os
28404
06245740b408 tests: test-dispatch use absolute_import
timeless <timeless@mozdev.org>
parents: 14438
diff changeset
     3
from mercurial import (
06245740b408 tests: test-dispatch use absolute_import
timeless <timeless@mozdev.org>
parents: 14438
diff changeset
     4
    dispatch,
06245740b408 tests: test-dispatch use absolute_import
timeless <timeless@mozdev.org>
parents: 14438
diff changeset
     5
)
5095
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     6
5178
18a9fbb5cd78 dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents: 5095
diff changeset
     7
def testdispatch(cmd):
18a9fbb5cd78 dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents: 5095
diff changeset
     8
    """Simple wrapper around dispatch.dispatch()
5095
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
     9
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    10
    Prints command and result value, but does not handle quoting.
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    11
    """
28405
1d9d29d4813a tests: test-dispatch use print_function
timeless <timeless@mozdev.org>
parents: 28404
diff changeset
    12
    print("running: %s" % (cmd,))
14438
08bfec2ef031 dispatch: wrap dispatch related information in a request class
Idan Kamara <idankk86@gmail.com>
parents: 9031
diff changeset
    13
    req = dispatch.request(cmd.split())
08bfec2ef031 dispatch: wrap dispatch related information in a request class
Idan Kamara <idankk86@gmail.com>
parents: 9031
diff changeset
    14
    result = dispatch.dispatch(req)
28405
1d9d29d4813a tests: test-dispatch use print_function
timeless <timeless@mozdev.org>
parents: 28404
diff changeset
    15
    print("result: %r" % (result,))
5095
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    16
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    17
# create file 'foo', add and commit
9031
3b76321aa0de compat: use open() instead of file() everywhere
Alejandro Santos <alejolp@alejolp.com>
parents: 5178
diff changeset
    18
f = open('foo', 'wb')
5095
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    19
f.write('foo\n')
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    20
f.close()
5178
18a9fbb5cd78 dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents: 5095
diff changeset
    21
testdispatch("add foo")
18a9fbb5cd78 dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents: 5095
diff changeset
    22
testdispatch("commit -m commit1 -d 2000-01-01 foo")
5095
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    23
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    24
# append to file 'foo' and commit
9031
3b76321aa0de compat: use open() instead of file() everywhere
Alejandro Santos <alejolp@alejolp.com>
parents: 5178
diff changeset
    25
f = open('foo', 'ab')
5095
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    26
f.write('bar\n')
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    27
f.close()
28406
0767c2f624c6 tests: divorce blackbox test from test-dispatch.py
timeless <timeless@mozdev.org>
parents: 28405
diff changeset
    28
# remove blackbox.log directory (proxy for readonly log file)
0767c2f624c6 tests: divorce blackbox test from test-dispatch.py
timeless <timeless@mozdev.org>
parents: 28405
diff changeset
    29
os.rmdir(".hg/blackbox.log")
0767c2f624c6 tests: divorce blackbox test from test-dispatch.py
timeless <timeless@mozdev.org>
parents: 28405
diff changeset
    30
# replace it with the real blackbox.log file
0767c2f624c6 tests: divorce blackbox test from test-dispatch.py
timeless <timeless@mozdev.org>
parents: 28405
diff changeset
    31
os.rename(".hg/blackbox.log-", ".hg/blackbox.log")
5178
18a9fbb5cd78 dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents: 5095
diff changeset
    32
testdispatch("commit -m commit2 -d 2000-01-02 foo")
5095
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    33
f3f033def181 Added test for commands.dispatch (especially 88803a69b24)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    34
# check 88803a69b24 (fancyopts modified command table)
5178
18a9fbb5cd78 dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents: 5095
diff changeset
    35
testdispatch("log -r 0")
18a9fbb5cd78 dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents: 5095
diff changeset
    36
testdispatch("log -r tip")