-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lttng: dynamically selectable context information
Events can be augmented with context information. This is dynamically configurable from the command line. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
- Loading branch information
Mathieu Desnoyers
authored and
Greg Kroah-Hartman
committed
Nov 29, 2011
1 parent
ccc7340
commit 6c19da3
Showing
11 changed files
with
1,027 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* ltt-context.c | ||
* | ||
* Copyright 2011 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | ||
* | ||
* LTTng trace/channel/event context management. | ||
* | ||
* Dual LGPL v2.1/GPL v2 license. | ||
*/ | ||
|
||
#include <linux/module.h> | ||
#include <linux/list.h> | ||
#include <linux/mutex.h> | ||
#include <linux/slab.h> | ||
#include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */ | ||
#include "ltt-events.h" | ||
#include "ltt-tracer.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; | ||
} | ||
EXPORT_SYMBOL_GPL(lttng_find_context); | ||
|
||
/* | ||
* Note: as we append context information, the pointer location may change. | ||
*/ | ||
struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p) | ||
{ | ||
struct lttng_ctx_field *field; | ||
struct lttng_ctx *ctx; | ||
|
||
if (!*ctx_p) { | ||
*ctx_p = kzalloc(sizeof(struct lttng_ctx), GFP_KERNEL); | ||
if (!*ctx_p) | ||
return NULL; | ||
} | ||
ctx = *ctx_p; | ||
if (ctx->nr_fields + 1 > ctx->allocated_fields) { | ||
struct lttng_ctx_field *new_fields; | ||
|
||
ctx->allocated_fields = max_t(size_t, 1, 2 * ctx->allocated_fields); | ||
new_fields = kzalloc(ctx->allocated_fields * sizeof(struct lttng_ctx_field), GFP_KERNEL); | ||
if (!new_fields) | ||
return NULL; | ||
if (ctx->fields) | ||
memcpy(new_fields, ctx->fields, sizeof(*ctx->fields) * ctx->nr_fields); | ||
kfree(ctx->fields); | ||
ctx->fields = new_fields; | ||
} | ||
field = &ctx->fields[ctx->nr_fields]; | ||
ctx->nr_fields++; | ||
return field; | ||
} | ||
EXPORT_SYMBOL_GPL(lttng_append_context); | ||
|
||
/* | ||
* Remove last context field. | ||
*/ | ||
void lttng_remove_context_field(struct lttng_ctx **ctx_p, | ||
struct lttng_ctx_field *field) | ||
{ | ||
struct lttng_ctx *ctx; | ||
|
||
ctx = *ctx_p; | ||
ctx->nr_fields--; | ||
WARN_ON_ONCE(&ctx->fields[ctx->nr_fields] != field); | ||
memset(&ctx->fields[ctx->nr_fields], 0, sizeof(struct lttng_ctx_field)); | ||
} | ||
EXPORT_SYMBOL_GPL(lttng_remove_context_field); | ||
|
||
void lttng_destroy_context(struct lttng_ctx *ctx) | ||
{ | ||
int i; | ||
|
||
if (!ctx) | ||
return; | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* (C) Copyright 2009-2011 - | ||
* Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | ||
* | ||
* LTTng nice context. | ||
* | ||
* Dual LGPL v2.1/GPL v2 license. | ||
*/ | ||
|
||
#include <linux/module.h> | ||
#include <linux/slab.h> | ||
#include <linux/sched.h> | ||
#include "ltt-events.h" | ||
#include "wrapper/ringbuffer/frontend_types.h" | ||
#include "wrapper/vmalloc.h" | ||
#include "ltt-tracer.h" | ||
|
||
static | ||
size_t nice_get_size(size_t offset) | ||
{ | ||
size_t size = 0; | ||
|
||
size += lib_ring_buffer_align(offset, ltt_alignof(int)); | ||
size += sizeof(int); | ||
return size; | ||
} | ||
|
||
static | ||
void nice_record(struct lttng_ctx_field *field, | ||
struct lib_ring_buffer_ctx *ctx, | ||
struct ltt_channel *chan) | ||
{ | ||
int nice; | ||
|
||
nice = task_nice(current); | ||
lib_ring_buffer_align_ctx(ctx, ltt_alignof(nice)); | ||
chan->ops->event_write(ctx, &nice, sizeof(nice)); | ||
} | ||
|
||
int lttng_add_nice_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, "nice")) { | ||
lttng_remove_context_field(ctx, field); | ||
return -EEXIST; | ||
} | ||
field->event_field.name = "nice"; | ||
field->event_field.type.atype = atype_integer; | ||
field->event_field.type.u.basic.integer.size = sizeof(int) * CHAR_BIT; | ||
field->event_field.type.u.basic.integer.alignment = ltt_alignof(int) * CHAR_BIT; | ||
field->event_field.type.u.basic.integer.signedness = is_signed_type(int); | ||
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 = nice_get_size; | ||
field->record = nice_record; | ||
wrapper_vmalloc_sync_all(); | ||
return 0; | ||
} | ||
EXPORT_SYMBOL_GPL(lttng_add_nice_to_ctx); | ||
|
||
MODULE_LICENSE("GPL and additional rights"); | ||
MODULE_AUTHOR("Mathieu Desnoyers"); | ||
MODULE_DESCRIPTION("Linux Trace Toolkit Nice Context"); |
Oops, something went wrong.