diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2008-11-28 12:19:29 -0200 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2008-11-28 12:19:29 -0200 |
commit | 28c093c0bf79a244caee41342640de949039a7bc (patch) | |
tree | 4a31b76f69ca57337d3317ee15e386491e38289a | |
parent | adc836b2b57357c435418aad3eae79e39122ce2f (diff) | |
download | tuna-28c093c0bf79a244caee41342640de949039a7bc.tar.gz |
cmdline: Allow passing threads by name in addition to by pid
Example:
Move firefox, whatever is its pid, to the second CPU in a two core
system, move its children threads too:
[root@doppio tuna]# tuna -t firefox -CP -c 0 -m -P
thread ctxt_switches
pid SCHED_ rtpri affinity voluntary nonvoluntary cmd
10838 OTHER 0 0,1 11548949 8040411 firefox
10848 OTHER 0 0,1 12551 2 firefox
10850 OTHER 0 0,1 2761 1452 firefox
10854 OTHER 0 0,1 1810857 452177 firefox
10855 OTHER 0 0,1 1 0 firefox
10857 OTHER 0 0,1 46469 38581 firefox
10839 OTHER 0 0,1 56727 1561 firefox
10840 OTHER 0 0,1 6885809 2704 firefox
10844 OTHER 0 0,1 1776 21 firefox
10845 OTHER 0 0,1 5 0 firefox
thread ctxt_switches
pid SCHED_ rtpri affinity voluntary nonvoluntary cmd
10838 OTHER 0 0 11548977 8040415 firefox
10848 OTHER 0 0 12551 2 firefox
10850 OTHER 0 0 2761 1452 firefox
10854 OTHER 0 0 1810866 452177 firefox
10855 OTHER 0 0 1 0 firefox
10857 OTHER 0 0 46469 38581 firefox
10839 OTHER 0 0 56727 1561 firefox
10840 OTHER 0 0 6885819 2704 firefox
10844 OTHER 0 0 1776 21 firefox
10845 OTHER 0 0 5 0 firefox
[root@doppio tuna]#
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rwxr-xr-x | tuna-cmd.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/tuna-cmd.py b/tuna-cmd.py index 3d27dd2..3c74a71 100755 --- a/tuna-cmd.py +++ b/tuna-cmd.py @@ -210,6 +210,17 @@ def do_cpu_list_op(op, cpu_list, op_list): return list(set(cpu_list) - set(op_list)) return list(set(op_list)) +def thread_mapper(s): + global ps + try: + return [ int(s), ] + except: + pass + if not ps: + ps = procfs.pidstats() + + return ps.find_by_name(s) + def main(): try: opts, args = getopt.getopt(sys.argv[1:], @@ -251,7 +262,9 @@ def main(): elif o in ("-C", "--affect_children"): affect_children = True elif o in ("-t", "--threads"): - thread_list = map(lambda cpu: int(cpu), a.split(",")) + thread_list = reduce(lambda i, j: i + j, + map(thread_mapper, a.split(","))) + thread_list = list(set(thread_list)) elif o in ("-f", "--filter"): filter = True elif o in ("-g", "--gui"): |