| 23 | |
| 24 | |
| 25 | def count_threads(ts_path, etnet_threads, accept_threads, task_threads, aio_threads): |
| 26 | |
| 27 | for p in psutil.process_iter(['name', 'cwd', 'threads']): |
| 28 | |
| 29 | # Find the pid corresponding to the ats process we started in autest. |
| 30 | # It needs to match the process name and the binary path. |
| 31 | # If autest can expose the pid of the process this is not needed anymore. |
| 32 | if p.name() == '[TS_MAIN]' and p.cwd() == ts_path: |
| 33 | |
| 34 | etnet_check = set() |
| 35 | accept_check = set() |
| 36 | task_check = set() |
| 37 | aio_check = set() |
| 38 | |
| 39 | for t in p.threads(): |
| 40 | |
| 41 | # Get the name of the thread. |
| 42 | thread_name = psutil.Process(t.id).name() |
| 43 | |
| 44 | if thread_name.startswith('[ET_NET'): |
| 45 | |
| 46 | # Get the id of this thread and check if it's in range. |
| 47 | etnet_id = int(thread_name.split(' ')[1][:-1]) |
| 48 | if etnet_id >= etnet_threads: |
| 49 | sys.stderr.write('Too many ET_NET threads created.\n') |
| 50 | return 2 |
| 51 | elif etnet_id in etnet_check: |
| 52 | sys.stderr.write('ET_NET thread with duplicate thread id created.\n') |
| 53 | return 3 |
| 54 | else: |
| 55 | etnet_check.add(etnet_id) |
| 56 | |
| 57 | elif thread_name.startswith('[ACCEPT'): |
| 58 | |
| 59 | # Get the id of this thread and check if it's in range. |
| 60 | accept_id = int(thread_name.split(' ')[1].split(':')[0]) |
| 61 | if accept_id >= accept_threads: |
| 62 | sys.stderr.write('Too many ACCEPT threads created.\n') |
| 63 | return 5 |
| 64 | else: |
| 65 | accept_check.add(accept_id) |
| 66 | |
| 67 | elif thread_name.startswith('[ET_TASK'): |
| 68 | |
| 69 | # Get the id of this thread and check if it's in range. |
| 70 | task_id = int(thread_name.split(' ')[1][:-1]) |
| 71 | if task_id >= task_threads: |
| 72 | sys.stderr.write('Too many ET_TASK threads created.\n') |
| 73 | return 7 |
| 74 | elif task_id in task_check: |
| 75 | sys.stderr.write('ET_TASK thread with duplicate thread id created.\n') |
| 76 | return 8 |
| 77 | else: |
| 78 | task_check.add(task_id) |
| 79 | |
| 80 | elif thread_name.startswith('[ET_AIO'): |
| 81 | |
| 82 | # Get the id of this thread and check if it's in range. |