From 5ab7411f67636afc407701d4cf87a5060e5b8aa9 Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 2 Nov 2016 13:46:05 +0200 Subject: 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 --- scripts/trex_show_threads.py | 80 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 scripts/trex_show_threads.py (limited to 'scripts/trex_show_threads.py') 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() + -- cgit 1.2.3-korg