Skip to content

Commit 280a852

Browse files
authored
Merge pull request #1157 from tonyyzy/master
CWL memory usage report
2 parents 8d85120 + 2a5ce6b commit 280a852

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

cwltool/job.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -681,21 +681,6 @@ def run(self,
681681
monitor_function = functools.partial(self.process_monitor)
682682
self._execute(runtime, env, runtimeContext, monitor_function)
683683

684-
@staticmethod
685-
def docker_get_memory(cid): # type: (Text) -> int
686-
memory = None
687-
try:
688-
memory = subprocess.check_output(
689-
['docker', 'inspect', '--type', 'container', '--format',
690-
'{{.HostConfig.Memory}}', cid], stderr=subprocess.DEVNULL) # type: ignore
691-
except subprocess.CalledProcessError:
692-
pass
693-
if memory:
694-
value = int(memory)
695-
if value != 0:
696-
return value
697-
return psutil.virtual_memory().total
698-
699684
def docker_monitor(self, cidfile, tmpdir_prefix, cleanup_cidfile, process):
700685
# type: (Text, Text, bool, subprocess.Popen) -> None
701686
"""Record memory usage of the running Docker container."""
@@ -716,7 +701,7 @@ def docker_monitor(self, cidfile, tmpdir_prefix, cleanup_cidfile, process):
716701
cid = cidhandle.readline().strip()
717702
except (OSError, IOError):
718703
cid = None
719-
max_mem = self.docker_get_memory(cid)
704+
max_mem = psutil.virtual_memory().total
720705
tmp_dir, tmp_prefix = os.path.split(tmpdir_prefix)
721706
stats_file = tempfile.NamedTemporaryFile(prefix=tmp_prefix, dir=tmp_dir)
722707
with open(stats_file.name, mode="w") as stats_file_handle:
@@ -736,7 +721,7 @@ def docker_monitor(self, cidfile, tmpdir_prefix, cleanup_cidfile, process):
736721
except ValueError:
737722
break
738723
_logger.info(u"[job %s] Max memory used: %iMiB", self.name,
739-
int((max_mem_percent * max_mem) / (2 ** 20)))
724+
int((max_mem_percent / 100 * max_mem) / (2 ** 20)))
740725
if cleanup_cidfile:
741726
os.remove(cidfile)
742727

0 commit comments

Comments
 (0)