From: Mathieu Desnoyers Date: Wed, 28 Sep 2011 00:46:04 +0000 (-0400) Subject: Add vpid context X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c1ef86f0812ff62354175f4c7136930814b8f850;p=ust.git Add vpid context Signed-off-by: Mathieu Desnoyers --- diff --git a/include/ust/lttng-events.h b/include/ust/lttng-events.h index 6bb4e8c..0439ea7 100644 --- a/include/ust/lttng-events.h +++ b/include/ust/lttng-events.h @@ -321,7 +321,9 @@ 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_vpid_to_ctx(struct lttng_ctx **ctx); int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx); void lttng_context_vtid_reset(void); +void lttng_context_vpid_reset(void); #endif /* _UST_LTTNG_EVENTS_H */ diff --git a/include/ust/lttng-ust-abi.h b/include/ust/lttng-ust-abi.h index 7146579..c967fb1 100644 --- a/include/ust/lttng-ust-abi.h +++ b/include/ust/lttng-ust-abi.h @@ -67,7 +67,8 @@ struct lttng_ust_event { enum lttng_ust_context_type { LTTNG_UST_CONTEXT_VTID = 0, - LTTNG_UST_CONTEXT_PTHREAD_ID = 1, + LTTNG_UST_CONTEXT_VPID = 1, + LTTNG_UST_CONTEXT_PTHREAD_ID = 2, }; struct lttng_ust_context { diff --git a/libust/Makefile.am b/libust/Makefile.am index 9857dd2..cb00e17 100644 --- a/libust/Makefile.am +++ b/libust/Makefile.am @@ -20,6 +20,7 @@ libust_la_SOURCES = \ probes/lttng-probe-ust.c \ probes/lttng-probe-ust.h \ lttng-context-vtid.c \ + lttng-context-vpid.c \ lttng-context-pthread-id.c \ ltt-context.c diff --git a/libust/lttng-context-vpid.c b/libust/lttng-context-vpid.c new file mode 100644 index 0000000..71395c9 --- /dev/null +++ b/libust/lttng-context-vpid.c @@ -0,0 +1,95 @@ +/* + * (C) Copyright 2009-2011 - + * Mathieu Desnoyers + * + * LTTng UST vpid context. + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#include +#include +#include +#include +#include + +#ifdef __linux__ +static inline +pid_t wrapper_getpid(void) +{ + return getpid(); +} + +void lttng_context_vpid_reset(void) +{ +} +#else +/* + * We cache the result to ensure we don't trigger a system call for + * each event. + */ +static pid_t cached_vpid; + +static inline +pid_t wrapper_getpid(void) +{ + if (unlikely(!cached_vpid)) + cached_vpid = getpid(); + return cached_vpid; +} + +/* + * Upon fork or clone, the PID assigned to our thread is not the same as + * we kept in cache. + */ +void lttng_context_vpid_reset(void) +{ + cached_vpid = 0; +} +#endif + +static +size_t vpid_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 vpid_record(struct lttng_ctx_field *field, + struct lib_ring_buffer_ctx *ctx, + struct ltt_channel *chan) +{ + pid_t pid; + + pid = wrapper_getpid(); + lib_ring_buffer_align_ctx(ctx, lttng_alignof(pid)); + chan->ops->event_write(ctx, &pid, sizeof(pid)); +} + +int lttng_add_vpid_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, "vpid")) { + lttng_remove_context_field(ctx, field); + return -EEXIST; + } + field->event_field.name = "vpid"; + 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 = vpid_get_size; + field->record = vpid_record; + return 0; +} diff --git a/libust/lttng-ust-abi.c b/libust/lttng-ust-abi.c index 35c93c9..e125ac6 100644 --- a/libust/lttng-ust-abi.c +++ b/libust/lttng-ust-abi.c @@ -276,6 +276,8 @@ long lttng_abi_add_context(int objd, return lttng_add_pthread_id_to_ctx(ctx); case LTTNG_UST_CONTEXT_VTID: return lttng_add_vtid_to_ctx(ctx); + case LTTNG_UST_CONTEXT_VPID: + return lttng_add_vpid_to_ctx(ctx); default: return -EINVAL; }