From 869d48f4570457f3d3fcfbd6d1c134330d34b6f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Graber?= Date: Sat, 22 Mar 2014 19:17:36 -0400 Subject: [PATCH] lxc-ls: Fix memory reporting MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This resolves the memory math when memsw is enabled and fixes reporting of nested containers memory when using cgmanager. Signed-off-by: Stéphane Graber Acked-by: Serge E. Hallyn --- src/lxc/lxc-ls.in | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lxc/lxc-ls.in b/src/lxc/lxc-ls.in index 7e35ab26e..19fbfb83a 100755 --- a/src/lxc/lxc-ls.in +++ b/src/lxc/lxc-ls.in @@ -272,20 +272,22 @@ def get_containers(fd=None, base="/", root=False): if container.running: try: - memory_total = int(container.get_cgroup_item( + memory_ram = int(container.get_cgroup_item( "memory.usage_in_bytes")) except: - memory_total = 0 + memory_ram = 0 try: memory_swap = int(container.get_cgroup_item( - "memory.memsw.usage_in_bytes")) + "memory.memsw.usage_in_bytes")) - memory_ram except: memory_swap = 0 else: - memory_total = 0 + memory_ram = 0 memory_swap = 0 + memory_total = memory_ram + memory_swap + if 'memory' in args.fancy_format: if container.running: entry['memory'] = "%sMB" % round(memory_total / 1048576, 2) @@ -294,8 +296,7 @@ def get_containers(fd=None, base="/", root=False): if 'ram' in args.fancy_format: if container.running: - entry['ram'] = "%sMB" % round( - (memory_total - memory_swap) / 1048576, 2) + entry['ram'] = "%sMB" % round(memory_ram / 1048576, 2) else: entry['ram'] = "-" @@ -330,8 +331,7 @@ def get_containers(fd=None, base="/", root=False): temp_fd, temp_file = tempfile.mkstemp() os.remove(temp_file) - container.attach_wait(get_containers, temp_fd, - attach_flags=0) + container.attach_wait(get_containers, temp_fd) json_file = os.fdopen(temp_fd, "r") json_file.seek(0) -- 2.47.2