@@ -1205,7 +1205,7 @@ def _read(self, drain):
1205
1205
1206
1206
1207
1207
# Get number of threads for process
1208
- def _get_num_threads (proc ):
1208
+ def _get_num_threads (proc , called_from ):
1209
1209
"""Function to get the number of threads a process is using
1210
1210
NOTE: If
1211
1211
@@ -1227,12 +1227,16 @@ def _get_num_threads(proc):
1227
1227
# Init variables
1228
1228
cb_log = logging .getLogger ('callback' )
1229
1229
cb_log .propogate = False
1230
+ cb_log .debug ('\n ---------------------\n Called from: %s' % called_from )
1230
1231
cb_log .debug ('proc pid: %d, parent pid: %d, name: %s, exe: %s, cmdline: %s, status: %s, num_threads: %d' \
1231
1232
% (proc .pid , proc .ppid (), proc .name (), proc .exe (), proc .cmdline (), proc .status (), proc .num_threads ()))
1233
+
1234
+
1232
1235
if proc .status () == psutil .STATUS_RUNNING :
1233
1236
num_threads = proc .num_threads ()
1234
1237
else :
1235
1238
num_threads = 0
1239
+
1236
1240
child_threads = 0
1237
1241
# Iterate through child processes and get number of their threads
1238
1242
try :
@@ -1241,17 +1245,18 @@ def _get_num_threads(proc):
1241
1245
# If leaf child process
1242
1246
if len (child .children ()) == 0 :
1243
1247
child_threads += child .num_threads ()
1244
- #num_threads = max(num_threads, child.num_threads()) #child.num_threads()
1245
1248
cb_log .debug ('child pid: %d, parent pid: %d, name: %s, exe: %s, cmdline: %s, status: %s, num_threads: %d' \
1246
1249
% (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 ))
1247
1251
1248
- #num_threads = max(num_threads, num_children,
1249
- # child.num_threads(), len(child.children()))
1250
1252
num_threads = max (child_threads , num_threads )
1251
1253
except psutil .NoSuchProcess :
1252
1254
pass
1253
1255
1256
+
1257
+
1254
1258
# Return number of threads found
1259
+ cb_log .debug ('RETURNING num_threads as: %d!\n ---------------------------\n ' % num_threads )
1255
1260
return num_threads
1256
1261
1257
1262
@@ -1307,7 +1312,7 @@ def _get_ram_mb(pid, pyfunc=False):
1307
1312
1308
1313
1309
1314
# 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 ):
1311
1316
"""Function to get the RAM and threads usage of a process
1312
1317
1313
1318
Paramters
@@ -1332,7 +1337,7 @@ def get_max_resources_used(pid, mem_mb, num_threads, pyfunc=False):
1332
1337
1333
1338
try :
1334
1339
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 ))
1336
1341
except Exception as exc :
1337
1342
iflogger .info ('Could not get resources used by process. Error: %s' \
1338
1343
% exc )
@@ -1394,7 +1399,7 @@ def run_command(runtime, output=None, timeout=0.01, redirect_x=False):
1394
1399
1395
1400
# Init variables for memory profiling
1396
1401
mem_mb = 0
1397
- num_threads = 0
1402
+ num_threads = 1
1398
1403
interval = .5
1399
1404
1400
1405
if output == 'stream' :
@@ -1415,7 +1420,7 @@ def _process(drain=0):
1415
1420
while proc .returncode is None :
1416
1421
if runtime_profile :
1417
1422
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 )
1419
1424
proc .poll ()
1420
1425
_process ()
1421
1426
time .sleep (interval )
@@ -1435,7 +1440,7 @@ def _process(drain=0):
1435
1440
if runtime_profile :
1436
1441
while proc .returncode is None :
1437
1442
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 )
1439
1444
proc .poll ()
1440
1445
time .sleep (interval )
1441
1446
stdout , stderr = proc .communicate ()
@@ -1457,7 +1462,7 @@ def _process(drain=0):
1457
1462
if runtime_profile :
1458
1463
while proc .returncode is None :
1459
1464
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 )
1461
1466
proc .poll ()
1462
1467
time .sleep (interval )
1463
1468
ret_code = proc .wait ()
@@ -1470,7 +1475,7 @@ def _process(drain=0):
1470
1475
if runtime_profile :
1471
1476
while proc .returncode is None :
1472
1477
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 )
1474
1479
proc .poll ()
1475
1480
time .sleep (interval )
1476
1481
proc .communicate ()
0 commit comments