annotate contrib/memory.py @ 41138:8ddc5d8bea25

tests: support passing testcase after .t paths that have path separators This probably could have been implemented by changing the regex above this bit of code, but I wasn't sure if it would end up handling various OSes correctly, so I decided to go with this version instead. Previously: $ tests/run-tests.py tests/test-ssh.t -l running 2 tests using 2 parallel processes .. # Ran 2 tests, 0 skipped, 0 failed. $ tests/run-tests.py tests/test-ssh.t#sshv1 -l running 0 tests using 0 parallel processes # Ran 0 tests, 0 skipped, 0 failed. Now: $ tests/run-tests.py tests/test-ssh.t -l running 2 tests using 2 parallel processes .. # Ran 2 tests, 0 skipped, 0 failed. $ tests/run-tests.py tests/test-ssh.t#sshv1 -l running 1 tests using 1 parallel processes . # Ran 1 tests, 0 skipped, 0 failed. Differential Revision: https://phab.mercurial-scm.org/D5535
author Kyle Lippincott <spectral@google.com>
date Tue, 08 Jan 2019 17:52:39 -0800
parents de5c9d0e02ea
children 2372284d9457
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
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
16 def memusage(ui):
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
17 """Report memory usage of the current process."""
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
18 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
19 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
20 # 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
21 # (like Linux).
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
22 for line in status:
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
23 parts = line.split()
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
24 key = parts[0][2:-1].lower()
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
25 if key in result:
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
26 result[key] = int(parts[1])
30386
ff896733c66a memory: avoid shadowing variables inside a list comprehension
Augie Fackler <augie@google.com>
parents: 28510
diff changeset
27 ui.write_err(", ".join(["%s: %.1f MiB" % (k, v / 1024.0)
ff896733c66a memory: avoid shadowing variables inside a list comprehension
Augie Fackler <augie@google.com>
parents: 28510
diff changeset
28 for k, v in result.iteritems()]) + "\n")
10017
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
29
253d0da256b2 contrib: helper extension to track memory usage
Martin Geisler <mg@lazybytes.net>
parents:
diff changeset
30 def extsetup(ui):
31958
de5c9d0e02ea atexit: switch to home-grown implementation
Bryan O'Sullivan <bryano@fb.com>
parents: 30386
diff changeset
31 ui.atexit(memusage, ui)