Skip to content

Commit 6fe8391

Browse files
committed
Debug code
1 parent be1ec62 commit 6fe8391

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

nipype/interfaces/afni/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ def __init__(self, **inputs):
147147
else:
148148
self._output_update()
149149

150+
# Update num threads estimate from OMP_NUM_THREADS env var
151+
import os
152+
self.num_threads = int(os.getenv('OMP_NUM_THREADS', 1))
153+
150154
def _output_update(self):
151155
""" i think? updates class private attribute based on instance input
152156
in fsl also updates ENVIRON variable....not valid in afni

nipype/interfaces/base.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ def _read(self, drain):
12051205

12061206

12071207
# Get number of threads for process
1208-
def _get_num_threads(proc):
1208+
def _get_num_threads(proc, called_from):
12091209
"""Function to get the number of threads a process is using
12101210
NOTE: If
12111211
@@ -1227,12 +1227,16 @@ def _get_num_threads(proc):
12271227
# Init variables
12281228
cb_log = logging.getLogger('callback')
12291229
cb_log.propogate = False
1230+
cb_log.debug('\n---------------------\nCalled from: %s' % called_from)
12301231
cb_log.debug('proc pid: %d, parent pid: %d, name: %s, exe: %s, cmdline: %s, status: %s, num_threads: %d' \
12311232
% (proc.pid, proc.ppid(), proc.name(), proc.exe(), proc.cmdline(), proc.status(), proc.num_threads()))
1233+
1234+
12321235
if proc.status() == psutil.STATUS_RUNNING:
12331236
num_threads = proc.num_threads()
12341237
else:
12351238
num_threads = 0
1239+
12361240
child_threads = 0
12371241
# Iterate through child processes and get number of their threads
12381242
try:
@@ -1241,17 +1245,18 @@ def _get_num_threads(proc):
12411245
# If leaf child process
12421246
if len(child.children()) == 0:
12431247
child_threads += child.num_threads()
1244-
#num_threads = max(num_threads, child.num_threads()) #child.num_threads()
12451248
cb_log.debug('child pid: %d, parent pid: %d, name: %s, exe: %s, cmdline: %s, status: %s, num_threads: %d' \
12461249
% (proc.pid, proc.ppid(), proc.name(), proc.exe(), proc.cmdline(), proc.status(), child.num_threads()))
1250+
cb_log.debug('child_threads: %d, num_threads: %d' % (child_threads, num_threads))
12471251

1248-
#num_threads = max(num_threads, num_children,
1249-
# child.num_threads(), len(child.children()))
12501252
num_threads = max(child_threads, num_threads)
12511253
except psutil.NoSuchProcess:
12521254
pass
12531255

1256+
1257+
12541258
# Return number of threads found
1259+
cb_log.debug('RETURNING num_threads as: %d!\n---------------------------\n' % num_threads)
12551260
return num_threads
12561261

12571262

@@ -1307,7 +1312,7 @@ def _get_ram_mb(pid, pyfunc=False):
13071312

13081313

13091314
# Get max resources used for process
1310-
def get_max_resources_used(pid, mem_mb, num_threads, pyfunc=False):
1315+
def get_max_resources_used(pid, mem_mb, num_threads, called_from, pyfunc=False):
13111316
"""Function to get the RAM and threads usage of a process
13121317
13131318
Paramters
@@ -1332,7 +1337,7 @@ def get_max_resources_used(pid, mem_mb, num_threads, pyfunc=False):
13321337

13331338
try:
13341339
mem_mb = max(mem_mb, _get_ram_mb(pid, pyfunc=pyfunc))
1335-
num_threads = max(num_threads, _get_num_threads(psutil.Process(pid)))
1340+
num_threads = max(num_threads, _get_num_threads(psutil.Process(pid), called_from))
13361341
except Exception as exc:
13371342
iflogger.info('Could not get resources used by process. Error: %s'\
13381343
% exc)
@@ -1394,7 +1399,7 @@ def run_command(runtime, output=None, timeout=0.01, redirect_x=False):
13941399

13951400
# Init variables for memory profiling
13961401
mem_mb = 0
1397-
num_threads = 0
1402+
num_threads = 1
13981403
interval = .5
13991404

14001405
if output == 'stream':
@@ -1415,7 +1420,7 @@ def _process(drain=0):
14151420
while proc.returncode is None:
14161421
if runtime_profile:
14171422
mem_mb, num_threads = \
1418-
get_max_resources_used(proc.pid, mem_mb, num_threads)
1423+
get_max_resources_used(proc.pid, mem_mb, num_threads, cmdline)
14191424
proc.poll()
14201425
_process()
14211426
time.sleep(interval)
@@ -1435,7 +1440,7 @@ def _process(drain=0):
14351440
if runtime_profile:
14361441
while proc.returncode is None:
14371442
mem_mb, num_threads = \
1438-
get_max_resources_used(proc.pid, mem_mb, num_threads)
1443+
get_max_resources_used(proc.pid, mem_mb, num_threads, cmdline)
14391444
proc.poll()
14401445
time.sleep(interval)
14411446
stdout, stderr = proc.communicate()
@@ -1457,7 +1462,7 @@ def _process(drain=0):
14571462
if runtime_profile:
14581463
while proc.returncode is None:
14591464
mem_mb, num_threads = \
1460-
get_max_resources_used(proc.pid, mem_mb, num_threads)
1465+
get_max_resources_used(proc.pid, mem_mb, num_threads, cmdline)
14611466
proc.poll()
14621467
time.sleep(interval)
14631468
ret_code = proc.wait()
@@ -1470,7 +1475,7 @@ def _process(drain=0):
14701475
if runtime_profile:
14711476
while proc.returncode is None:
14721477
mem_mb, num_threads = \
1473-
get_max_resources_used(proc.pid, mem_mb, num_threads)
1478+
get_max_resources_used(proc.pid, mem_mb, num_threads, cmdline)
14741479
proc.poll()
14751480
time.sleep(interval)
14761481
proc.communicate()

nipype/interfaces/utility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def _function_handle_wrapper(queue, **kwargs):
492492
while proc.is_alive():
493493
mem_mb, num_threads = \
494494
get_max_resources_used(proc.pid, mem_mb, num_threads,
495-
pyfunc=True)
495+
function_handle.__name__, pyfunc=True)
496496

497497
# Get result from process queue
498498
out = queue.get()

nipype/pipeline/plugins/base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,8 @@ def run(self, graph, config, updatehash=False):
252252
while np.any(self.proc_done == False) | \
253253
np.any(self.proc_pending == True):
254254

255-
mem_mb, num_thr = get_max_resources_used(gpid, memory_mb, num_threads)
256-
memory_mb = max(mem_mb, memory_mb)
257-
num_threads = max(num_thr, num_threads)
258-
gw_log.info('Memory GB usage: %.4f, Threads usage: %d' % (memory_mb/1024.0, num_threads))
255+
#memory_mb, num_threads = get_max_resources_used(gpid, memory_mb, num_threads, )
256+
#gw_log.info('Memory GB usage: %.4f, Threads usage: %d' % (memory_mb/1024.0, num_threads))
259257
toappend = []
260258
# trigger callbacks for any pending results
261259
while self.pending_tasks:

nipype/utils/draw_gantt_chart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def calculate_resource_timeseries(events, resource):
183183

184184
# Iterate through the events
185185
for tdelta, event in sorted(events.items()):
186-
if tdelta > 70.7:
186+
if tdelta > 80:
187187
print 'hi'
188188
if event['event'] == "start":
189189
if resource in event and event[resource] != 'Unkown':

0 commit comments

Comments
 (0)