Skip to content

Commit afa63dc

Browse files
committed
add new [monitoring] section to nipype config
1 parent 8e79259 commit afa63dc

File tree

5 files changed

+46
-30
lines changed

5 files changed

+46
-30
lines changed

doc/users/config_file.rst

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,28 @@ Execution
153153
crashfiles allow portability across machines and shorter load time.
154154
(possible values: ``pklz`` and ``txt``; default value: ``pklz``)
155155

156-
*resource_monitor*
156+
157+
Resource Monitor
158+
~~~~~~~~~~~~~~~~
159+
160+
*enabled*
157161
Enables monitoring the resources occupation (possible values: ``true`` and
158-
``false``; default value: ``false``)
162+
``false``; default value: ``false``). All the following options will be
163+
dismissed if the resource monitor is not enabled.
159164

160-
*resource_monitor_frequency*
165+
*sample_frequency*
161166
Sampling period (in seconds) between measurements of resources (memory, cpus)
162-
being used by an interface. Requires ``resource_monitor`` to be ``true``.
163-
(default value: ``1``)
167+
being used by an interface (default value: ``1``)
164168

165-
*resource_monitor_append*
166-
Append to an existing ``resource_monitor.json`` in the workflow ``base_dir``.
167-
Requires ``resource_monitor`` to be ``true``. (unset by default,
168-
possible values: ``true`` or ``false``, the resource monitor will append
169-
unless explicitly set to ``false``).
169+
*summary_path*
170+
Path where the summary ``resource_monitor.json`` should be stored, when running
171+
a workflow (``summary_path`` does not apply to interfaces run independently).
172+
(unset by default, in which case the summary file will be written out to
173+
``<base_dir>/resource_monitor.json`` of the top-level workflow).
174+
175+
*summary_append*
176+
Append to an existing summary file (only applies to workflows).
177+
(default value: ``true``, possible values: ``true`` or ``false``).
170178

171179
Example
172180
~~~~~~~
@@ -181,6 +189,10 @@ Example
181189
hash_method = timestamp
182190
display_variable = :1
183191

192+
[monitoring]
193+
enabled = false
194+
195+
184196
Workflow.config property has a form of a nested dictionary reflecting the
185197
structure of the .cfg file.
186198

docker/files/run_examples.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ echo '[execution]' >> ${HOME}/.nipype/nipype.cfg
2020
echo 'crashfile_format = txt' >> ${HOME}/.nipype/nipype.cfg
2121

2222
if [[ "${NIPYPE_RESOURCE_MONITOR:-0}" == "1" ]]; then
23-
echo 'resource_monitor = true' >> ${HOME}/.nipype/nipype.cfg
24-
echo 'resource_monitor_frequency = 3' >> ${HOME}/.nipype/nipype.cfg
23+
echo '[monitoring]' >> ${HOME}/.nipype/nipype.cfg
24+
echo 'enabled = true' >> ${HOME}/.nipype/nipype.cfg
25+
echo 'sample_frequency = 3' >> ${HOME}/.nipype/nipype.cfg
2526
fi
2627

2728
# Set up coverage

nipype/interfaces/tests/test_resource_monitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_cmdline_profiling(tmpdir, mem_gb, n_procs):
5454
of a CommandLine-derived interface
5555
"""
5656
from nipype import config
57-
config.set('execution', 'resource_monitor_frequency', '0.2') # Force sampling fast
57+
config.set('monitoring', 'sample_frequency', '0.2') # Force sampling fast
5858

5959
tmpdir.chdir()
6060
iface = UseResources(mem_gb=mem_gb, n_procs=n_procs)
@@ -72,7 +72,7 @@ def test_function_profiling(tmpdir, mem_gb, n_procs):
7272
of a Function interface
7373
"""
7474
from nipype import config
75-
config.set('execution', 'resource_monitor_frequency', '0.2') # Force sampling fast
75+
config.set('monitoring', 'sample_frequency', '0.2') # Force sampling fast
7676

7777
tmpdir.chdir()
7878
iface = niu.Function(function=_use_resources)

nipype/utils/config.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232

