Skip to contentSkip to conversation

UST command to regenerate the statedump

PATCH Superseded Julien Desfossez 3 participants 8 messages Jul 4, 2016 3 messages not in the archive

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 2/6 UST command to regenerate the statedump

From: Mathieu Desnoyers <[email protected]>

---
 src/bin/lttng-sessiond/lttng-ust-abi.h | 1 +
 1 file changed, 1 insertion(+)
src/bin/lttng-sessiond/lttng-ust-abi.h +1 -0
index 7bec0c9..9ef7b9a 100644
@@ -275,6 +275,7 @@ struct lttng_ust_event_exclusion {
 	_UST_CMDW(0x51, struct lttng_ust_channel)
 #define LTTNG_UST_SESSION_START			_UST_CMD(0x52)
 #define LTTNG_UST_SESSION_STOP			_UST_CMD(0x53)
+#define LTTNG_UST_SESSION_STATEDUMP		_UST_CMD(0x54)
 
 /* Channel FD commands */
 #define LTTNG_UST_STREAM			_UST_CMD(0x60)
Signature · 6 lines
1.9.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#2 lore raw

PATCH v2 3/6 Kernel ioctl to regenerate the statedump

In reply to a message not in the archive

From: Mathieu Desnoyers <[email protected]>

---
 src/common/kernel-ctl/kernel-ioctl.h | 2 ++
 1 file changed, 2 insertions(+)
src/common/kernel-ctl/kernel-ioctl.h +2 -0
index 68056dc..805de02 100644
@@ -134,6 +134,8 @@
  */
 #define LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS	_IO(0xF6, 0x58)
 #define LTTNG_KERNEL_SESSION_METADATA_REGEN	_IO(0xF6, 0x59)
+/* 0x5A and 0x5B are reserved for a future ABI-breaking cleanup. */
+#define LTTNG_KERNEL_SESSION_STATEDUMP		_IO(0xF6, 0x5C)
 
 /* Channel FD ioctl */
 #define LTTNG_KERNEL_STREAM			_IO(0xF6, 0x62)
Signature · 6 lines
1.9.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#3 lore raw

PATCH v2 4/6 Allow regenerating the statedump of a running session

In reply to a message not in the archive

The "lttng regenerate statedump" command can be used to regenerate the statedump of a running session whenever needed. This is particularly useful in snapshot and trace-file rotation modes where the original statedump may be lost.

---
 include/lttng/lttng-error.h              |  1 +
 include/lttng/lttng.h                    |  9 +++++
 src/bin/lttng-sessiond/cmd.c             | 44 +++++++++++++++++++++
 src/bin/lttng-sessiond/cmd.h             |  1 +
 src/bin/lttng-sessiond/main.c            |  6 +++
 src/bin/lttng-sessiond/ust-app.c         | 66 ++++++++++++++++++++++++++++++++
 src/bin/lttng-sessiond/ust-app.h         |  6 +++
 src/bin/lttng/commands/regenerate.c      | 19 +++++++++
 src/common/error.c                       |  1 +
 src/common/kernel-ctl/kernel-ctl.c       |  5 +++
 src/common/kernel-ctl/kernel-ctl.h       |  1 +
 src/common/sessiond-comm/sessiond-comm.h |  1 +
 src/lib/lttng-ctl/lttng-ctl.c            | 30 +++++++++++++++
 13 files changed, 190 insertions(+)
include/lttng/lttng-error.h +1 -0
index 72194ef..52ce333 100644
@@ -142,6 +142,7 @@ enum lttng_error_code {
 	LTTNG_ERR_LIVE_SESSION           = 119, /* Live session unsupported */
 	LTTNG_ERR_PER_PID_SESSION        = 120, /* Per-PID sessions unsupported */
 	LTTNG_ERR_KERN_CONTEXT_UNAVAILABLE = 121, /* Context unavailable on this kernel */
+	LTTNG_ERR_REGEN_STATEDUMP_FAIL   = 122, /* Failed to regenerate the statdump */
 
 	/* MUST be last element */
 	LTTNG_ERR_NR,                           /* Last element */
include/lttng/lttng.h +9 -0
index 09aa969..b81a01c 100644
@@ -173,6 +173,15 @@ extern int lttng_metadata_regenerate(const char *session_name);
  */
 extern int lttng_regenerate_metadata(const char *session_name);
 
+/*
+ * Trigger the regeneration of the statedump for a session. The new statedump
+ * information is appended to the currently active trace, the session needs to
+ * be started.
+ *
+ * Return 0 on success, a negative LTTng error code on error.
+ */
+extern int lttng_regenerate_statedump(const char *session_name);
+
 #ifdef __cplusplus
 }
 #endif
src/bin/lttng-sessiond/cmd.c +44 -0

50 lines not on this page · raw message

src/bin/lttng-sessiond/cmd.h +1 -0
index 320d717..975a7f1 100644
@@ -111,5 +111,6 @@ int cmd_snapshot_record(struct ltt_session *session,
 int cmd_set_session_shm_path(struct ltt_session *session,
 		const char *shm_path);
 int cmd_regenerate_metadata(struct ltt_session *session);
+int cmd_regenerate_statedump(struct ltt_session *session);
 
 #endif /* CMD_H */
src/bin/lttng-sessiond/main.c +6 -0
index 3623e5d..8309c3f 100644
@@ -3004,6 +3004,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock,
 	case LTTNG_SAVE_SESSION:
 	case LTTNG_SET_SESSION_SHM_PATH:
 	case LTTNG_REGENERATE_METADATA:
+	case LTTNG_REGENERATE_STATEDUMP:
 		need_domain = 0;
 		break;
 	default:
@@ -4119,6 +4120,11 @@ error_add_context:
 		ret = cmd_regenerate_metadata(cmd_ctx->session);
 		break;
 	}
+	case LTTNG_REGENERATE_STATEDUMP:
+	{
+		ret = cmd_regenerate_statedump(cmd_ctx->session);
+		break;
+	}
 	default:
 		ret = LTTNG_ERR_UND;
 		break;
src/bin/lttng-sessiond/ust-app.c +66 -0

69 lines not on this page · raw message

src/bin/lttng-sessiond/ust-app.h +6 -0
index d02f353..8369d14 100644
@@ -352,6 +352,7 @@ int ust_app_pid_get_channel_runtime_stats(struct ltt_ust_session *usess,
 		struct ltt_ust_channel *uchan,
 		struct consumer_output *consumer,
 		int overwrite, uint64_t *discarded, uint64_t *lost);
+int ust_app_regenerate_statedump_all(struct ltt_ust_session *usess);
 
 static inline
 int ust_app_supported(void)
@@ -583,6 +584,11 @@ int ust_app_pid_get_channel_runtime_stats(struct ltt_ust_session *usess,
 {
 	return 0;
 }
+static inline
+int ust_app_regenerate_metadata_all(struct ltt_ust_session *usess)
+{
+	return 0;
+}
 
 #endif /* HAVE_LIBLTTNG_UST_CTL */
 
src/bin/lttng/commands/regenerate.c +19 -0
index c64d8fe..f111d06 100644
@@ -32,6 +32,7 @@ static char *opt_session_name;
 static char *session_name = NULL;
 
 static int regenerate_metadata(int argc, const char **argv);
+static int regenerate_statedump(int argc, const char **argv);
 
 enum {
 	OPT_HELP = 1,
@@ -52,6 +53,7 @@ static struct poptOption long_options[] = {
 
 static struct cmd_struct actions[] = {
 	{ "metadata", regenerate_metadata },
+	{ "statedump", regenerate_statedump },
 	{ NULL, NULL }	/* Array closure */
 };
 
@@ -88,6 +90,23 @@ end:
 	return ret;
 }
 
+static int regenerate_statedump(int argc, const char **argv)
+{
+	int ret;
+
+	if (argc > 1) {
+		ret = -LTTNG_ERR_INVALID;
+		goto end;
+	}
+	ret = lttng_regenerate_statedump(session_name);
+	if (ret == 0) {
+		MSG("Statedump successfully regenerated for session %s", session_name);
+	}
+
+end:
+	return ret;
+}
+
 static int handle_command(const char **argv)
 {
 	struct cmd_struct *cmd;
src/common/error.c +1 -0
index bc42577..6730e14 100644
@@ -183,6 +183,7 @@ static const char *error_string_array[] = {
 	[ ERROR_INDEX(LTTNG_ERR_LIVE_SESSION) ] = "Live sessions are not supported",
 	[ ERROR_INDEX(LTTNG_ERR_PER_PID_SESSION) ] = "Per-PID tracing sessions are not supported",
 	[ ERROR_INDEX(LTTNG_ERR_KERN_CONTEXT_UNAVAILABLE) ] = "Context unavailable on this kernel",
+	[ ERROR_INDEX(LTTNG_ERR_REGEN_STATEDUMP_FAIL) ] = "Statedump regeneration failed",
 
 	/* Last element */
 	[ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"
src/common/kernel-ctl/kernel-ctl.c +5 -0
index e1de0e7..1c2ab61 100644
@@ -230,6 +230,11 @@ int kernctl_session_regenerate_metadata(int fd)
 	return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_METADATA_REGEN);
 }
 
+int kernctl_session_regenerate_statedump(int fd)
+{
+	return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_STATEDUMP);
+}
+
 int kernctl_create_stream(int fd)
 {
 	return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_STREAM,
src/common/kernel-ctl/kernel-ctl.h +1 -0
index f30e6f3..7c25a17 100644
@@ -66,6 +66,7 @@ int kernctl_untrack_pid(int fd, int pid);
 int kernctl_list_tracker_pids(int fd);
 
 int kernctl_session_regenerate_metadata(int fd);
+int kernctl_session_regenerate_statedump(int fd);
 
 /* Buffer operations */
 
src/common/sessiond-comm/sessiond-comm.h +1 -0
index 29740c1..628b1ea 100644
@@ -95,6 +95,7 @@ enum lttcomm_sessiond_command {
 	LTTNG_LIST_TRACKER_PIDS             = 34,
 	LTTNG_SET_SESSION_SHM_PATH          = 40,
 	LTTNG_REGENERATE_METADATA           = 41,
+	LTTNG_REGENERATE_STATEDUMP          = 42,
 };
 
 enum lttcomm_relayd_command {
src/lib/lttng-ctl/lttng-ctl.c +30 -0
index 8c78e1c..bcd59f0 100644
@@ -2419,6 +2419,36 @@ int lttng_metadata_regenerate(const char *session_name)
 }
 
 /*
+ * Regenerate the statedump of a session.
+ * Return 0 on success, a negative error code on error.
+ */
+int lttng_regenerate_statedump(const char *session_name)
+{
+	int ret;
+	struct lttcomm_session_msg lsm;
+
+	if (!session_name) {
+		ret = -LTTNG_ERR_INVALID;
+		goto end;
+	}
+
+	memset(&lsm, 0, sizeof(lsm));
+	lsm.cmd_type = LTTNG_REGENERATE_STATEDUMP;
+
+	lttng_ctl_copy_string(lsm.session.name, session_name,
+			sizeof(lsm.session.name));
+
+	ret = lttng_ctl_ask_sessiond(&lsm, NULL);
+	if (ret < 0) {
+		goto end;
+	}
+
+	ret = 0;
+end:
+	return ret;
+}
+
+/*
  * lib constructor.
  */
 static void __attribute__((constructor)) init(void)
Signature · 6 lines
1.9.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#4 lore raw

PATCH v2 5/6 Tests for the regenerate statedump command

In reply to a message not in the archive
---
 configure.ac                                       |  1 +
 tests/fast_regression                              |  1 +
 tests/regression/tools/Makefile.am                 |  2 +-
 tests/regression/tools/regen-statedump/Makefile.am | 16 ++++
 tests/regression/tools/regen-statedump/test_kernel | 80 +++++++++++++++++++
 tests/regression/tools/regen-statedump/test_ust    | 89 ++++++++++++++++++++++
 tests/root_regression                              |  1 +
 tests/utils/utils.sh                               | 54 +++++++++++++
 8 files changed, 243 insertions(+), 1 deletion(-)
 create mode 100644 tests/regression/tools/regen-statedump/Makefile.am
 create mode 100755 tests/regression/tools/regen-statedump/test_kernel
 create mode 100755 tests/regression/tools/regen-statedump/test_ust
configure.ac +1 -0
index 89a7858..6222e2b 100644
@@ -981,6 +981,7 @@ AC_CONFIG_FILES([
 	tests/regression/tools/wildcard/Makefile
 	tests/regression/tools/crash/Makefile
 	tests/regression/tools/regen-metadata/Makefile
+	tests/regression/tools/regen-statedump/Makefile
 	tests/regression/ust/Makefile
 	tests/regression/ust/nprocesses/Makefile
 	tests/regression/ust/high-throughput/Makefile
tests/fast_regression +1 -0
index 262c846..8edbeca 100644
@@ -17,6 +17,7 @@ regression/tools/mi/test_mi
 regression/tools/wildcard/test_event_wildcard
 regression/tools/crash/test_crash
 regression/tools/regen-metadata/test_ust
+regression/tools/regen-statedump/test_ust
 regression/ust/before-after/test_before_after
 regression/ust/buffers-pid/test_buffers_pid
 regression/ust/multi-session/test_multi_session
tests/regression/tools/Makefile.am +1 -1
index 91820ad..76374c7 100644
@@ -1,2 +1,2 @@
 SUBDIRS = streaming filtering health tracefile-limits snapshots live exclusion save-load mi \
-		wildcard crash regen-metadata
+		wildcard crash regen-metadata regen-statedump
tests/regression/tools/regen-statedump/Makefile.am new file +16 -0
new file mode 100644
index 0000000..d4a92eb
@@ -0,0 +1,16 @@
+noinst_SCRIPTS = test_ust test_kernel
+EXTRA_DIST = test_ust test_kernel
+
+all-local:
+	@if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+		for script in $(EXTRA_DIST); do \
+			cp -f $(srcdir)/$$script $(builddir); \
+		done; \
+	fi
+
+clean-local:
+	@if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+		for script in $(EXTRA_DIST); do \
+			rm -f $(builddir)/$$script; \
+		done; \
+	fi
tests/regression/tools/regen-statedump/test_kernel new file +80 -0

80 lines not on this page · raw message

tests/regression/tools/regen-statedump/test_ust new file +89 -0

89 lines not on this page · raw message

tests/root_regression +1 -0
index d0fad04..d3eaf23 100644
@@ -15,4 +15,5 @@ regression/tools/filtering/test_unsupported_op
 regression/tools/filtering/test_valid_filter
 regression/tools/wildcard/test_event_wildcard
 regression/tools/regen-metadata/test_kernel
+regression/tools/regen-statedump/test_kernel
 regression/ust/test_event_perf
tests/utils/utils.sh +54 -0

66 lines not on this page · raw message

Signature · 6 lines
1.9.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#5 lore raw

PATCH v2 6/6 Manpage for the regenerate statedump command

In reply to a message not in the archive
---
 doc/man/lttng-regenerate.1.txt | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
doc/man/lttng-regenerate.1.txt +13 -2
index dbbfa4d..80bae20 100644
@@ -14,12 +14,19 @@ Regenerate the metadata of a session
 [verse]
 *lttng* ['linkgenoptions:(GENERAL OPTIONS)'] *regenerate metadata* [option:--session='SESSION']
 
+Regenerate the statedump of a session
+
+[verse]
+*lttng* ['linkgenoptions:(GENERAL OPTIONS)'] *regenerate statedump* [option:--session='SESSION']
+
 DESCRIPTION
 -----------
 The `lttng regenerate` command manages a tracing session's data regeneration
 options.
 
-As of this version, only the `metadata` command's action is available.
+As of this version, the `metadata` and `statedump` command's action are
+available.
+
 Regenerating a tracing session's metadata can be used to
 resample the offset between the system's monotonic clock and
 the wall-clock time.
@@ -32,12 +39,16 @@ traced before its wall time is NTP-corrected. Regenerating the tracing
 session's metadata ensures that trace viewers can accurately determine
 the events time relative to Unix Epoch.
 
+Regenerating a tracing session's statedump can be used to collect up-to-date
+statedump informations during the trace session. This is particularly useful in
+snapshot or trace-file rotation modes where the statedump information may be
+lost.
 
 include::common-cmd-options-head.txt[]
 
 
 option:-s, option:--session='SESSION'::
-    Manage the metadata generation of the tracing session named 'SESSION'
+    Manage the data regeneration of the tracing session named 'SESSION'
     instead of the current tracing session.
 
 
Signature · 6 lines
1.9.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Re: [PATCH lttng-tools v2 6/6] Manpage for the regenerate statedump command

Change subject to "Add man page for..."

Quoted 11 lines · Julien Desfossez
---
 doc/man/lttng-regenerate.1.txt | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
doc/man/lttng-regenerate.1.txt +0 -0
index dbbfa4d..80bae20 100644

doc/man/lttng-regenerate.1.txt Regenerate the metadata of a session · line 17

Quoted 4 lines
doc/man/lttng-regenerate.1.txt +1 -0
@@ -14,12 +14,19 @@ Regenerate the metadata of a session
 [verse]
 *lttng* ['linkgenoptions:(GENERAL OPTIONS)'] *regenerate metadata* [option:--session='SESSION']
 
+Regenerate the statedump of a session

"state dump" in two words

doc/man/lttng-regenerate.1.txt Regenerate the metadata of a session · line 27

Quoted 11 lines
doc/man/lttng-regenerate.1.txt +5 -1
+
+[verse]
+*lttng* ['linkgenoptions:(GENERAL OPTIONS)'] *regenerate statedump* [option:--session='SESSION']
+
 DESCRIPTION
 -----------
 The `lttng regenerate` command manages a tracing session's data regeneration
 options.
 
-As of this version, only the `metadata` command's action is available.
+As of this version, the `metadata` and `statedump` command's action are

command actions

Quoted 26 lines
doc/man/lttng-regenerate.1.txt +7 -2
+available.
+
 Regenerating a tracing session's metadata can be used to
 resample the offset between the system's monotonic clock and
 the wall-clock time.
@@ -32,12 +39,16 @@ traced before its wall time is NTP-corrected. Regenerating the tracing
 session's metadata ensures that trace viewers can accurately determine
 the events time relative to Unix Epoch.
 
+Regenerating a tracing session's statedump can be used to collect up-to-date
+statedump informations during the trace session. This is particularly useful in
+snapshot or trace-file rotation modes where the statedump information may be
+lost.
 
 include::common-cmd-options-head.txt[]
 
 
 option:-s, option:--session='SESSION'::
-    Manage the metadata generation of the tracing session named 'SESSION'
+    Manage the data regeneration of the tracing session named 'SESSION'
     instead of the current tracing session.
 
 
--

1.9.1

Signature · 7 lines
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#8 lore raw

Re: [PATCH lttng-tools v2 6/6] Manpage for the regenerate statedump command

In reply to a message not in the archive

doc/man/lttng-regenerate.1.txt Regenerate the metadata of a session

Quoted 12 lines · Julien Desfossez
---
 doc/man/lttng-regenerate.1.txt | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
doc/man/lttng-regenerate.1.txt +0 -0
index dbbfa4d..80bae20 100644
@@ -14,12 +14,19 @@ Regenerate the metadata of a session

Missing trailing colon.

doc/man/lttng-regenerate.1.txt Regenerate the metadata of a session · line 17

Quoted 4 lines
doc/man/lttng-regenerate.1.txt +1 -0
 [verse]
 *lttng* ['linkgenoptions:(GENERAL OPTIONS)'] *regenerate metadata* [option:--session='SESSION']
 
+Regenerate the statedump of a session

Missing trailing colon.

doc/man/lttng-regenerate.1.txt Regenerate the metadata of a session · line 25

Quoted 8 lines
doc/man/lttng-regenerate.1.txt +4 -0
+
+[verse]
+*lttng* ['linkgenoptions:(GENERAL OPTIONS)'] *regenerate statedump* [option:--session='SESSION']
+
 DESCRIPTION
 -----------
 The `lttng regenerate` command manages a tracing session's data regeneration
 options.

The lttng regenerate command regenerates specific data of a tracing session.

Quoted 9 lines
doc/man/lttng-regenerate.1.txt +3 -1
-As of this version, only the `metadata` command's action is available.
+As of this version, the `metadata` and `statedump` command's action are
+available.
+
 Regenerating a tracing session's metadata can be used to
 resample the offset between the system's monotonic clock and
 the wall-clock time.

doc/man/lttng-regenerate.1.txt traced before its wall time is NTP-corrected. Regenerating the tracing · line 45

Quoted 7 lines
doc/man/lttng-regenerate.1.txt +4 -0
@@ -32,12 +39,16 @@ traced before its wall time is NTP-corrected. Regenerating the tracing
 session's metadata ensures that trace viewers can accurately determine
 the events time relative to Unix Epoch.
 
+Regenerating a tracing session's statedump can be used to collect up-to-date
+statedump informations during the trace session. This is particularly useful in
+snapshot or trace-file rotation modes where the statedump information may be
+lost.

Let's replace those three last paragraphs with this:

As of this version, the metadata and statedump actions are available.

Regenerating a tracing session's metadata
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The lttng regenerate metadata action can be used to resample the offset between the system's monotonic clock and the wall-clock time.

This action is meant to be used to resample the wall-clock time following a major

correction. As such, a system booting with an incorrect wall time can be traced before its wall time is NTP-corrected. Regenerating the tracing session's metadata ensures that trace viewers can accurately determine the events time relative to Unix Epoch.

Regenerating a tracing session's state dump
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The lttng regenerate statedump action can be used to collect up-to-date state dump information during the tracing session. This is particularly useful in snapshot (see man:lttng-snapshot(1)) or trace file rotation (see man:lttng-enable-channel(1)) modes where the state dump information may be lost.

doc/man/lttng-regenerate.1.txt traced before its wall time is NTP-corrected. Regenerating the tracing · line 51

Quoted 8 lines
doc/man/lttng-regenerate.1.txt +1 -1
 include::common-cmd-options-head.txt[]
 
 
 option:-s, option:--session='SESSION'::
-    Manage the metadata generation of the tracing session named 'SESSION'
+    Manage the data regeneration of the tracing session named 'SESSION'
     instead of the current tracing session.

Regenerate the data of the tracing session named [...]

Quoted 9 lines
doc/man/lttng-regenerate.1.txt +0 -1
--

1.9.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw

Re: [PATCH lttng-tools v2 4/6] Allow regenerating the statedump of a running session

Quoted 27 lines · Julien Desfossez

The "lttng regenerate statedump" command can be used to regenerate the statedump of a running session whenever needed. This is particularly useful in snapshot and trace-file rotation modes where the original statedump may be lost.

---
 include/lttng/lttng-error.h              |  1 +
 include/lttng/lttng.h                    |  9 +++++
 src/bin/lttng-sessiond/cmd.c             | 44 +++++++++++++++++++++
 src/bin/lttng-sessiond/cmd.h             |  1 +
 src/bin/lttng-sessiond/main.c            |  6 +++
 src/bin/lttng-sessiond/ust-app.c         | 66 ++++++++++++++++++++++++++++++++
 src/bin/lttng-sessiond/ust-app.h         |  6 +++
 src/bin/lttng/commands/regenerate.c      | 19 +++++++++
 src/common/error.c                       |  1 +
 src/common/kernel-ctl/kernel-ctl.c       |  5 +++
 src/common/kernel-ctl/kernel-ctl.h       |  1 +
 src/common/sessiond-comm/sessiond-comm.h |  1 +
 src/lib/lttng-ctl/lttng-ctl.c            | 30 +++++++++++++++
 13 files changed, 190 insertions(+)
include/lttng/lttng-error.h +0 -0
index 72194ef..52ce333 100644

include/lttng/lttng-error.h enum lttng_error_code { · line 145

Quoted 4 lines
include/lttng/lttng-error.h +1 -0
@@ -142,6 +142,7 @@ enum lttng_error_code {
        LTTNG_ERR_LIVE_SESSION           = 119, /* Live session unsupported */
        LTTNG_ERR_PER_PID_SESSION        = 120, /* Per-PID sessions unsupported */
        LTTNG_ERR_KERN_CONTEXT_UNAVAILABLE = 121, /* Context unavailable on this kernel */
+       LTTNG_ERR_REGEN_STATEDUMP_FAIL   = 122, /* Failed to regenerate the statdump */

statdump -> statedump

Quoted 8 lines
include/lttng/lttng-error.h +0 -0
        /* MUST be last element */
        LTTNG_ERR_NR,                           /* Last element */
include/lttng/lttng.h +0 -0
index 09aa969..b81a01c 100644

include/lttng/lttng.h extern int lttng_metadata_regenerate(const char *session_name); · line 179

Quoted 7 lines
include/lttng/lttng.h +4 -0
@@ -173,6 +173,15 @@ extern int lttng_metadata_regenerate(const char *session_name);
  */
 extern int lttng_regenerate_metadata(const char *session_name);
 
+/*
+ * Trigger the regeneration of the statedump for a session. The new statedump
+ * information is appended to the currently active trace, the session needs to
+ * be started.

needs to be active

Quoted 29 lines
include/lttng/lttng.h +5 -0
+ *
+ * Return 0 on success, a negative LTTng error code on error.
+ */
+extern int lttng_regenerate_statedump(const char *session_name);
+
 #ifdef __cplusplus
 }
 #endif
src/bin/lttng-sessiond/cmd.c +13 -0
index bd63389..480333d 100644
@@ -3540,6 +3540,50 @@ end:
 }
 
 /*
+ * Command LTTNG_REGENERATE_STATEDUMP from the lttng-ctl library.
+ *
+ * Ask the tracer to regenerate a new statedump.
+ *
+ * Return 0 on success or else a LTTNG_ERR code.
+ */
+int cmd_regenerate_statedump(struct ltt_session *session)
+{
+       int ret;
+
+       assert(session);
+
+       if (!session->active) {

src/bin/lttng-sessiond/cmd.c end: · line 3565

Quoted 10 lines
src/bin/lttng-sessiond/cmd.c +10 -0
+               ret = LTTNG_ERR_SESSION_NOT_STARTED;
+               goto end;
+       }
+       ret = 0;
+
+       if (session->kernel_session) {
+               ret = kernctl_session_regenerate_statedump(
+                               session->kernel_session->fd);
+               if (ret < 0) {
+                       ret = LTTNG_ERR_REGEN_STATEDUMP_FAIL;

Does kernctl_session_regenerate_statedump() return a more precise error code? I see that this can fail if the session is not active (handled before). Are there other reasons?

src/bin/lttng-sessiond/cmd.c end: · line 3572

Quoted 7 lines
src/bin/lttng-sessiond/cmd.c +7 -0
+                       ERR("Failed to regenerate the kernel statedump");
+                       goto end;
+               }
+       }
+
+       if (session->ust_session) {
+               ret = ust_app_regenerate_statedump_all(session->ust_session);

Same applies here.

Quoted 72 lines
src/bin/lttng-sessiond/cmd.c +14 -0
+               if (ret < 0) {
+                       ret = LTTNG_ERR_REGEN_STATEDUMP_FAIL;
+                       ERR("Failed to regenerate the UST statedump");
+                       goto end;
+               }
+       }
+       DBG("Cmd regenerate statedump for session %s", session->name);
+       ret = LTTNG_OK;
+
+end:
+       return ret;
+}
+
+/*
  * Send relayd sockets from snapshot output to consumer. Ignore request if the
  * snapshot output is *not* set with a remote destination.
  *
src/bin/lttng-sessiond/cmd.h +1 -0
index 320d717..975a7f1 100644
@@ -111,5 +111,6 @@ int cmd_snapshot_record(struct ltt_session *session,
 int cmd_set_session_shm_path(struct ltt_session *session,
                const char *shm_path);
 int cmd_regenerate_metadata(struct ltt_session *session);
+int cmd_regenerate_statedump(struct ltt_session *session);
 
 #endif /* CMD_H */
src/bin/lttng-sessiond/main.c +6 -0
index 3623e5d..8309c3f 100644
@@ -3004,6 +3004,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock,
        case LTTNG_SAVE_SESSION:
        case LTTNG_SET_SESSION_SHM_PATH:
        case LTTNG_REGENERATE_METADATA:
+       case LTTNG_REGENERATE_STATEDUMP:
                need_domain = 0;
                break;
        default:
@@ -4119,6 +4120,11 @@ error_add_context:
                ret = cmd_regenerate_metadata(cmd_ctx->session);
                break;
        }
+       case LTTNG_REGENERATE_STATEDUMP:
+       {
+               ret = cmd_regenerate_statedump(cmd_ctx->session);
+               break;
+       }
        default:
                ret = LTTNG_ERR_UND;
                break;
src/bin/lttng-sessiond/ust-app.c +12 -0
index f30df20..3474082 100644
@@ -6148,3 +6148,69 @@ end:
        rcu_read_unlock();
        return ret;
 }
+
+static
+int ust_app_regenerate_statedump(struct ltt_ust_session *usess,
+               struct ust_app *app)
+{
+       int ret = 0;
+       struct ust_app_session *ua_sess;
+
+       DBG("Regenerating the metadata for ust app pid %d", app->pid);
+
+       rcu_read_lock();
+

src/bin/lttng-sessiond/ust-app.c end: · line 6172

Quoted 10 lines
src/bin/lttng-sessiond/ust-app.c +10 -0
+       ua_sess = lookup_session_by_app(usess, app);
+       if (ua_sess == NULL) {
+               /* The session is in teardown process. Ignore and continue. */
+               goto end;
+       }
+
+       pthread_mutex_lock(&ua_sess->lock);
+
+       if (ua_sess->deleted) {
+               pthread_mutex_unlock(&ua_sess->lock);

Remove this pthread_mutex_unlock() and goto end_unlock;

src/bin/lttng-sessiond/ust-app.c end: · line 6178

Quoted 6 lines
src/bin/lttng-sessiond/ust-app.c +6 -0
+               goto end;
+       }
+
+       pthread_mutex_lock(&app->sock_lock);
+       ret = ustctl_regenerate_statedump(app->sock, ua_sess->handle);
+       pthread_mutex_unlock(&app->sock_lock);

Add
end_unlock:

Quoted 19 lines
src/bin/lttng-sessiond/ust-app.c +19 -0
+       pthread_mutex_unlock(&ua_sess->lock);
+
+end:
+       rcu_read_unlock();
+       health_code_update();
+       return ret;
+}
+
+/*
+ * Regenerate the statedump for each app in the session.
+ */
+int ust_app_regenerate_statedump_all(struct ltt_ust_session *usess)
+{
+       int ret = 0;
+       struct lttng_ht_iter iter;
+       struct ust_app *app;
+
+       DBG("Regenerating the metadata for all UST apps");
+

src/bin/lttng-sessiond/ust-app.c end: · line 6207

Quoted 10 lines
src/bin/lttng-sessiond/ust-app.c +10 -0
+       rcu_read_lock();
+
+       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
+               if (!app->compatible) {
+                       continue;
+               }
+
+               ret = ust_app_regenerate_statedump(usess, app);
+               if (ret < 0) {
+                       /* Continue to next apps even on error */

to next app

src/bin/lttng-sessiond/ust-app.c end: · line 6216

Quoted 9 lines
src/bin/lttng-sessiond/ust-app.c +9 -0
+                       continue;
+               }
+       }
+
+       rcu_read_unlock();
+
+       return 0;
+}
+

Remove blank line here.

Quoted 49 lines
src/bin/lttng-sessiond/ust-app.h +6 -0
index d02f353..8369d14 100644
@@ -352,6 +352,7 @@ int ust_app_pid_get_channel_runtime_stats(struct ltt_ust_session *usess,
                struct ltt_ust_channel *uchan,
                struct consumer_output *consumer,
                int overwrite, uint64_t *discarded, uint64_t *lost);
+int ust_app_regenerate_statedump_all(struct ltt_ust_session *usess);
 
 static inline
 int ust_app_supported(void)
@@ -583,6 +584,11 @@ int ust_app_pid_get_channel_runtime_stats(struct ltt_ust_session *usess,
 {
        return 0;
 }
+static inline
+int ust_app_regenerate_metadata_all(struct ltt_ust_session *usess)
+{
+       return 0;
+}
 
 #endif /* HAVE_LIBLTTNG_UST_CTL */
 
src/bin/lttng/commands/regenerate.c +3 -0
index c64d8fe..f111d06 100644
@@ -32,6 +32,7 @@ static char *opt_session_name;
 static char *session_name = NULL;
 
 static int regenerate_metadata(int argc, const char **argv);
+static int regenerate_statedump(int argc, const char **argv);
 
 enum {
        OPT_HELP = 1,
@@ -52,6 +53,7 @@ static struct poptOption long_options[] = {
 
 static struct cmd_struct actions[] = {
        { "metadata", regenerate_metadata },
+       { "statedump", regenerate_statedump },
        { NULL, NULL }  /* Array closure */
 };
 
@@ -88,6 +90,23 @@ end:
        return ret;
 }
 
+static int regenerate_statedump(int argc, const char **argv)

src/bin/lttng/commands/regenerate.c end: · line 103

Quoted 10 lines
src/bin/lttng/commands/regenerate.c +10 -0
+{
+       int ret;
+
+       if (argc > 1) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
+       ret = lttng_regenerate_statedump(session_name);
+       if (ret == 0) {
+               MSG("Statedump successfully regenerated for session %s", session_name);

Please use "State dump" in two words in human-readable messages.

Quoted 14 lines
src/bin/lttng/commands/regenerate.c +6 -0
+       }
+
+end:
+       return ret;
+}
+
 static int handle_command(const char **argv)
 {
        struct cmd_struct *cmd;
src/common/error.c +0 -0
index bc42577..6730e14 100644

src/common/error.c static const char *error_string_array[] = { · line 186

Quoted 4 lines
src/common/error.c +1 -0
@@ -183,6 +183,7 @@ static const char *error_string_array[] = {
        [ ERROR_INDEX(LTTNG_ERR_LIVE_SESSION) ] = "Live sessions are not supported",
        [ ERROR_INDEX(LTTNG_ERR_PER_PID_SESSION) ] = "Per-PID tracing sessions are not supported",
        [ ERROR_INDEX(LTTNG_ERR_KERN_CONTEXT_UNAVAILABLE) ] = "Context unavailable on this kernel",
+       [ ERROR_INDEX(LTTNG_ERR_REGEN_STATEDUMP_FAIL) ] = "Statedump regeneration failed",

"State dump"

Quoted 87 lines
src/common/error.c +0 -0
        /* Last element */
        [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"
src/common/kernel-ctl/kernel-ctl.c +5 -0
index e1de0e7..1c2ab61 100644
@@ -230,6 +230,11 @@ int kernctl_session_regenerate_metadata(int fd)
        return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_METADATA_REGEN);
 }
 
+int kernctl_session_regenerate_statedump(int fd)
+{
+       return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_STATEDUMP);
+}
+
 int kernctl_create_stream(int fd)
 {
        return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_STREAM,
src/common/kernel-ctl/kernel-ctl.h +1 -0
index f30e6f3..7c25a17 100644
@@ -66,6 +66,7 @@ int kernctl_untrack_pid(int fd, int pid);
 int kernctl_list_tracker_pids(int fd);
 
 int kernctl_session_regenerate_metadata(int fd);
+int kernctl_session_regenerate_statedump(int fd);
 
 /* Buffer operations */
 
src/common/sessiond-comm/sessiond-comm.h +1 -0
index 29740c1..628b1ea 100644
@@ -95,6 +95,7 @@ enum lttcomm_sessiond_command {
        LTTNG_LIST_TRACKER_PIDS             = 34,
        LTTNG_SET_SESSION_SHM_PATH          = 40,
        LTTNG_REGENERATE_METADATA           = 41,
+       LTTNG_REGENERATE_STATEDUMP          = 42,
 };
 
 enum lttcomm_relayd_command {
src/lib/lttng-ctl/lttng-ctl.c +30 -1
index 8c78e1c..bcd59f0 100644
@@ -2419,6 +2419,36 @@ int lttng_metadata_regenerate(const char *session_name)
 }
 
 /*
+ * Regenerate the statedump of a session.
+ * Return 0 on success, a negative error code on error.
+ */
+int lttng_regenerate_statedump(const char *session_name)
+{
+       int ret;
+       struct lttcomm_session_msg lsm;
+
+       if (!session_name) {
+               ret = -LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       memset(&lsm, 0, sizeof(lsm));
+       lsm.cmd_type = LTTNG_REGENERATE_STATEDUMP;
+
+       lttng_ctl_copy_string(lsm.session.name, session_name,
+                       sizeof(lsm.session.name));
+
+       ret = lttng_ctl_ask_sessiond(&lsm, NULL);
+       if (ret < 0) {
+               goto end;
+       }
+
+       ret = 0;
+end:
+       return ret;
+}
+
+/*
  * lib constructor.
  */
 static void __attribute__((constructor)) init(void)
--

1.9.1

Signature · 7 lines
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev