From: Mathieu Desnoyers Date: Sun, 25 Sep 2011 04:31:46 +0000 (-0400) Subject: Add pthread id context X-Git-Tag: v1.9.1~185 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=8173ec7c273a8f083f35bbcd850718a4e6a1f253;p=lttng-ust.git Add pthread id context Signed-off-by: Mathieu Desnoyers --- diff --git a/include/ust/lttng-events.h b/include/ust/lttng-events.h index ea7b87e6..a7726f09 100644 --- a/include/ust/lttng-events.h +++ b/include/ust/lttng-events.h @@ -317,11 +317,12 @@ const struct lttng_event_desc *ltt_event_get(const char *name); void ltt_event_put(const struct lttng_event_desc *desc); int ltt_probes_init(void); void ltt_probes_exit(void); -struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx); -void lttng_remove_context_field(struct lttng_ctx **ctx, +int lttng_find_context(struct lttng_ctx *ctx, const char *name); +struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p); +void lttng_remove_context_field(struct lttng_ctx **ctx_p, struct lttng_ctx_field *field); void lttng_destroy_context(struct lttng_ctx *ctx); -int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx); +int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx); //extern const struct file_operations lttng_tracepoint_list_fops; diff --git a/libust/Makefile.am b/libust/Makefile.am index 0aba5c53..66837f5a 100644 --- a/libust/Makefile.am +++ b/libust/Makefile.am @@ -13,13 +13,14 @@ libust_la_SOURCES = \ ltt-ring-buffer-metadata-client.h \ ltt-ring-buffer-metadata-client.c \ ltt-events.c \ - ltt-context.c \ ltt-probes.c \ lttng-ust-abi.c \ lttng-ust-comm.c \ ust-core.c \ probes/lttng-probe-ust.c \ - probes/lttng-probe-ust.h + probes/lttng-probe-ust.h \ + lttng-context-pthread-id.c \ + ltt-context.c libust_la_LDFLAGS = -no-undefined -version-info 0:0:0 diff --git a/libust/ltt-context.c b/libust/ltt-context.c index 83aa2975..7f8351ec 100644 --- a/libust/ltt-context.c +++ b/libust/ltt-context.c @@ -3,15 +3,30 @@ * * Copyright 2011 (c) - Mathieu Desnoyers * - * LTTng trace/channel/event context management. + * LTTng UST trace/channel/event context management. * * Dual LGPL v2.1/GPL v2 license. */ #include +#include #include #include -#include +#include + +int lttng_find_context(struct lttng_ctx *ctx, const char *name) +{ + unsigned int i; + + for (i = 0; i < ctx->nr_fields; i++) { + /* Skip allocated (but non-initialized) contexts */ + if (!ctx->fields[i].event_field.name) + continue; + if (!strcmp(ctx->fields[i].event_field.name, name)) + return 1; + } + return 0; +} /* * Note: as we append context information, the pointer location may change. @@ -54,7 +69,7 @@ void lttng_remove_context_field(struct lttng_ctx **ctx_p, ctx = *ctx_p; ctx->nr_fields--; - WARN_ON_ONCE(&ctx->fields[ctx->nr_fields] != field); + assert(&ctx->fields[ctx->nr_fields] == field); memset(&ctx->fields[ctx->nr_fields], 0, sizeof(struct lttng_ctx_field)); } diff --git a/libust/lttng-context-pthread-id.c b/libust/lttng-context-pthread-id.c new file mode 100644 index 00000000..f65968bf --- /dev/null +++ b/libust/lttng-context-pthread-id.c @@ -0,0 +1,59 @@ +/* + * (C) Copyright 2009-2011 - + * Mathieu Desnoyers + * + * LTTng UST pthread_id context. + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#include +#include +#include +#include + +static +size_t pthread_id_get_size(size_t offset) +{ + size_t size = 0; + + size += lib_ring_buffer_align(offset, lttng_alignof(pid_t)); + size += sizeof(pid_t); + return size; +} + +static +void pthread_id_record(struct lttng_ctx_field *field, + struct lib_ring_buffer_ctx *ctx, + struct ltt_channel *chan) +{ + unsigned long pthread_id; + + pthread_id = (unsigned long) pthread_self(); + lib_ring_buffer_align_ctx(ctx, lttng_alignof(pthread_id)); + chan->ops->event_write(ctx, &pthread_id, sizeof(pthread_id)); +} + +int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx) +{ + struct lttng_ctx_field *field; + + field = lttng_append_context(ctx); + if (!field) + return -ENOMEM; + if (lttng_find_context(*ctx, "pthread_id")) { + lttng_remove_context_field(ctx, field); + return -EEXIST; + } + field->event_field.name = "pthread_id"; + field->event_field.type.atype = atype_integer; + field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; + field->event_field.type.u.basic.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; + field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(pid_t); + field->event_field.type.u.basic.integer.reverse_byte_order = 0; + field->event_field.type.u.basic.integer.base = 10; + field->event_field.type.u.basic.integer.encoding = lttng_encode_none; + field->get_size = pthread_id_get_size; + field->record = pthread_id_record; + return 0; +}