2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2009-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * LTTng UST pthread_id context.
12 #include <lttng/ust-events.h>
13 #include <lttng/ust-tracer.h>
14 #include <lttng/ringbuffer-config.h>
16 #include "context-internal.h"
19 size_t pthread_id_get_size(struct lttng_ctx_field
*field
, size_t offset
)
23 size
+= lib_ring_buffer_align(offset
, lttng_alignof(unsigned long));
24 size
+= sizeof(unsigned long);
29 void pthread_id_record(struct lttng_ctx_field
*field
,
30 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
31 struct lttng_channel
*chan
)
33 unsigned long pthread_id
;
35 pthread_id
= (unsigned long) pthread_self();
36 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(pthread_id
));
37 chan
->ops
->event_write(ctx
, &pthread_id
, sizeof(pthread_id
));
41 void pthread_id_get_value(struct lttng_ctx_field
*field
,
42 struct lttng_ctx_value
*value
)
44 value
->u
.s64
= (unsigned long) pthread_self();
47 int lttng_add_pthread_id_to_ctx(struct lttng_ctx
**ctx
)
49 struct lttng_ctx_field
*field
;
51 field
= lttng_append_context(ctx
);
54 if (lttng_find_context(*ctx
, "pthread_id")) {
55 lttng_remove_context_field(ctx
, field
);
58 field
->event_field
.name
= "pthread_id";
59 field
->event_field
.type
.atype
= atype_integer
;
60 field
->event_field
.type
.u
.integer
.size
= sizeof(unsigned long) * CHAR_BIT
;
61 field
->event_field
.type
.u
.integer
.alignment
= lttng_alignof(unsigned long) * CHAR_BIT
;
62 field
->event_field
.type
.u
.integer
.signedness
= lttng_is_signed_type(unsigned long);
63 field
->event_field
.type
.u
.integer
.reverse_byte_order
= 0;
64 field
->event_field
.type
.u
.integer
.base
= 10;
65 field
->event_field
.type
.u
.integer
.encoding
= lttng_encode_none
;
66 field
->get_size
= pthread_id_get_size
;
67 field
->record
= pthread_id_record
;
68 field
->get_value
= pthread_id_get_value
;
69 lttng_context_update(*ctx
);