Commit | Line | Data |
---|---|---|
8173ec7c MD |
1 | /* |
2 | * (C) Copyright 2009-2011 - | |
3 | * Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
4 | * | |
5 | * LTTng UST pthread_id context. | |
6 | * | |
7 | * Dual LGPL v2.1/GPL v2 license. | |
8 | */ | |
9 | ||
10 | #include <pthread.h> | |
4318ae1b MD |
11 | #include <lttng/ust-events.h> |
12 | #include <lttng/ust-tracer.h> | |
13 | #include <lttng/ringbuffer-config.h> | |
8173ec7c MD |
14 | |
15 | static | |
16 | size_t pthread_id_get_size(size_t offset) | |
17 | { | |
18 | size_t size = 0; | |
19 | ||
8de38cf7 MD |
20 | size += lib_ring_buffer_align(offset, lttng_alignof(unsigned long)); |
21 | size += sizeof(unsigned long); | |
8173ec7c MD |
22 | return size; |
23 | } | |
24 | ||
25 | static | |
26 | void pthread_id_record(struct lttng_ctx_field *field, | |
4cfec15c | 27 | struct lttng_ust_lib_ring_buffer_ctx *ctx, |
8173ec7c MD |
28 | struct ltt_channel *chan) |
29 | { | |
30 | unsigned long pthread_id; | |
31 | ||
32 | pthread_id = (unsigned long) pthread_self(); | |
33 | lib_ring_buffer_align_ctx(ctx, lttng_alignof(pthread_id)); | |
34 | chan->ops->event_write(ctx, &pthread_id, sizeof(pthread_id)); | |
35 | } | |
36 | ||
37 | int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx) | |
38 | { | |
39 | struct lttng_ctx_field *field; | |
40 | ||
41 | field = lttng_append_context(ctx); | |
42 | if (!field) | |
43 | return -ENOMEM; | |
44 | if (lttng_find_context(*ctx, "pthread_id")) { | |
45 | lttng_remove_context_field(ctx, field); | |
46 | return -EEXIST; | |
47 | } | |
48 | field->event_field.name = "pthread_id"; | |
49 | field->event_field.type.atype = atype_integer; | |
8de38cf7 MD |
50 | field->event_field.type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT; |
51 | field->event_field.type.u.basic.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; | |
3b402b40 | 52 | field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(unsigned long); |
8173ec7c MD |
53 | field->event_field.type.u.basic.integer.reverse_byte_order = 0; |
54 | field->event_field.type.u.basic.integer.base = 10; | |
55 | field->event_field.type.u.basic.integer.encoding = lttng_encode_none; | |
56 | field->get_size = pthread_id_get_size; | |
57 | field->record = pthread_id_record; | |
58 | return 0; | |
59 | } |