af98816b4d5801001bbbb02ae1967938ea97a9a0
[lttng-ust.git] / src / lib / lttng-ust / lttng-context-pthread-id.c
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2009-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng UST pthread_id context.
7 */
8
9 #define _LGPL_SOURCE
10 #include <limits.h>
11 #include <stddef.h>
12 #include <pthread.h>
13 #include <lttng/ust-events.h>
14 #include <lttng/ust-tracer.h>
15 #include <lttng/ust-ringbuffer-context.h>
16
17 #include "context-internal.h"
18
19 static
20 size_t pthread_id_get_size(void *priv __attribute__((unused)),
21 size_t offset)
22 {
23 size_t size = 0;
24
25 size += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(unsigned long));
26 size += sizeof(unsigned long);
27 return size;
28 }
29
30 static
31 void pthread_id_record(void *priv __attribute__((unused)),
32 struct lttng_ust_ring_buffer_ctx *ctx,
33 struct lttng_ust_channel_buffer *chan)
34 {
35 unsigned long pthread_id;
36
37 pthread_id = (unsigned long) pthread_self();
38 chan->ops->event_write(ctx, &pthread_id, sizeof(pthread_id), lttng_ust_rb_alignof(pthread_id));
39 }
40
41 static
42 void pthread_id_get_value(void *priv __attribute__((unused)),
43 struct lttng_ust_ctx_value *value)
44 {
45 value->u.s64 = (unsigned long) pthread_self();
46 }
47
48 static const struct lttng_ust_ctx_field *ctx_field = lttng_ust_static_ctx_field(
49 lttng_ust_static_event_field("pthread_id",
50 lttng_ust_static_type_integer(sizeof(unsigned long) * CHAR_BIT,
51 lttng_ust_rb_alignof(unsigned long) * CHAR_BIT,
52 lttng_ust_is_signed_type(unsigned long),
53 LTTNG_UST_BYTE_ORDER, 10),
54 false, false),
55 pthread_id_get_size,
56 pthread_id_record,
57 pthread_id_get_value,
58 NULL, NULL);
59
60 int lttng_add_pthread_id_to_ctx(struct lttng_ust_ctx **ctx)
61 {
62 int ret;
63
64 if (lttng_find_context(*ctx, ctx_field->event_field->name)) {
65 ret = -EEXIST;
66 goto error_find_context;
67 }
68 ret = lttng_ust_context_append(ctx, ctx_field);
69 if (ret)
70 return ret;
71 return 0;
72
73 error_find_context:
74 return ret;
75 }
This page took 0.029914 seconds and 3 git commands to generate.