API refactoring: introduce probe context
[lttng-ust.git] / src / lib / lttng-ust / lttng-context-pthread-id.c
CommitLineData
8173ec7c 1/*
c0c0989a 2 * SPDX-License-Identifier: LGPL-2.1-only
8173ec7c 3 *
e92f3e28
MD
4 * Copyright (C) 2009-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
c0c0989a 6 * LTTng UST pthread_id context.
8173ec7c
MD
7 */
8
3fbec7dc 9#define _LGPL_SOURCE
9af5d97a 10#include <limits.h>
b4051ad8 11#include <stddef.h>
8173ec7c 12#include <pthread.h>
4318ae1b
MD
13#include <lttng/ust-events.h>
14#include <lttng/ust-tracer.h>
0b4b8811 15#include <lttng/ust-ringbuffer-context.h>
8173ec7c 16
fc80554e
MJ
17#include "context-internal.h"
18
8173ec7c 19static
4e48b5d2 20size_t pthread_id_get_size(void *priv __attribute__((unused)),
b2e37d27 21 struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
2208d8b5 22 size_t offset)
8173ec7c
MD
23{
24 size_t size = 0;
25
b5457df5 26 size += lttng_ust_ring_buffer_align(offset, lttng_ust_rb_alignof(unsigned long));
8de38cf7 27 size += sizeof(unsigned long);
8173ec7c
MD
28 return size;
29}
30
31static
4e48b5d2 32void pthread_id_record(void *priv __attribute__((unused)),
b2e37d27
MD
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)
8173ec7c
MD
36{
37 unsigned long pthread_id;
38
39 pthread_id = (unsigned long) pthread_self();
8936b6c0 40 chan->ops->event_write(ctx, &pthread_id, sizeof(pthread_id), lttng_ust_rb_alignof(pthread_id));
8173ec7c
MD
41}
42
77aa5901 43static
4e48b5d2 44void pthread_id_get_value(void *priv __attribute__((unused)),
b2e37d27 45 struct lttng_ust_probe_ctx *probe_ctx __attribute__((unused)),
daacdbfc 46 struct lttng_ust_ctx_value *value)
77aa5901 47{
b2e37d27 48 value->u.u64 = (unsigned long) pthread_self();
77aa5901
MD
49}
50
4e48b5d2
MD
51static 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),
baa8acf3 56 LTTNG_UST_BYTE_ORDER, 10),
4e48b5d2
MD
57 false, false),
58 pthread_id_get_size,
59 pthread_id_record,
60 pthread_id_get_value,
61 NULL, NULL);
62
daacdbfc 63int lttng_add_pthread_id_to_ctx(struct lttng_ust_ctx **ctx)
8173ec7c 64{
a084756d 65 int ret;
8173ec7c 66
4e48b5d2 67 if (lttng_find_context(*ctx, ctx_field->event_field->name)) {
a084756d
MD
68 ret = -EEXIST;
69 goto error_find_context;
8173ec7c 70 }
4e48b5d2
MD
71 ret = lttng_ust_context_append(ctx, ctx_field);
72 if (ret)
73 return ret;
8173ec7c 74 return 0;
a084756d 75
a084756d 76error_find_context:
a084756d 77 return ret;
8173ec7c 78}
This page took 0.037398 seconds and 4 git commands to generate.