Introduce common event structure
[lttng-ust.git] / liblttng-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
b4051ad8 10#include <stddef.h>
8173ec7c 11#include <pthread.h>
4318ae1b
MD
12#include <lttng/ust-events.h>
13#include <lttng/ust-tracer.h>
14#include <lttng/ringbuffer-config.h>
8173ec7c 15
fc80554e
MJ
16#include "context-internal.h"
17
8173ec7c 18static
53569322 19size_t pthread_id_get_size(struct lttng_ctx_field *field, size_t offset)
8173ec7c
MD
20{
21 size_t size = 0;
22
8de38cf7
MD
23 size += lib_ring_buffer_align(offset, lttng_alignof(unsigned long));
24 size += sizeof(unsigned long);
8173ec7c
MD
25 return size;
26}
27
28static
29void pthread_id_record(struct lttng_ctx_field *field,
4cfec15c 30 struct lttng_ust_lib_ring_buffer_ctx *ctx,
7dd08bec 31 struct lttng_channel *chan)
8173ec7c
MD
32{
33 unsigned long pthread_id;
34
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));
38}
39
77aa5901
MD
40static
41void pthread_id_get_value(struct lttng_ctx_field *field,
53569322 42 struct lttng_ctx_value *value)
77aa5901 43{
6e9ac4ae 44 value->u.s64 = (unsigned long) pthread_self();
77aa5901
MD
45}
46
8173ec7c
MD
47int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx)
48{
49 struct lttng_ctx_field *field;
50
51 field = lttng_append_context(ctx);
52 if (!field)
53 return -ENOMEM;
54 if (lttng_find_context(*ctx, "pthread_id")) {
55 lttng_remove_context_field(ctx, field);
56 return -EEXIST;
57 }
58 field->event_field.name = "pthread_id";
59 field->event_field.type.atype = atype_integer;
218deb69
MD
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;
8173ec7c
MD
66 field->get_size = pthread_id_get_size;
67 field->record = pthread_id_record;
77aa5901 68 field->get_value = pthread_id_get_value;
b2cc986a 69 lttng_context_update(*ctx);
8173ec7c
MD
70 return 0;
71}
This page took 0.034509 seconds and 4 git commands to generate.