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.
13 #include <lttng/ust-events.h>
14 #include <lttng/ust-tracer.h>
15 #include <lttng/ringbuffer-context.h>
17 #include "context-internal.h"
20 size_t pthread_id_get_size(struct lttng_ust_ctx_field
*field
, size_t offset
)
24 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(unsigned long));
25 size
+= sizeof(unsigned long);
30 void pthread_id_record(struct lttng_ust_ctx_field
*field
,
31 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
32 struct lttng_ust_channel_buffer
*chan
)
34 unsigned long pthread_id
;
36 pthread_id
= (unsigned long) pthread_self();
37 lttng_ust_lib_ring_buffer_align_ctx(ctx
, lttng_ust_rb_alignof(pthread_id
));
38 chan
->ops
->event_write(ctx
, &pthread_id
, sizeof(pthread_id
));
42 void pthread_id_get_value(struct lttng_ust_ctx_field
*field
,
43 struct lttng_ust_ctx_value
*value
)
45 value
->u
.s64
= (unsigned long) pthread_self();
48 int lttng_add_pthread_id_to_ctx(struct lttng_ust_ctx
**ctx
)
50 struct lttng_ust_ctx_field
*field
;
51 struct lttng_ust_type_common
*type
;
54 type
= lttng_ust_create_type_integer(sizeof(unsigned long) * CHAR_BIT
,
55 lttng_ust_rb_alignof(unsigned long) * CHAR_BIT
,
56 lttng_ust_is_signed_type(unsigned long),
60 field
= lttng_append_context(ctx
);
65 if (lttng_find_context(*ctx
, "pthread_id")) {
67 goto error_find_context
;
69 field
->event_field
->name
= strdup("pthread_id");
70 if (!field
->event_field
->name
) {
74 field
->event_field
->type
= type
;
75 field
->get_size
= pthread_id_get_size
;
76 field
->record
= pthread_id_record
;
77 field
->get_value
= pthread_id_get_value
;
78 lttng_context_update(*ctx
);
83 lttng_remove_context_field(ctx
, field
);
85 lttng_ust_destroy_type(type
);