Ticket #10188: myth-poll

File myth-poll, 2.0 KB (added by J. Ali Harlow <ali@…>, 8 years ago)

Script to see what mythbackend is watching

Line 
1#!/bin/sh
2#
3# This script lists what mythbackend is polling on.
4#
5PATH=/files2/home/ali/wk/myth:$PATH
6if [ -f /var/run/mythbackend.pid ]; then
7    pid=`cat /var/run/mythbackend.pid` || exit 1
8else
9    echo Myth backend not running
10    exit 1
11fi
12if [ -d /proc/$pid/task ]; then
13    polling=`fgrep -lx poll_schedule_timeout /proc/$pid/task/*/wchan | \
14      sed -e 's:.*/task/\([0-9]*\)/wchan:\1:'`
15else
16    echo Myth backend not running
17    exit 1
18fi
19fds_to_list=`mktemp`
20for task in $polling; do
21    read callno arg0 arg1 arg2 arg3 arg4 arg5 sp pc < /proc/$task/syscall
22    # syscall numbers are in /usr/include/syscall.h
23    # NB: We should support ppoll, epoll and pselect (and others?),
24    # but mythbackend doesn't seem to use them.
25    case $callno in
26        7)
27            if [ "$arg0" = "0x0" ]; then
28                fds=$arg0
29            else
30                fds="[`read_mem -t pollfd $pid $arg0 $arg1`]"
31                read_mem -t pollfd $pid $arg0 $arg1 | \
32                  sed -n -e 's/.*{fd=\([1-9][0-9]*\),.*/\1/p' >> $fds_to_list
33            fi
34            echo $task: poll fds=$fds nfds=$arg1
35            ;;
36        23)
37            if [ "$arg1" = "0x0" ]; then
38                readfds=$arg1
39            else
40                readfds=`read_mem -t fdset $pid $arg1 1`
41                echo $readfds | sed -n -e 's/.*\[\(.*\)\].*/\1/p' | \
42                  tr ' ' '\012' >> $fds_to_list
43            fi
44            if [ "$arg2" = "0x0" ]; then
45                writefds=$arg2
46            else
47                writefds=`read_mem -t fdset $pid $arg2 1`
48                echo $writefds | sed -n -e 's/.*\[\(.*\)\].*/\1/p' | \
49                  tr ' ' '\012' >> $fds_to_list
50            fi
51            if [ "$arg3" = "0x0" ]; then
52                exceptfds=$arg3
53            else
54                exceptfds=`read_mem -t fdset $pid $arg3 1`
55                echo $exceptfds | sed -n -e 's/.*\[\(.*\)\].*/\1/p' | \
56                  tr ' ' '\012' >> $fds_to_list
57            fi
58            echo $task: select nfds=$arg0 readfds=$readfds writefds=$writefds \
59              exceptfds=$exceptfds
60            ;;
61        219)
62            echo $task: restart_syscall
63            ;;
64        running)
65            # task is no longer waiting in a syscall
66            ;;
67        *)
68            echo $task: syscall no $callno
69            ;;
70    esac
71done
72fds=`sort -n -u $fds_to_list | tr '\012' ',' | sed -e 's/^,//' -e 's/,$//'`
73lsof -p $pid -a -d $fds
74rm $fds_to_list