Move struct lttng_counter_ops to internal header
[lttng-ust.git] / liblttng-ust / lttng-context-pthread-id.c
... / ...
CommitLineData
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 <stddef.h>
11#include <pthread.h>
12#include <lttng/ust-events.h>
13#include <lttng/ust-tracer.h>
14#include <lttng/ringbuffer-config.h>
15
16#include "context-internal.h"
17
18static
19size_t pthread_id_get_size(struct lttng_ctx_field *field, size_t offset)
20{
21 size_t size = 0;
22
23 size += lib_ring_buffer_align(offset, lttng_alignof(unsigned long));
24 size += sizeof(unsigned long);
25 return size;
26}
27
28static
29void pthread_id_record(struct lttng_ctx_field *field,
30 struct lttng_ust_lib_ring_buffer_ctx *ctx,
31 struct lttng_channel *chan)
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
40static
41void pthread_id_get_value(struct lttng_ctx_field *field,
42 struct lttng_ctx_value *value)
43{
44 value->u.s64 = (unsigned long) pthread_self();
45}
46
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;
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;
66 field->get_size = pthread_id_get_size;
67 field->record = pthread_id_record;
68 field->get_value = pthread_id_get_value;
69 lttng_context_update(*ctx);
70 return 0;
71}
This page took 0.024002 seconds and 4 git commands to generate.