diff options
author | 2016-11-02 13:46:05 +0200 | |
---|---|---|
committer | 2016-11-02 13:52:16 +0200 | |
commit | 5ab7411f67636afc407701d4cf87a5060e5b8aa9 (patch) | |
tree | 261446f44c1f8d7edf5aa16c0f48c7ebe3a28c3d /scripts | |
parent | aafa0ec65f83a6cb9f14782d90df42a8e6e412c3 (diff) |
Trex threads - pin DPDK master thread to the master core
also, some names to the threads to make things clear
and a script to show them
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/trex_show_threads.py | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/scripts/trex_show_threads.py b/scripts/trex_show_threads.py new file mode 100755 index 00000000..fabe6d68 --- /dev/null +++ b/scripts/trex_show_threads.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os + +def read_task_stats (task_path): + + # files + status = task_path + "/status" + stat = task_path + "/stat" + + stats_dict = {} + for line in open(status, 'r').readlines(): + name, value = line.split(':', 1) + stats_dict[name.strip().lower()] = value.strip() + + stat_data = open(stat, 'r').readline().split() + + stats_dict['last_sched_cpu'] = stat_data[-14] + + return stats_dict + + +def show_threads (pid): + process_dir = "/proc/{0}/task".format(pid) + task_paths = ["{0}/{1}".format(process_dir, task) for task in os.listdir(process_dir)] + + + header = [ 'Task Name', 'PID', 'Allowed CPU', 'Last Sched CPU', 'Asked Ctx Switch', 'Forced Ctx Switch'] + for x in header: + print('{:^20}'.format(x)), + print("") + + tasks = [] + for task_path in task_paths: + task = read_task_stats(task_path) + tasks.append(task) + + tasks = sorted(tasks, key = lambda x: int(x['cpus_allowed_list'])) + for task in tasks: + # name + print("{:<20}".format(task['name'])), + print("{:^20}".format(task['pid'])), + print("{:^20}".format(task['cpus_allowed_list'])), + print("{:^20}".format(task['last_sched_cpu'])), + print("{:^20}".format(task['voluntary_ctxt_switches'])), + print("{:^20}".format(task['nonvoluntary_ctxt_switches'])), + print("") + +def isnum (x): + try: + int(x) + return True + except ValueError: + return False + + +def find_trex_pid (): + procs = [x for x in os.listdir('/proc/') if isnum(x)] + for proc in procs: + cmd = open('/proc/{0}/{1}'.format(proc, 'cmdline')).readline() + if '_t-rex' in cmd: + return proc + + return None + +def main (): + trex_pid = find_trex_pid() + if trex_pid is None: + print("Unable to find Trex PID") + exit(1) + + print("\nTrex PID on {0}\n".format(trex_pid)) + show_threads(trex_pid) + + + +if __name__ == '__main__': + main() + |