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

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Thu Jun 30 18:27:18 UTC 2016


----- On Jun 30, 2016, at 12:36 PM, Julien Desfossez jdesfossez at efficios.com wrote:

> 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.
> 
> Signed-off-by: Julien Desfossez <jdesfossez at efficios.com>
> ---
> 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         | 62 ++++++++++++++++++++++++++++++++
> 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            | 31 ++++++++++++++++
> 13 files changed, 187 insertions(+)
> 
> diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h
> index 72194ef..52ce333 100644
> --- a/include/lttng/lttng-error.h
> +++ b/include/lttng/lttng-error.h
> @@ -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 */
> diff --git a/include/lttng/lttng.h b/include/lttng/lttng.h
> index ed03bdb..7f9fa9d 100644
> --- a/include/lttng/lttng.h
> +++ b/include/lttng/lttng.h
> @@ -172,6 +172,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
> diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c
> index bd63389..480333d 100644
> --- a/src/bin/lttng-sessiond/cmd.c
> +++ b/src/bin/lttng-sessiond/cmd.c
> @@ -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) {
> +		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;
> +			ERR("Failed to regenerate the kernel statedump");
> +			goto end;
> +		}
> +	}
> +
> +	if (session->ust_session) {
> +		ret = ust_app_regenerate_statedump_all(session->ust_session);
> +		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.
>  *
> diff --git a/src/bin/lttng-sessiond/cmd.h b/src/bin/lttng-sessiond/cmd.h
> index 320d717..975a7f1 100644
> --- a/src/bin/lttng-sessiond/cmd.h
> +++ b/src/bin/lttng-sessiond/cmd.h
> @@ -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 */
> diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c
> index 3623e5d..8309c3f 100644
> --- a/src/bin/lttng-sessiond/main.c
> +++ b/src/bin/lttng-sessiond/main.c
> @@ -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;
> diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c
> index f30df20..37263e6 100644
> --- a/src/bin/lttng-sessiond/ust-app.c
> +++ b/src/bin/lttng-sessiond/ust-app.c
> @@ -6148,3 +6148,65 @@ 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();
> +

missing:

        if (!app->compatible) {
                goto end_not_compatible;
        }

> +	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);
> +		goto end;
> +	}
> +
> +	pthread_mutex_lock(&app->sock_lock);
> +	ret = ustctl_regenerate_statedump(app->sock, ua_sess->handle);
> +	pthread_mutex_unlock(&app->sock_lock);
> +	pthread_mutex_unlock(&ua_sess->lock);
> +
> +end:
> +	rcu_read_unlock();
> +	health_code_update();
> +	return ret;
> +}
> +

[...]

> /*
> + * 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;
> +}
> +

Remove extra whiteline.

Thanks,

Mathieu

> +
> +/*
>  * lib constructor.
>  */
> static void __attribute__((constructor)) init(void)
> --
> 1.9.1

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list