From: Jérémie Galarneau Date: Wed, 27 Jan 2016 03:48:21 +0000 (-0500) Subject: Add app context support to ust-ctl protocol X-Git-Tag: v2.8.0-rc1~42 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=53f0df512fb13a5c1b9609a001f9afd5114f2991;p=lttng-ust.git Add app context support to ust-ctl protocol Signed-off-by: Jérémie Galarneau Signed-off-by: Mathieu Desnoyers --- diff --git a/include/lttng/ust-abi.h b/include/lttng/ust-abi.h index 126e6124..8cae00e6 100644 --- a/include/lttng/ust-abi.h +++ b/include/lttng/ust-abi.h @@ -140,6 +140,7 @@ enum lttng_ust_context_type { LTTNG_UST_CONTEXT_IP = 4, LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER = 5, LTTNG_UST_CONTEXT_CPU_ID = 6, + LTTNG_UST_CONTEXT_APP_CONTEXT = 7, }; struct lttng_ust_perf_counter_ctx { @@ -156,6 +157,11 @@ struct lttng_ust_context { union { struct lttng_ust_perf_counter_ctx perf_counter; + struct { + /* Includes trailing '\0'. */ + uint32_t provider_name_len; + uint32_t ctx_name_len; + } app_ctx; char padding[LTTNG_UST_CONTEXT_PADDING2]; } u; } LTTNG_PACKED; diff --git a/include/lttng/ust-ctl.h b/include/lttng/ust-ctl.h index 916eb280..d3c50c5c 100644 --- a/include/lttng/ust-ctl.h +++ b/include/lttng/ust-ctl.h @@ -59,6 +59,17 @@ struct ustctl_consumer_channel_attr { * API used by sessiond. */ +struct lttng_ust_context_attr { + enum lttng_ust_context_type ctx; + union { + struct lttng_ust_perf_counter_ctx perf_counter; + struct { + char *provider_name; + char *ctx_name; + } app_ctx; + } u; +}; + /* * Error values: all the following functions return: * >= 0: Success (LTTNG_UST_OK) @@ -69,7 +80,7 @@ int ustctl_create_session(int sock); int ustctl_create_event(int sock, struct lttng_ust_event *ev, struct lttng_ust_object_data *channel_data, struct lttng_ust_object_data **event_data); -int ustctl_add_context(int sock, struct lttng_ust_context *ctx, +int ustctl_add_context(int sock, struct lttng_ust_context_attr *ctx, struct lttng_ust_object_data *obj_data, struct lttng_ust_object_data **context_data); int ustctl_set_filter(int sock, struct lttng_ust_filter_bytecode *bytecode, diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c index bbf47381..10fb9c49 100644 --- a/liblttng-ust-ctl/ustctl.c +++ b/liblttng-ust-ctl/ustctl.c @@ -212,34 +212,86 @@ int ustctl_create_event(int sock, struct lttng_ust_event *ev, return 0; } -int ustctl_add_context(int sock, struct lttng_ust_context *ctx, +int ustctl_add_context(int sock, struct lttng_ust_context_attr *ctx, struct lttng_ust_object_data *obj_data, struct lttng_ust_object_data **_context_data) { struct ustcomm_ust_msg lum; struct ustcomm_ust_reply lur; - struct lttng_ust_object_data *context_data; + struct lttng_ust_object_data *context_data = NULL; + char *buf = NULL; + size_t len; int ret; - if (!obj_data || !_context_data) - return -EINVAL; + if (!obj_data || !_context_data) { + ret = -EINVAL; + goto end; + } context_data = zmalloc(sizeof(*context_data)); - if (!context_data) - return -ENOMEM; + if (!context_data) { + ret = -ENOMEM; + goto end; + } context_data->type = LTTNG_UST_OBJECT_TYPE_CONTEXT; memset(&lum, 0, sizeof(lum)); lum.handle = obj_data->handle; lum.cmd = LTTNG_UST_CONTEXT; - lum.u.context = *ctx; - ret = ustcomm_send_app_cmd(sock, &lum, &lur); - if (ret) { - free(context_data); - return ret; + + lum.u.context.ctx = ctx->ctx; + switch (ctx->ctx) { + case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER: + lum.u.context.u.perf_counter = ctx->u.perf_counter; + break; + case LTTNG_UST_CONTEXT_APP_CONTEXT: + { + size_t provider_name_len = strlen( + ctx->u.app_ctx.provider_name) + 1; + size_t ctx_name_len = strlen(ctx->u.app_ctx.ctx_name) + 1; + + lum.u.context.u.app_ctx.provider_name_len = provider_name_len; + lum.u.context.u.app_ctx.ctx_name_len = ctx_name_len; + + len = provider_name_len + ctx_name_len; + buf = zmalloc(len); + if (!buf) { + ret = -ENOMEM; + goto end; + } + memcpy(buf, ctx->u.app_ctx.provider_name, + provider_name_len); + memcpy(buf + provider_name_len, ctx->u.app_ctx.ctx_name, + ctx_name_len); + break; + } + default: + break; + } + ret = ustcomm_send_app_msg(sock, &lum); + if (ret) + goto end; + if (buf) { + /* send var len ctx_name */ + ret = ustcomm_send_unix_sock(sock, buf, len); + if (ret < 0) { + goto end; + } + if (ret != len) { + ret = -EINVAL; + goto end; + } + } + ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd); + if (ret < 0) { + goto end; } context_data->handle = -1; DBG("Context created successfully"); *_context_data = context_data; + context_data = NULL; +end: + free(context_data); + free(buf); return ret; }