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;
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
*
* Copyright 2011 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
*
- * LTTng trace/channel/event context management.
+ * LTTng UST trace/channel/event context management.
*
* Dual LGPL v2.1/GPL v2 license.
*/
#include <ust/lttng-events.h>
+#include <ust/lttng-tracer.h>
#include <ust/core.h>
#include <string.h>
-#include <ust/usterr-signal-safe.h>
+#include <assert.h>
+
+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.
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));
}
--- /dev/null
+/*
+ * (C) Copyright 2009-2011 -
+ * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng UST pthread_id context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <pthread.h>
+#include <ust/lttng-events.h>
+#include <ust/lttng-tracer.h>
+#include <ust/ringbuffer-config.h>
+
+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;
+}