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