view contrib/memory.py @ 30080:33e8a5a00007

zsh_completion: update some option usage flags ('+', '=' and ':') Here are the relevant symbol descriptions from [0] optspec:... The colon indicates handling for one or more arguments to the option; if it is not present, the option is assumed to take no arguments. -optname+ The first argument may appear immediately after optname in the same word, or may appear as a separate word after the option. For example, ‘-foo+:...’ specifies that the completed option and argument will look like either ‘-fooarg’ or ‘-foo arg’. -optname= The argument may appear as the next word, or in same word as the option name provided that it is separated from it by an equals sign, for example ‘-foo=arg’ or ‘-foo arg’. There are 3 types of changes in this patch: - addition of '=': means that '--repository ~/foo' can now also be spelled as '--reporitory=~/foo' - addition of '+': means '-r 0' can now also be spelled as '-r0' - removal of '+', '=' and ':': means that '-u|--untrusted' doesn't take any arguments, so '-uq' is definitely '-u -q' and not '--untrusted=q' Occasionally, ':' had to be added together with '=' and '+'. This patch is mostly just making zsh_completion file look more like zsh's own hg completion file so that we can more easily take improvements from them or send patches to them. Some context for this patch from zsh project: [2] [3]. [0]: http://zsh.sourceforge.net/Doc/Release/Completion-System.html [1]: https://sourceforge.net/p/zsh/code/ci/master/tree/Completion/Unix/Command/_hg [2]: https://sourceforge.net/p/zsh/code/ci/92584634d3d39e9ca64475ae5af8010e2ccebe24/ [3]: http://www.zsh.org/mla/workers/2015/msg02551.html
author Anton Shestakov <av6@dwimlabs.net>
date Tue, 04 Oct 2016 20:49:59 +0800
parents ade330deb39a
children ff896733c66a
line wrap: on
line source

# memory.py - track memory usage
#
# Copyright 2009 Matt Mackall <mpm@selenic.com> and others
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

'''helper extension to measure memory usage

Reads current and peak memory usage from ``/proc/self/status`` and
prints it to ``stderr`` on exit.
'''

from __future__ import absolute_import
import atexit

def memusage(ui):
    """Report memory usage of the current process."""
    result = {'peak': 0, 'rss': 0}
    with open('/proc/self/status', 'r') as status:
        # This will only work on systems with a /proc file system
        # (like Linux).
        for line in status:
            parts = line.split()
            key = parts[0][2:-1].lower()
            if key in result:
                result[key] = int(parts[1])
    ui.write_err(", ".join(["%s: %.1f MiB" % (key, value / 1024.0)
                            for key, value in result.iteritems()]) + "\n")

def extsetup(ui):
    atexit.register(memusage, ui)