Skip to content

Commit cbb944c

Browse files
avtikhonroot
authored and
root
committed
Add RSS memory status collecting routine
Added RSS memory status collecting routine which parses file /sys/fs/cgroup/memory/memory.stat for RSS value. Part of tarantool/tarantool-qa#98
1 parent 121bd1e commit cbb944c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/options.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ def __init__(self):
271271
default=os.environ.get("MEMTX_ALLOCATOR", "small"),
272272
help="""Memtx allocator type for tests""")
273273

274+
parser.add_argument(
275+
"--collect-statistics",
276+
dest="collect_statistics",
277+
action="store_true",
278+
default=False,
279+
help="""Collect memory/disk host statistics usage.
280+
Default: false.""")
281+
274282
# XXX: We can use parser.parse_intermixed_args() on
275283
# Python 3.7 to understand commands like
276284
# ./test-run.py foo --exclude bar baz

lib/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import re
23
import sys
34
import collections
45
import signal
@@ -233,6 +234,19 @@ def format_process(pid):
233234
return 'process %d [%s; %s]' % (pid, status, cmdline)
234235

235236

237+
def get_mem_stat_rss():
238+
rss = 'unknown'
239+
pat = re.compile(r"^rss .*")
240+
try:
241+
with open('/sys/fs/cgroup/memory/memory.stat', 'r') as f:
242+
for line in f:
243+
if pat.match(line) is not None:
244+
rss = line.split(' ')[1]
245+
except (OSError, IOError):
246+
pass
247+
return rss
248+
249+
236250
def set_fd_cloexec(socket):
237251
flags = fcntl.fcntl(socket, fcntl.F_GETFD)
238252
fcntl.fcntl(socket, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)

0 commit comments

Comments
 (0)