tracepoint: Refactor representation of nested types
[lttng-ust.git] / liblttng-ust / lttng-context-cpu-id.c
CommitLineData
c7ea8487
MD
1/*
2 * lttng-context-cpu-id.c
3 *
4 * LTTng UST CPU id context.
5 *
6 * Note: threads can be migrated at any point while executing the
7 * tracepoint probe. This means the CPU id field (and filter) is only
8 * statistical. For instance, even though a user might select a
9 * cpu_id==1 filter, there may be few events recorded into the channel
10 * appearing from other CPUs, due to migration.
11 *
12 * Copyright (C) 2009-2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; only
17 * version 2.1 of the License.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29#define _GNU_SOURCE
3fbec7dc 30#define _LGPL_SOURCE
b4051ad8 31#include <stddef.h>
c7ea8487
MD
32#include <sys/types.h>
33#include <unistd.h>
34#include <lttng/ust-events.h>
35#include <lttng/ust-tracer.h>
36#include <lttng/ringbuffer-config.h>
37#include "../libringbuffer/getcpu.h"
38
39static
53569322 40size_t cpu_id_get_size(struct lttng_ctx_field *field, size_t offset)
c7ea8487
MD
41{
42 size_t size = 0;
43
44 size += lib_ring_buffer_align(offset, lttng_alignof(int));
45 size += sizeof(int);
46 return size;
47}
48
49static
50void cpu_id_record(struct lttng_ctx_field *field,
51 struct lttng_ust_lib_ring_buffer_ctx *ctx,
52 struct lttng_channel *chan)
53{
54 int cpu;
55
56 cpu = lttng_ust_get_cpu();
57 lib_ring_buffer_align_ctx(ctx, lttng_alignof(cpu));
58 chan->ops->event_write(ctx, &cpu, sizeof(cpu));
59}
60
61static
62void cpu_id_get_value(struct lttng_ctx_field *field,
53569322 63 struct lttng_ctx_value *value)
c7ea8487 64{
6e9ac4ae 65 value->u.s64 = lttng_ust_get_cpu();
c7ea8487
MD
66}
67
68int lttng_add_cpu_id_to_ctx(struct lttng_ctx **ctx)
69{
70 struct lttng_ctx_field *field;
71
72 field = lttng_append_context(ctx);
73 if (!field)
74 return -ENOMEM;
75 if (lttng_find_context(*ctx, "cpu_id")) {
76 lttng_remove_context_field(ctx, field);
77 return -EEXIST;
78 }
79 field->event_field.name = "cpu_id";
80 field->event_field.type.atype = atype_integer;
218deb69
MD
81 field->event_field.type.u.integer.size = sizeof(int) * CHAR_BIT;
82 field->event_field.type.u.integer.alignment = lttng_alignof(int) * CHAR_BIT;
83 field->event_field.type.u.integer.signedness = lttng_is_signed_type(int);
84 field->event_field.type.u.integer.reverse_byte_order = 0;
85 field->event_field.type.u.integer.base = 10;
86 field->event_field.type.u.integer.encoding = lttng_encode_none;
c7ea8487
MD
87 field->get_size = cpu_id_get_size;
88 field->record = cpu_id_record;
89 field->get_value = cpu_id_get_value;
90 lttng_context_update(*ctx);
91 return 0;
92}
This page took 0.0284 seconds and 4 git commands to generate.