3333
CONFIG_DEPRECATIONS = {
34-
'profile_runtime': ('resource_monitor', '1.0'),
35-
'filemanip_level': ('utils_level', '1.0'),
34+
'profile_runtime': ('monitoring.enabled', '1.0'),
35+
'filemanip_level': ('logging.utils_level', '1.0'),
3636
}
3737

3838
NUMPY_MMAP = LooseVersion(np.__version__) >= LooseVersion('1.12.0')
@@ -71,8 +71,11 @@
7171
parameterize_dirs = true
7272
poll_sleep_duration = 2
7373
xvfb_max_wait = 10
74-
resource_monitor = false
75-
resource_monitor_frequency = 1
74+
75+
[monitoring]
76+
enabled = false
77+
sample_frequency = 1
78+
summary_append = true
7679
7780
[check]
7881
interval = 1209600
@@ -105,12 +108,12 @@ def __init__(self, *args, **kwargs):
105108
self._config.read([config_file, 'nipype.cfg'])
106109

107110
for option in CONFIG_DEPRECATIONS:
108-
for section in ['execution', 'logging']:
111+
for section in ['execution', 'logging', 'monitoring']:
109112
if self.has_option(section, option):
110-
new_option = CONFIG_DEPRECATIONS[option][0]
111-
if not self.has_option(section, new_option):
113+
new_section, new_option = CONFIG_DEPRECATIONS[option][0].split('.')
114+
if not self.has_option(new_section, new_option):
112115
# Warn implicit in get
113-
self.set(section, new_option, self.get(section, option))
116+
self.set(new_section, new_option, self.get(section, option))
114117

115118
def set_default_config(self):
116119
self._config.readfp(StringIO(default_cfg))
@@ -138,7 +141,7 @@ def get(self, section, option, default=None):
138141
'"%s" instead.') % (option, CONFIG_DEPRECATIONS[option][1],
139142
CONFIG_DEPRECATIONS[option][0])
140143
warn(msg)
141-
option = CONFIG_DEPRECATIONS[option][0]
144+
section, option = CONFIG_DEPRECATIONS[option][0].split('.')
142145

143146
if self._config.has_option(section, option):
144147
return self._config.get(section, option)
@@ -154,7 +157,7 @@ def set(self, section, option, value):
154157
'"%s" instead.') % (option, CONFIG_DEPRECATIONS[option][1],
155158
CONFIG_DEPRECATIONS[option][0])
156159
warn(msg)
157-
option = CONFIG_DEPRECATIONS[option][0]
160+
section, option = CONFIG_DEPRECATIONS[option][0].split('.')
158161

159162
return self._config.set(section, option, value)
160163

@@ -222,8 +225,8 @@ def resource_monitor(self):
222225
return self._resource_monitor
223226

224227
# Cache config from nipype config
225-
self.resource_monitor = self._config.get(
226-
'execution', 'resource_monitor') or False
228+
self.resource_monitor = str2bool(self._config.get(
229+
'monitoring', 'enabled')) or False
227230
return self._resource_monitor
228231

229232
@resource_monitor.setter
@@ -248,7 +251,7 @@ def resource_monitor(self, value):
248251
if not self._resource_monitor:
249252
warn('Could not enable the resource monitor: psutil>=5.0'
250253
' could not be imported.')
251-
self._config.set('execution', 'resource_monitor',
254+
self._config.set('monitoring', 'enabled',
252255
('%s' % self._resource_monitor).lower())
253256

254257
def enable_resource_monitor(self):

nipype/utils/profiler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# @Author: oesteban
33
# @Date: 2017-09-21 15:50:37
44
# @Last Modified by: oesteban
5-
# @Last Modified time: 2017-10-20 09:12:36
5+
# @Last Modified time: 2017-11-15 11:14:07
66
"""
77
Utilities to keep track of performance
88
"""
@@ -202,8 +202,8 @@ def get_max_resources_used(pid, mem_mb, num_threads, pyfunc=False):
202202
"""
203203

204204
if not resource_monitor:
205-
raise RuntimeError('Attempted to measure resources with '
206-
'"resource_monitor" set off.')
205+
raise RuntimeError('Attempted to measure resources with option '
206+
'"monitoring.enabled" set off.')
207207

208208
try:
209209
mem_mb = max(mem_mb, _get_ram_mb(pid, pyfunc=pyfunc))

0 commit comments

Comments
 (0)