Skip to content

Commit 373bddd

Browse files
authored
Merge pull request #2331 from effigies/profile/vms
ENH: Profile VMS as well as RSS
2 parents d1176eb + e8b7697 commit 373bddd

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

nipype/interfaces/base/core.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,9 @@ def run(self, **inputs):
530530

531531
runtime.prof_dict = {
532532
'time': vals[:, 0].tolist(),
533-
'mem_gb': (vals[:, 1] / 1024).tolist(),
534-
'cpus': vals[:, 2].tolist(),
533+
'cpus': vals[:, 1].tolist(),
534+
'rss_GiB': (vals[:, 2] / 1024).tolist(),
535+
'vms_GiB': (vals[:, 3] / 1024).tolist(),
535536
}
536537

537538
return results

nipype/pipeline/engine/utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,8 @@ def write_workflow_resources(graph, filename=None, append=None):
13201320
'time': [],
13211321
'name': [],
13221322
'interface': [],
1323-
'mem_gb': [],
1323+
'rss_GiB': [],
1324+
'vms_GiB': [],
13241325
'cpus': [],
13251326
'mapnode': [],
13261327
'params': [],
@@ -1361,7 +1362,7 @@ def write_workflow_resources(graph, filename=None, append=None):
13611362
'(mapflow %d/%d).', nodename, subidx + 1, len(rt_list))
13621363
continue
13631364

1364-
for key in ['time', 'mem_gb', 'cpus']:
1365+
for key in ['time', 'cpus', 'rss_GiB', 'vms_GiB']:
13651366
big_dict[key] += runtime.prof_dict[key]
13661367

13671368
big_dict['interface'] += [classname] * nsamples

nipype/utils/profiler.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@ def stop(self):
6767

6868
def _sample(self, cpu_interval=None):
6969
cpu = 0.0
70-
mem = 0.0
70+
rss = 0.0
71+
vms = 0.0
7172
try:
7273
with self._process.oneshot():
7374
cpu += self._process.cpu_percent(interval=cpu_interval)
74-
mem += self._process.memory_info().rss
75+
mem_info = self._process.memory_info()
76+
rss += mem_info.rss
77+
vms += mem_info.vms
7578
except psutil.NoSuchProcess:
7679
pass
7780

@@ -85,19 +88,24 @@ def _sample(self, cpu_interval=None):
8588
try:
8689
with child.oneshot():
8790
cpu += child.cpu_percent()
88-
mem += child.memory_info().rss
91+
mem_info = child.memory_info()
92+
rss += mem_info.rss
93+
vms += mem_info.vms
8994
except psutil.NoSuchProcess:
9095
pass
9196

92-
print('%f,%f,%f' % (time(), (mem / _MB), cpu),
97+
print('%f,%f,%f,%f' % (time(), cpu, rss / _MB, vms / _MB),
9398
file=self._logfile)
9499
self._logfile.flush()
95100

96101
def run(self):
97102
"""Core monitoring function, called by start()"""
103+
start_time = time()
104+
wait_til = start_time
98105
while not self._event.is_set():
99106
self._sample()
100-
self._event.wait(self._freq)
107+
wait_til += self._freq
108+
self._event.wait(max(0, wait_til - time()))
101109

102110

103111
# Log node stats function

0 commit comments

Comments
 (0)