Add missing headers for packaging
[lttngtop.git] / utils / lttngtrace
CommitLineData
534a2bcd
JD
1#!/bin/bash
2
3# Wrapper to setup a live session on localhost and read it in text mode live
4
5SESSION_NAME="lttngtop-live-simple-$RANDOM"
6
7destroy()
8{
9 lttng destroy $SESSION_NAME >/dev/null
10 rm -rf $HOME/lttng-traces/$HOSTNAME/${SESSION_NAME}*
11 exit 0
12}
13
14if 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
23fi
24
25pgrep -u root lttng-sessiond >/dev/null
26if test $? != 0; then
27 echo "Starting lttng-sessiond as root (trying sudo, start manually if \
28it fails)"
29 sudo lttng-sessiond -d
30 if test $? != 0; then
31 exit 1
32 fi
33fi
34
35pgrep lttng-relayd >/dev/null
36if test $? != 0; then
37 echo "Starting lttng-relayd as your current user, start manually if \
38it fails"
39 lttng-relayd -d
40 if test $? != 0; then
41 exit 1
42 fi
43fi
44
45SUDO=""
46groups|grep tracing >/dev/null
47if test $? != 0; then
48 echo "You are not a member of the tracing group, so you need root \
49access, the script will try with sudo"
50 SUDO="sudo"
51fi
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
57if test $? != 0; then
58 echo "Something went wrong executing \"$SUDO lttng list -k | grep sched_switch\", \
59try to fix the problem manually and then start the script again"
60fi
61
62# if our random session name was already in use, add more randomness...
63$SUDO lttng list | grep $SESSION_NAME
64if test $? = 0; then
65 SESSION_NAME="$SESSION_NAME-$RANDOM"
66fi
67$SUDO lttng list | grep $SESSION_NAME
68if test $? = 0; then
69 echo "Cannot create a random session name, something must be wrong"
70 exit 2
71fi
72
73lttng create $SESSION_NAME --live 1000000 -U net://localhost >/dev/null
74[[ $? != 0 ]] && exit 2
75
76trap "destroy" SIGINT SIGTERM
77
78lttng enable-event -s $SESSION_NAME -u -a >/dev/null
79lttng add-context -s $SESSION_NAME -u -t vpid -t procname -t vtid >/dev/null
80
81lttng 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
83lttng enable-event -s $SESSION_NAME -k --syscall -a >/dev/null
84[[ $? != 0 ]] && exit 2
85lttng 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
90LTTNGTOPARGS=""
91PROG=""
92
93while [ "$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
113done
114
115if test ! -z "$PROG"; then
116 PROG="-- $PROG"
117fi
118
119lttng start $SESSION_NAME >/dev/null
120[[ $? != 0 ]] && exit 2
121
122s=$(lttngtop -r net://localhost | grep $SESSION_NAME)
123if test $? != 0; then
124 echo "Problem executing lttngtop -r net://localhost | grep $SESSION_NAME"
125 exit 1
126fi
127lttngtop -t -r $(echo $s|cut -d' ' -f1) $LTTNGTOPARGS $PROG
128
129destroy
This page took 0.025482 seconds and 4 git commands to generate.