Introduce LTTNG_UST_MAP_POPULATE_POLICY environment variable
[lttng-ust.git] / liblttng-ust / lttng-ust-dynamic-type.c
1 /*
2 * lttng-ust-dynamic-type.c
3 *
4 * UST dynamic type implementation.
5 *
6 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #define _GNU_SOURCE
24 #define _LGPL_SOURCE
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <stddef.h>
28 #include <inttypes.h>
29
30 #include <helper.h>
31 #include <lttng/ust-dynamic-type.h>
32
33 #define ctf_enum_value(_string, _value) \
34 { \
35 .start = { \
36 .signedness = lttng_is_signed_type(__typeof__(_value)), \
37 .value = lttng_is_signed_type(__typeof__(_value)) ? \
38 (long long) (_value) : (_value), \
39 }, \
40 .end = { \
41 .signedness = lttng_is_signed_type(__typeof__(_value)), \
42 .value = lttng_is_signed_type(__typeof__(_value)) ? \
43 (long long) (_value) : (_value), \
44 }, \
45 .string = (_string), \
46 },
47
48 static const struct lttng_enum_entry dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
49 [LTTNG_UST_DYNAMIC_TYPE_NONE] = ctf_enum_value("_none", 0)
50 [LTTNG_UST_DYNAMIC_TYPE_S8] = ctf_enum_value("_int8", 1)
51 [LTTNG_UST_DYNAMIC_TYPE_S16] = ctf_enum_value("_int16", 2)
52 [LTTNG_UST_DYNAMIC_TYPE_S32] = ctf_enum_value("_int32", 3)
53 [LTTNG_UST_DYNAMIC_TYPE_S64] = ctf_enum_value("_int64", 4)
54 [LTTNG_UST_DYNAMIC_TYPE_U8] = ctf_enum_value("_uint8", 5)
55 [LTTNG_UST_DYNAMIC_TYPE_U16] = ctf_enum_value("_uint16", 6)
56 [LTTNG_UST_DYNAMIC_TYPE_U32] = ctf_enum_value("_uint32", 7)
57 [LTTNG_UST_DYNAMIC_TYPE_U64] = ctf_enum_value("_uint64", 8)
58 [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = ctf_enum_value("_float", 9)
59 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = ctf_enum_value("_double", 10)
60 [LTTNG_UST_DYNAMIC_TYPE_STRING] = ctf_enum_value("_string", 11)
61 };
62
63 static const struct lttng_enum_desc dt_enum_desc = {
64 .name = "dynamic_type_enum",
65 .entries = dt_enum,
66 .nr_entries = LTTNG_ARRAY_SIZE(dt_enum),
67 };
68
69 const struct lttng_event_field dt_var_fields[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
70 [LTTNG_UST_DYNAMIC_TYPE_NONE] = {
71 .name = "none",
72 .type = {
73 .atype = atype_struct,
74 .u._struct.nr_fields = 0, /* empty struct. */
75 },
76 .nowrite = 0,
77 },
78 [LTTNG_UST_DYNAMIC_TYPE_S8] = {
79 .name = "int8",
80 .type = __type_integer(int8_t, BYTE_ORDER, 10, none),
81 .nowrite = 0,
82 },
83 [LTTNG_UST_DYNAMIC_TYPE_S16] = {
84 .name = "int16",
85 .type = __type_integer(int16_t, BYTE_ORDER, 10, none),
86 .nowrite = 0,
87 },
88 [LTTNG_UST_DYNAMIC_TYPE_S32] = {
89 .name = "int32",
90 .type = __type_integer(int32_t, BYTE_ORDER, 10, none),
91 .nowrite = 0,
92 },
93 [LTTNG_UST_DYNAMIC_TYPE_S64] = {
94 .name = "int64",
95 .type = __type_integer(int64_t, BYTE_ORDER, 10, none),
96 .nowrite = 0,
97 },
98 [LTTNG_UST_DYNAMIC_TYPE_U8] = {
99 .name = "uint8",
100 .type = __type_integer(uint8_t, BYTE_ORDER, 10, none),
101 .nowrite = 0,
102 },
103 [LTTNG_UST_DYNAMIC_TYPE_U16] = {
104 .name = "uint16",
105 .type = __type_integer(uint16_t, BYTE_ORDER, 10, none),
106 .nowrite = 0,
107 },
108 [LTTNG_UST_DYNAMIC_TYPE_U32] = {
109 .name = "uint32",
110 .type = __type_integer(uint32_t, BYTE_ORDER, 10, none),
111 .nowrite = 0,
112 },
113 [LTTNG_UST_DYNAMIC_TYPE_U64] = {
114 .name = "uint64",
115 .type = __type_integer(uint64_t, BYTE_ORDER, 10, none),
116 .nowrite = 0,
117 },
118 [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = {
119 .name = "float",
120 .type = __type_float(float),
121 .nowrite = 0,
122 },
123 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = {
124 .name = "double",
125 .type = __type_float(double),
126 .nowrite = 0,
127 },
128 [LTTNG_UST_DYNAMIC_TYPE_STRING] = {
129 .name = "string",
130 .type = {
131 .atype = atype_string,
132 .u.basic.string.encoding = lttng_encode_UTF8,
133 },
134 .nowrite = 0,
135 },
136 };
137
138 static const struct lttng_event_field dt_enum_field = {
139 .name = NULL,
140 .type.atype = atype_enum,
141 .type.u.basic.enumeration.desc = &dt_enum_desc,
142 .type.u.basic.enumeration.container_type = {
143 .size = sizeof(char) * CHAR_BIT,
144 .alignment = lttng_alignof(char) * CHAR_BIT,
145 .signedness = lttng_is_signed_type(char),
146 .reverse_byte_order = 0,
147 .base = 10,
148 .encoding = lttng_encode_none,
149 },
150 .nowrite = 0,
151 };
152
153 const struct lttng_event_field *lttng_ust_dynamic_type_field(int64_t value)
154 {
155 if (value >= _NR_LTTNG_UST_DYNAMIC_TYPES || value < 0)
156 return NULL;
157 return &dt_var_fields[value];
158 }
159
160 int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_event_field **choices)
161 {
162 *nr_choices = _NR_LTTNG_UST_DYNAMIC_TYPES;
163 *choices = dt_var_fields;
164 return 0;
165 }
166
167 const struct lttng_event_field *lttng_ust_dynamic_type_tag_field(void)
168 {
169 return &dt_enum_field;
170 }
This page took 0.031878 seconds and 4 git commands to generate.