Commit | Line | Data |
---|---|---|
06919f70 | 1 | #!/bin/bash |
4ed24f86 JD |
2 | # |
3 | # The MIT License (MIT) | |
4 | # | |
a3fa57c0 | 5 | # Copyright (C) 2015 - Julien Desfossez <jdesfossez@efficios.com> |
4ed24f86 JD |
6 | # |
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: | |
13 | # | |
14 | # The above copyright notice and this permission notice shall be included in | |
15 | # all copies or substantial portions of the Software. | |
16 | # | |
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 | |
23 | # SOFTWARE. | |
06919f70 JD |
24 | |
25 | # Helper to setup a local LTTng tracing session with the appropriate | |
26 | # settings for the lttng analyses scripts | |
27 | ||
28 | SESSION_NAME="lttng-analysis-$RANDOM" | |
29 | ||
30 | destroy() | |
31 | { | |
32 | lttng destroy $SESSION_NAME >/dev/null | |
33 | echo "" | |
34 | echo "You can now launch the analyses scripts on /$TRACEPATH" | |
35 | exit 0 | |
36 | } | |
37 | ||
38 | if test "$1" = "-h" -o "$1" = "--help"; then | |
39 | echo "usage : $0" | |
40 | exit 0 | |
41 | fi | |
42 | ||
43 | pgrep -u root lttng-sessiond >/dev/null | |
44 | if test $? != 0; then | |
45 | echo "Starting lttng-sessiond as root (trying sudo, start manually if \ | |
46 | it fails)" | |
47 | sudo lttng-sessiond -d | |
48 | if test $? != 0; then | |
49 | exit 1 | |
50 | fi | |
51 | fi | |
52 | ||
53 | SUDO="" | |
54 | groups|grep tracing >/dev/null | |
55 | if test $? != 0; then | |
56 | echo "You are not a member of the tracing group, so you need root \ | |
57 | access, the script will try with sudo" | |
58 | SUDO="sudo" | |
59 | fi | |
60 | ||
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 | |
65 | if test $? != 0; then | |
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" | |
68 | fi | |
69 | ||
70 | # if our random session name was already in use, add more randomness... | |
71 | $SUDO lttng list | grep $SESSION_NAME | |
72 | if test $? = 0; then | |
73 | SESSION_NAME="$SESSION_NAME-$RANDOM" | |
74 | fi | |
75 | $SUDO lttng list | grep $SESSION_NAME | |
76 | if test $? = 0; then | |
77 | echo "Cannot create a random session name, something must be wrong" | |
78 | exit 2 | |
79 | fi | |
80 | ||
81 | lttng create $SESSION_NAME >/tmp/lttngout | |
82 | [[ $? != 0 ]] && exit 2 | |
83 | TRACEPATH=$(grep Traces /tmp/lttngout | cut -d'/' -f2-) | |
84 | rm /tmp/lttngout | |
85 | ||
86 | trap "destroy" SIGINT SIGTERM | |
87 | ||
01ca9f2f | 88 | lttng enable-channel -k chan1 --subbuf-size=8M >/dev/null |
a8d0b962 JD |
89 | |
90 | # events that always work | |
00e78d4b | 91 | lttng enable-event -s $SESSION_NAME -k sched_switch,sched_wakeup,sched_waking,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 |
0e903d62 | 92 | [[ $? != 0 ]] && echo "Warning: some events were not enabled, some analyses might not be complete" |
a8d0b962 JD |
93 | |
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 | |
94cdc371 | 96 | [[ $? != 0 ]] && echo "Warning: Optional event writeback_pages_written could not be enabled, everything will still work (experimental feature)" |
a8d0b962 | 97 | |
06919f70 JD |
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 | |
102 | ||
103 | lttng start $SESSION_NAME >/dev/null | |
104 | [[ $? != 0 ]] && exit 2 | |
105 | ||
106 | echo -n "The trace is now recording, press ctrl+c to stop it " | |
107 | ||
108 | while true; do | |
109 | echo -n "." | |
110 | sleep 1 | |
111 | done | |
112 | ||
113 | destroy |