3 # The MIT License (MIT)
5 # Copyright (C) 2015 - Julien Desfossez <jdesfossez@efficios.com>
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 # Helper to setup a local LTTng tracing session with the appropriate
26 # settings for the lttng analyses scripts
28 SESSION_NAME
="lttng-analysis-$RANDOM"
32 lttng destroy
$SESSION_NAME >/dev
/null
34 echo "You can now launch the analyses scripts on /$TRACEPATH"
38 if test "$1" = "-h" -o "$1" = "--help"; then
43 pgrep
-u root lttng-sessiond
>/dev
/null
45 echo "Starting lttng-sessiond as root (trying sudo, start manually if \
47 sudo lttng-sessiond
-d
54 groups|
grep tracing
>/dev
/null
56 echo "You are not a member of the tracing group, so you need root \
57 access, the script will try with sudo"
61 # check if lttng command if in the path
62 # check if the user can execute the command (with sudo if not in tracing group)
63 # check if lttng-modules is installed
64 $SUDO lttng list
-k |
grep sched_switch
>/dev
/null
66 echo "Something went wrong executing \"$SUDO lttng list -k | grep sched_switch\", \
67 try to fix the problem manually and then start the script again"
70 # if our random session name was already in use, add more randomness...
71 $SUDO lttng list |
grep $SESSION_NAME
73 SESSION_NAME
="$SESSION_NAME-$RANDOM"
75 $SUDO lttng list |
grep $SESSION_NAME
77 echo "Cannot create a random session name, something must be wrong"
81 lttng create
$SESSION_NAME >/tmp
/lttngout
82 [[ $?
!= 0 ]] && exit 2
83 TRACEPATH
=$
(grep Traces
/tmp
/lttngout | cut
-d'/' -f2-)
86 trap "destroy" SIGINT SIGTERM
88 lttng enable-channel
-k chan1
--subbuf-size=8M
>/dev
/null
90 # events that always work
91 lttng enable-event
-s $SESSION_NAME -k sched_switch
,block_rq_complete
,block_rq_issue
,block_bio_remap
,block_bio_backmerge
,netif_receive_skb
,net_dev_xmit
,sched_process_fork
,sched_process_exec
,lttng_statedump_process_state
,lttng_statedump_file_descriptor
,lttng_statedump_block_device
,mm_vmscan_wakeup_kswapd
,mm_page_free
,mm_page_alloc
,block_dirty_buffer
,irq_handler_entry
,irq_handler_exit
,softirq_entry
,softirq_exit
,softirq_raise
-c chan1
>/dev
/null
92 [[ $?
!= 0 ]] && echo "Warning: some events were not enabled, some analyses might not be complete"
94 # events that might fail on specific kernels and that are not mandatory
95 lttng enable-event
-s $SESSION_NAME -k writeback_pages_written
-c chan1
>/dev
/null
2>&1
96 [[ $?
!= 0 ]] && echo "Warning: Optional event writeback_pages_written could not be enabled, everything will still work (experimental feature)"
98 lttng enable-event
-s $SESSION_NAME -k -c chan1
--syscall -a >/dev
/null
99 [[ $?
!= 0 ]] && exit 2
100 # if you want to add Perf counters, do something like that :
101 #lttng add-context -s $SESSION_NAME -k -t perf:cache-misses -t perf:major-faults -t perf:branch-load-misses >/dev/null
103 lttng start
$SESSION_NAME >/dev
/null
104 [[ $?
!= 0 ]] && exit 2
106 echo -n "The trace is now recording, press ctrl+c to stop it "