annotate contrib/memory.py @ 29889:6f447b9ec263

util: rename checkcase() to fscasesensitive() (API) I always read the name "checkcase(path)" as "do we need to check for case folding at this path", but it's actually (I think) meant to be read "check if the file system cares about case at this path". I'm clearly not the only one confused by this as the dirstate has this property: def _checkcase(self): return not util.checkcase(self._join('.hg')) Maybe we should even inverse the function and call it fscasefolding() since that's what all callers care about?
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 30 Aug 2016 09:22:53 -0700
parents ade330deb39a
children ff896733c66a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10017
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
1 # memory.py - track memory usage
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
2 #
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
3 # Copyright 2009 Matt Mackall <mpm@selenic.com> and others
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
4 #
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
10264
d6512b3e9ac0 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 10017
diff changeset
6 # GNU General Public License version 2 or any later version.
10017
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
7
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
8 '''helper extension to measure memory usage
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
9
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
10 Reads current and peak memory usage from ``/proc/self/status`` and
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
11 prints it to ``stderr`` on exit.
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
12 '''
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
13
28510
ade330deb39a contrib: make memory.py use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27795
diff changeset
14 from __future__ import absolute_import
10017
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
15 import atexit
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
16
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
17 def memusage(ui):
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
18 """Report memory usage of the current process."""
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
19 result = {'peak': 0, 'rss': 0}
27795
3e0d27d298b7 with: use context manager for file I/O in memusage
Bryan O'Sullivan <bryano@fb.com>
parents: 10282
diff changeset
20 with open('/proc/self/status', 'r') as status:
10017
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
21 # This will only work on systems with a /proc file system
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
22 # (like Linux).
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
23 for line in status:
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
24 parts = line.split()
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
25 key = parts[0][2:-1].lower()
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
26 if key in result:
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
27 result[key] = int(parts[1])
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
28 ui.write_err(", ".join(["%s: %.1f MiB" % (key, value / 1024.0)
10017
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
29 for key, value in result.iteritems()]) + "\n")
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
30
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
31 def extsetup(ui):
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
32 atexit.register(memusage, ui)