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/ust-ringbuffer-context.h>
17 #include "context-internal.h"
20 size_t pthread_id_get_size(void *priv
__attribute__((unused
)),
21 struct lttng_ust_probe_ctx
*probe_ctx
__attribute__((unused
)),
26 size
+= lttng_ust_ring_buffer_align(offset
, lttng_ust_rb_alignof(unsigned long));
27 size
+= sizeof(unsigned long);
32 void pthread_id_record(void *priv
__attribute__((unused
)),
33 struct lttng_ust_probe_ctx
*probe_ctx
__attribute__((unused
)),
34 struct lttng_ust_ring_buffer_ctx
*ctx
,
35 struct lttng_ust_channel_buffer
*chan
)
37 unsigned long pthread_id
;
39 pthread_id
= (unsigned long) pthread_self();
40 chan
->ops
->event_write(ctx
, &pthread_id
, sizeof(pthread_id
), lttng_ust_rb_alignof(pthread_id
));
44 void pthread_id_get_value(void *priv
__attribute__((unused
)),
45 struct lttng_ust_probe_ctx
*probe_ctx
__attribute__((unused
)),
46 struct lttng_ust_ctx_value
*value
)
48 value
->u
.u64
= (unsigned long) pthread_self();
51 static const struct lttng_ust_ctx_field
*ctx_field
= lttng_ust_static_ctx_field(
52 lttng_ust_static_event_field("pthread_id",
53 lttng_ust_static_type_integer(sizeof(unsigned long) * CHAR_BIT
,
54 lttng_ust_rb_alignof(unsigned long) * CHAR_BIT
,
55 lttng_ust_is_signed_type(unsigned long),
56 LTTNG_UST_BYTE_ORDER
, 10),
63 int lttng_add_pthread_id_to_ctx(struct lttng_ust_ctx
**ctx
)
67 if (lttng_find_context(*ctx
, ctx_field
->event_field
->name
)) {
69 goto error_find_context
;
71 ret
= lttng_ust_context_append(ctx
, ctx_field
);