| 1 | #!/bin/bash |
| 2 | |
| 3 | # Wrapper to setup a live session on localhost and read it in text mode live |
| 4 | |
| 5 | SESSION_NAME="lttngtop-live-simple-$RANDOM" |
| 6 | |
| 7 | destroy() |
| 8 | { |
| 9 | lttng destroy $SESSION_NAME >/dev/null |
| 10 | rm -rf $HOME/lttng-traces/$HOSTNAME/${SESSION_NAME}* |
| 11 | exit 0 |
| 12 | } |
| 13 | |
| 14 | if test "$1" = "-h" -o "$1" = "--help"; then |
| 15 | echo "usage : $0 [OPTIONS] [program [program-options]]" |
| 16 | echo "OPTIONS :" |
| 17 | echo " -f, --child Follow threads associated with selected PIDs" |
| 18 | echo " -p, --pid Comma-separated list of PIDs to display (in addition to the executed program)" |
| 19 | echo " -a, --all In textdump mode, display all events but write in bold the processes we are interested in (-f and -p)" |
| 20 | echo " -k, --kprobes kprobes to insert (same format as lttng enable-event, can be repeated)" |
| 21 | echo " -o, --output <filename> In textdump, output the log in <filename>" |
| 22 | exit 0 |
| 23 | fi |
| 24 | |
| 25 | pgrep -u root lttng-sessiond >/dev/null |
| 26 | if test $? != 0; then |
| 27 | echo "Starting lttng-sessiond as root (trying sudo, start manually if \ |
| 28 | it fails)" |
| 29 | sudo lttng-sessiond -d |
| 30 | if test $? != 0; then |
| 31 | exit 1 |
| 32 | fi |
| 33 | fi |
| 34 | |
| 35 | pgrep lttng-relayd >/dev/null |
| 36 | if test $? != 0; then |
| 37 | echo "Starting lttng-relayd as your current user, start manually if \ |
| 38 | it fails" |
| 39 | lttng-relayd -d |
| 40 | if test $? != 0; then |
| 41 | exit 1 |
| 42 | fi |
| 43 | fi |
| 44 | |
| 45 | SUDO="" |
| 46 | groups|grep tracing >/dev/null |
| 47 | if test $? != 0; then |
| 48 | echo "You are not a member of the tracing group, so you need root \ |
| 49 | access, the script will try with sudo" |
| 50 | SUDO="sudo" |
| 51 | fi |
| 52 | |
| 53 | # check if lttng command if in the path |
| 54 | # check if the user can execute the command (with sudo if not in tracing group) |
| 55 | # check if lttng-modules is installed |
| 56 | $SUDO lttng list -k | grep sched_switch >/dev/null |
| 57 | if test $? != 0; then |
| 58 | echo "Something went wrong executing \"$SUDO lttng list -k | grep sched_switch\", \ |
| 59 | try to fix the problem manually and then start the script again" |
| 60 | fi |
| 61 | |
| 62 | # if our random session name was already in use, add more randomness... |
| 63 | $SUDO lttng list | grep $SESSION_NAME |
| 64 | if test $? = 0; then |
| 65 | SESSION_NAME="$SESSION_NAME-$RANDOM" |
| 66 | fi |
| 67 | $SUDO lttng list | grep $SESSION_NAME |
| 68 | if test $? = 0; then |
| 69 | echo "Cannot create a random session name, something must be wrong" |
| 70 | exit 2 |
| 71 | fi |
| 72 | |
| 73 | lttng create $SESSION_NAME --live 1000000 -U net://localhost >/dev/null |
| 74 | [[ $? != 0 ]] && exit 2 |
| 75 | |
| 76 | trap "destroy" SIGINT SIGTERM |
| 77 | |
| 78 | lttng enable-event -s $SESSION_NAME -u -a >/dev/null |
| 79 | lttng add-context -s $SESSION_NAME -u -t vpid -t procname -t vtid >/dev/null |
| 80 | |
| 81 | lttng enable-event -s $SESSION_NAME -k lttng_statedump_start,lttng_statedump_end,lttng_statedump_process_state,lttng_statedump_file_descriptor,lttng_statedump_vm_map,lttng_statedump_network_interface,lttng_statedump_interrupt,sched_process_free,sched_switch,sched_process_fork >/dev/null |
| 82 | [[ $? != 0 ]] && exit 2 |
| 83 | lttng enable-event -s $SESSION_NAME -k --syscall -a >/dev/null |
| 84 | [[ $? != 0 ]] && exit 2 |
| 85 | lttng add-context -s $SESSION_NAME -k -t pid -t procname -t tid -t ppid >/dev/null |
| 86 | [[ $? != 0 ]] && exit 2 |
| 87 | # if you want to add Perf counters, do something like that : |
| 88 | #lttng add-context -s $SESSION_NAME -k -t perf:cache-misses -t perf:major-faults -t perf:branch-load-misses >/dev/null |
| 89 | |
| 90 | LTTNGTOPARGS="" |
| 91 | PROG="" |
| 92 | |
| 93 | while [ "$1" != "" ]; do |
| 94 | if test "$1" = "-p"; then |
| 95 | shift |
| 96 | LTTNGTOPARGS="$LTTNGTOPARGS -p $1" |
| 97 | shift |
| 98 | elif test "$1" = "-k"; then |
| 99 | shift |
| 100 | lttng enable-event -k -s $SESSION_NAME "probe-$1" --probe $1 >/dev/null |
| 101 | shift |
| 102 | elif test "$1" = "-o"; then |
| 103 | shift |
| 104 | LTTNGTOPARGS="$LTTNGTOPARGS -o $1" |
| 105 | shift |
| 106 | elif test "${1:0:1}" = "-"; then |
| 107 | LTTNGTOPARGS="$LTTNGTOPARGS $1" |
| 108 | shift |
| 109 | else |
| 110 | PROG=$@ |
| 111 | break |
| 112 | fi |
| 113 | done |
| 114 | |
| 115 | if test ! -z "$PROG"; then |
| 116 | PROG="-- $PROG" |
| 117 | fi |
| 118 | |
| 119 | lttng start $SESSION_NAME >/dev/null |
| 120 | [[ $? != 0 ]] && exit 2 |
| 121 | |
| 122 | s=$(lttngtop -r net://localhost | grep $SESSION_NAME) |
| 123 | if test $? != 0; then |
| 124 | echo "Problem executing lttngtop -r net://localhost | grep $SESSION_NAME" |
| 125 | exit 1 |
| 126 | fi |
| 127 | lttngtop -t -r $(echo $s|cut -d' ' -f1) $LTTNGTOPARGS $PROG |
| 128 | |
| 129 | destroy |