From c071ccd98cbd98e5f49a6b6f691e21a578c8a14e Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 19 Jul 2013 17:55:00 -0400 Subject: [PATCH] extras: core-handler: simplify, allow usage from tracing group Allow managing the coredump handler tracing session from the tracing group. Use create --snapshot. Signed-off-by: Mathieu Desnoyers --- extras/core-handler/README | 49 +++++++++++++++++----------------- extras/core-handler/handler.sh | 24 +++++------------ extras/core-handler/install.sh | 12 +++++---- extras/core-handler/test.sh | 24 ++++++++++------- 4 files changed, 53 insertions(+), 56 deletions(-) diff --git a/extras/core-handler/README b/extras/core-handler/README index 4482fd15b..039ce3b5b 100644 --- a/extras/core-handler/README +++ b/extras/core-handler/README @@ -23,36 +23,34 @@ You can use the provided test.sh script to test that the core dump snapshot handler is working properly: # ./test.sh -Setup... -Spawning a session daemon -Session auto-20130626-224838 created. -Kernel channel chan enabled for session auto-20130626-224838 -kernel event sched_switch created in channel chan -Tracing started for session auto-20130626-224838 +Setup coredump-handler... +Session coredump-handler created. +Default snapshot output set to: /tmp/lttng/snapshot +Snapshot mode set. Every channel enabled for that session will be set in overwrite mode and mmap output +kernel event sched_switch created in channel channel0 +Tracing started for session coredump-handler Sleeping... Crashing... -./test.sh: line 35: 16980 Segmentation fault (core dumped) -$(dirname $0)/crash +Segmentation fault (core dumped) +Sleeping... Waiting for data availability -Tracing stopped for session auto-20130626-224838 -Session auto-20130626-224838 destroyed -Core dump and snapshot will be available in /tmp/lttng/{core,snapshot}. +Tracing stopped for session coredump-handler +Session coredump-handler destroyed +Core dump will be available in /tmp/lttng/core. +Snapshot will be available in /tmp/lttng/snapshot. # tree /tmp/lttng /tmp/lttng -|-- core -| `-- core.16980 -`-- snapshot - `-- snapshot - |-- chan_0 - |-- chan_1 - |-- chan_2 - |-- chan_3 - |-- chan_4 - |-- chan_5 - |-- chan_6 - |-- chan_7 - `-- metadata +├── core +│   └── core.29085 +└── snapshot + └── snapshot-1-20130719-175041-0 + └── kernel + ├── channel0_0 + ├── channel0_1 + ├── channel0_2 + ├── channel0_3 + └── metadata Chaining with other core dump handler: @@ -72,7 +70,8 @@ In LTTng handler.sh script: [...] # Save core dump from stdin. -$MKDIR_BIN -p "${CORE_PATH}" +#$MKDIR_BIN -p "${CORE_PATH}" +#$CAT_BIN - > "${CORE_PATH}/${CORE_PREFIX}.$p" # Optional, chain core dump handler with original systemd script. $CAT_BIN - | /usr/lib/systemd/systemd-coredump $p $u $g $s $t $e diff --git a/extras/core-handler/handler.sh b/extras/core-handler/handler.sh index 3026e52f9..781728223 100755 --- a/extras/core-handler/handler.sh +++ b/extras/core-handler/handler.sh @@ -23,18 +23,16 @@ PGREP_BIN="pgrep" MKDIR_BIN="mkdir" LTTNG_BIN="lttng" -# Core file settings. -CORE_PATH="/tmp/lttng/core" -CORE_PREFIX="core" - -# Folder where to save snapshot output. -# Can also be a remote URI. -SNAPSHOT_PATH="/tmp/lttng/snapshot" -SNAPSHOT_OUTPUT="file://${SNAPSHOT_PATH}" +# Session name +SESSION_NAME="coredump-handler" # Sessiond binary name. SESSIOND_BIN_NAME="lttng-sessiond" +# Core file settings. +CORE_PATH="/tmp/lttng/core" +CORE_PREFIX="core" + # Core specifiers, see man core(5) p=$1 # PID of dumped process @@ -60,13 +58,5 @@ $CAT_BIN - > "${CORE_PATH}/${CORE_PREFIX}.$p" # TODO: Checking for a sessiond lockfile would be more appropriate. if $PGREP_BIN -u root "${SESSIOND_BIN_NAME}" > /dev/null 2>&1 then - # Since we are called via the kernel coredump mechanism, we need to - # setup our environment manually. - # - # The lttng command line tool lookup $HOME to adjust the .lttngrc - # path. This is useful to have automatic session name lookup. - export HOME="/root" - $MKDIR_BIN -p "${SNAPSHOT_PATH}" - $LTTNG_BIN snapshot add-output "${SNAPSHOT_OUTPUT}" > /dev/null 2>&1 - $LTTNG_BIN snapshot record > /dev/null 2>&1 + $LTTNG_BIN snapshot record -s ${SESSION_NAME} > /dev/null 2>&1 fi diff --git a/extras/core-handler/install.sh b/extras/core-handler/install.sh index 4e8d8443f..8116805fd 100755 --- a/extras/core-handler/install.sh +++ b/extras/core-handler/install.sh @@ -17,18 +17,20 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # -CORE_PATTERN="/proc/sys/kernel/core_pattern" +CORE_PATTERN_PATH="/proc/sys/kernel/core_pattern" CORE_HANDLER_PATH="$(dirname $(readlink -e $0))/handler.sh" +CORE_PATTERN="$(cat ${CORE_PATTERN_PATH})" -cat ${CORE_PATTERN} > core_pattern.bkp +echo ${CORE_PATTERN} > core_pattern.bkp echo "Backup current core_pattern in core_pattern.bkp." -echo "|$CORE_HANDLER_PATH %p %u %g %s %t %h %e %E %c" > ${CORE_PATTERN} +echo "|$CORE_HANDLER_PATH %p %u %g %s %t %h %e %E %c" > ${CORE_PATTERN_PATH} if [ $? -eq 0 ] then - echo "Successfully installed core_pattern." + echo "Successfully installed core_pattern." else - echo "Installation of core_pattern failed." + echo "Installation of core_pattern failed." + exit 1 fi diff --git a/extras/core-handler/test.sh b/extras/core-handler/test.sh index 0c04bcd97..c36fdf78c 100755 --- a/extras/core-handler/test.sh +++ b/extras/core-handler/test.sh @@ -19,14 +19,19 @@ LTTNG_BIN="lttng" -CHANNEL_NAME="chan" +SESSION_NAME="coredump-handler" + +# Just recording kernel event sched_switch as an example, but we can as +# well record user-space events from UST domain. EVENT_NAME="sched_switch" -echo "Setup..." -$LTTNG_BIN create --no-output -$LTTNG_BIN enable-channel "${CHANNEL_NAME}" -k --overwrite --output mmap -$LTTNG_BIN enable-event "${EVENT_NAME}" -c "${CHANNEL_NAME}" -k -$LTTNG_BIN start +SNAPSHOT_PATH="/tmp/lttng/snapshot" +SNAPSHOT_URI="file://${SNAPSHOT_PATH}" + +echo "Setup ${SESSION_NAME}..." +$LTTNG_BIN create ${SESSION_NAME} --snapshot -U ${SNAPSHOT_PATH} +$LTTNG_BIN enable-event ${EVENT_NAME} -k -s ${SESSION_NAME} +$LTTNG_BIN start ${SESSION_NAME} echo "Sleeping..." sleep 10 @@ -37,7 +42,8 @@ $(dirname $0)/crash echo "Sleeping..." sleep 10 -$LTTNG_BIN stop -$LTTNG_BIN destroy +$LTTNG_BIN stop ${SESSION_NAME} +$LTTNG_BIN destroy ${SESSION_NAME} -echo "Core dump and snapshot will be available in /tmp/lttng/{core,snapshot}." +echo "Core dump will be available in /tmp/lttng/core." +echo "Snapshot will be available in ${SNAPSHOT_PATH}." -- 2.34.1