From 9e7e489272e646b39c51e3074de800e928bb5cec Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 25 May 2011 17:33:56 -0400 Subject: [PATCH] Add PID context Signed-off-by: Mathieu Desnoyers --- ltt-context.c | 6 ++-- ltt-events.h | 3 ++ probes/Makefile | 2 ++ probes/lttng-context-pid.c | 53 ++++++++++++++++++++++++++++++++++++ probes/lttng-ftrace.c | 4 +-- probes/lttng-kprobes.c | 2 +- probes/lttng-perf-counters.c | 5 ++-- probes/lttng.h | 3 -- 8 files changed, 67 insertions(+), 11 deletions(-) create mode 100644 probes/lttng-context-pid.c diff --git a/ltt-context.c b/ltt-context.c index cc9633ac..89e54bf8 100644 --- a/ltt-context.c +++ b/ltt-context.c @@ -47,8 +47,10 @@ void lttng_destroy_context(struct lttng_ctx *ctx) { int i; - for (i = 0; i < ctx->nr_fields; i++) - ctx->fields[i].destroy(&ctx->fields[i]); + for (i = 0; i < ctx->nr_fields; i++) { + if (ctx->fields[i].destroy) + ctx->fields[i].destroy(&ctx->fields[i]); + } kfree(ctx->fields); kfree(ctx); } diff --git a/ltt-events.h b/ltt-events.h index bacef0a8..1a5b5d5c 100644 --- a/ltt-events.h +++ b/ltt-events.h @@ -14,6 +14,9 @@ #include #include "ltt-debugfs-abi.h" +#undef is_signed_type +#define is_signed_type(type) (((type)(-1)) < 0) + struct ltt_channel; struct ltt_session; struct lib_ring_buffer_ctx; diff --git a/probes/Makefile b/probes/Makefile index 554e6ffa..78c0c699 100644 --- a/probes/Makefile +++ b/probes/Makefile @@ -28,6 +28,8 @@ ifneq ($(CONFIG_PERF_EVENTS),) obj-m += lttng-perf-counters.o endif +obj-m += lttng-context-pid.o + endif else diff --git a/probes/lttng-context-pid.c b/probes/lttng-context-pid.c new file mode 100644 index 00000000..669e593f --- /dev/null +++ b/probes/lttng-context-pid.c @@ -0,0 +1,53 @@ +/* + * (C) Copyright 2009-2011 - + * Mathieu Desnoyers + * + * LTTng PID context. + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#include +#include +#include +#include "../ltt-events.h" +#include "../wrapper/ringbuffer/frontend_types.h" +#include "../wrapper/vmalloc.h" +#include "../ltt-tracer.h" + +static +void pid_record(struct lttng_ctx_field *field, + struct lib_ring_buffer_ctx *ctx, + struct ltt_channel *chan) +{ + pid_t pid; + + pid = current->pid; + lib_ring_buffer_align_ctx(ctx, ltt_alignof(pid)); + chan->ops->event_write(ctx, &pid, sizeof(pid)); +} + +int lttng_add_pid_to_ctx(struct lttng_ctx **ctx) +{ + struct lttng_ctx_field *field; + int ret; + + field = lttng_append_context(ctx); + if (!field) + return ret; + field->name = "pid"; + field->type.atype = atype_integer; + field->type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT; + field->type.u.basic.integer.alignment = ltt_alignof(pid_t) * CHAR_BIT; + field->type.u.basic.integer.signedness = is_signed_type(pid_t); + field->type.u.basic.integer.reverse_byte_order = 0; + field->type.u.basic.integer.base = 10; + field->type.u.basic.integer.encoding = lttng_encode_none; + field->callback = pid_record; + wrapper_vmalloc_sync_all(); + return 0; +} + +MODULE_LICENSE("GPL and additional rights"); +MODULE_AUTHOR("Mathieu Desnoyers"); +MODULE_DESCRIPTION("Linux Trace Toolkit Perf Support"); diff --git a/probes/lttng-ftrace.c b/probes/lttng-ftrace.c index ec086902..c18a4702 100644 --- a/probes/lttng-ftrace.c +++ b/probes/lttng-ftrace.c @@ -78,7 +78,7 @@ int lttng_create_ftrace_event(const char *name, struct ltt_event *event) fields[0].type.atype = atype_integer; fields[0].type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT; fields[0].type.u.basic.integer.alignment = ltt_alignof(unsigned long) * CHAR_BIT; - fields[0].type.u.basic.integer.signedness = 0; + fields[0].type.u.basic.integer.signedness = is_signed_type(unsigned long); fields[0].type.u.basic.integer.reverse_byte_order = 0; fields[0].type.u.basic.integer.base = 16; fields[0].type.u.basic.integer.encoding = lttng_encode_none; @@ -87,7 +87,7 @@ int lttng_create_ftrace_event(const char *name, struct ltt_event *event) fields[1].type.atype = atype_integer; fields[1].type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT; fields[1].type.u.basic.integer.alignment = ltt_alignof(unsigned long) * CHAR_BIT; - fields[1].type.u.basic.integer.signedness = 0; + fields[1].type.u.basic.integer.signedness = is_signed_type(unsigned long); fields[1].type.u.basic.integer.reverse_byte_order = 0; fields[1].type.u.basic.integer.base = 16; fields[1].type.u.basic.integer.encoding = lttng_encode_none; diff --git a/probes/lttng-kprobes.c b/probes/lttng-kprobes.c index 9dd3569b..481807de 100644 --- a/probes/lttng-kprobes.c +++ b/probes/lttng-kprobes.c @@ -67,7 +67,7 @@ int lttng_create_kprobe_event(const char *name, struct ltt_event *event) field->type.atype = atype_integer; field->type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT; field->type.u.basic.integer.alignment = ltt_alignof(unsigned long) * CHAR_BIT; - field->type.u.basic.integer.signedness = 0; + field->type.u.basic.integer.signedness = is_signed_type(unsigned long); field->type.u.basic.integer.reverse_byte_order = 0; field->type.u.basic.integer.base = 16; field->type.u.basic.integer.encoding = lttng_encode_none; diff --git a/probes/lttng-perf-counters.c b/probes/lttng-perf-counters.c index c6620713..740c1d94 100644 --- a/probes/lttng-perf-counters.c +++ b/probes/lttng-perf-counters.c @@ -34,8 +34,7 @@ void perf_counter_record(struct lttng_ctx_field *field, event = field->u.perf_counter.e[ctx->cpu]; event->pmu->read(event); value = local64_read(&event->count); - lib_ring_buffer_align_ctx(ctx, - ltt_alignof(field->type.u.basic.integer.alignment / CHAR_BIT)); + lib_ring_buffer_align_ctx(ctx, ltt_alignof(value)); chan->ops->event_write(ctx, &value, sizeof(value)); } @@ -109,7 +108,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, field->type.atype = atype_integer; field->type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT; field->type.u.basic.integer.alignment = ltt_alignof(unsigned long) * CHAR_BIT; - field->type.u.basic.integer.signedness = 0; + field->type.u.basic.integer.signedness = is_signed_type(unsigned long); field->type.u.basic.integer.reverse_byte_order = 0; field->type.u.basic.integer.base = 10; field->type.u.basic.integer.encoding = lttng_encode_none; diff --git a/probes/lttng.h b/probes/lttng.h index d09ecb11..f87017ba 100644 --- a/probes/lttng.h +++ b/probes/lttng.h @@ -1,9 +1,6 @@ #ifndef _LTTNG_PROBES_LTTNG_H #define _LTTNG_PROBES_LTTNG_H -#undef is_signed_type -#define is_signed_type(type) (((type)(-1)) < 0) - #undef PARAMS #define PARAMS(args...) args -- 2.34.1