| 1 | /* |
| 2 | * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; version 2.1 of |
| 7 | * the License. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | #include <stdint.h> |
| 20 | #include <stdio.h> |
| 21 | #include <string.h> |
| 22 | #include <unistd.h> |
| 23 | |
| 24 | /* Internal UST API: ust-variant.h */ |
| 25 | #include <lttng/ust-variant.h> |
| 26 | #include <lttng/ust-events.h> |
| 27 | #include <helper.h> |
| 28 | |
| 29 | #define NR_ENTRIES 5 |
| 30 | |
| 31 | static const struct lttng_enum_entry myentries[NR_ENTRIES] = { |
| 32 | [0] = { |
| 33 | .start = 0, |
| 34 | .end = 0, |
| 35 | .string = "_mystring", |
| 36 | }, |
| 37 | [1] = { |
| 38 | .start = 1, |
| 39 | .end = 1, |
| 40 | .string = "_myint32", |
| 41 | }, |
| 42 | [2] = { |
| 43 | .start = 2, |
| 44 | .end = 2, |
| 45 | .string = "_myuint16", |
| 46 | }, |
| 47 | [3] = { |
| 48 | .start = 3, |
| 49 | .end = 3, |
| 50 | .string = "_mychar", |
| 51 | }, |
| 52 | [4] = { |
| 53 | .start = 4, |
| 54 | .end = 4, |
| 55 | .string = "_mylonglong", |
| 56 | }, |
| 57 | }; |
| 58 | |
| 59 | static const struct lttng_enum_desc myenum_desc = { |
| 60 | .name = "myenum", |
| 61 | .entries = myentries, |
| 62 | .nr_entries = LTTNG_ARRAY_SIZE(myentries), |
| 63 | }; |
| 64 | |
| 65 | const struct lttng_event_field myvarfields[NR_ENTRIES] = { |
| 66 | [0] = { |
| 67 | .name = "mystring", |
| 68 | .type = { |
| 69 | .atype = atype_string, |
| 70 | .u.basic.string.encoding = lttng_encode_UTF8, |
| 71 | }, |
| 72 | .nowrite = 0, |
| 73 | }, |
| 74 | [1] = { |
| 75 | .name = "myint32", |
| 76 | .type = __type_integer(int32_t, BYTE_ORDER, 10, none), |
| 77 | .nowrite = 0, |
| 78 | }, |
| 79 | [2] = { |
| 80 | .name = "myuint16", |
| 81 | .type = __type_integer(uint16_t, BYTE_ORDER, 10, none), |
| 82 | .nowrite = 0, |
| 83 | }, |
| 84 | [3] = { |
| 85 | .name = "mychar", |
| 86 | .type = __type_integer(char, BYTE_ORDER, 10, none), |
| 87 | .nowrite = 0, |
| 88 | }, |
| 89 | [4] = { |
| 90 | .name = "mylonglong", |
| 91 | .type = __type_integer(long long, BYTE_ORDER, 10, none), |
| 92 | .nowrite = 0, |
| 93 | }, |
| 94 | }; |
| 95 | |
| 96 | static const struct lttng_event_field *get_field(const struct lttng_ust_type_variant *variant, |
| 97 | int64_t value) |
| 98 | { |
| 99 | if (value >= NR_ENTRIES || value < 0) |
| 100 | return NULL; |
| 101 | return &myvarfields[value]; |
| 102 | } |
| 103 | |
| 104 | static int get_choices(const struct lttng_ust_type_variant *variant, |
| 105 | size_t *nr_choices, const struct lttng_event_field **choices) |
| 106 | { |
| 107 | *nr_choices = NR_ENTRIES; |
| 108 | *choices = myvarfields; |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | static const struct lttng_event_field myfields[]; |
| 113 | |
| 114 | static const struct lttng_ust_type_variant myvariant = { |
| 115 | .tag = &myfields[0], |
| 116 | .get_field = get_field, |
| 117 | .get_choices = get_choices, |
| 118 | .free_priv = NULL, |
| 119 | .priv = NULL, |
| 120 | }; |
| 121 | |
| 122 | /* dummy event */ |
| 123 | |
| 124 | static void __event_probe__myprobe___myevent(void * __tp_data) |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | static const struct lttng_event_field myfields[] = { |
| 129 | [0] = { |
| 130 | .name = "mytag", |
| 131 | .type.atype = atype_enum_nestable, |
| 132 | .type.u.enum_nestable.desc = &myenum_desc, |
| 133 | .type.u.enum_nestable.container_type = |
| 134 | __LTTNG_COMPOUND_LITERAL(struct lttng_type, |
| 135 | __type_integer(char, BYTE_ORDER, 10, none)), |
| 136 | .nowrite = 0, |
| 137 | }, |
| 138 | [1] = { |
| 139 | .name = "myfield", |
| 140 | .type = { |
| 141 | .atype = atype_variant_nestable, |
| 142 | .u.variant_nestable = &myvariant, |
| 143 | }, |
| 144 | .nowrite = 0, |
| 145 | }, |
| 146 | }; |
| 147 | |
| 148 | static const struct lttng_event_desc myevent_desc = { |
| 149 | .name = "myprobe:myevent", |
| 150 | .probe_callback = (void (*)(void)) &__event_probe__myprobe___myevent, |
| 151 | .ctx = NULL, |
| 152 | .fields = myfields, |
| 153 | .nr_fields = LTTNG_ARRAY_SIZE(myfields), |
| 154 | .loglevel = NULL, |
| 155 | .signature = "mysig", |
| 156 | .u = { |
| 157 | .ext = { |
| 158 | .model_emf_uri = NULL, |
| 159 | }, |
| 160 | }, |
| 161 | }; |
| 162 | |
| 163 | static const struct lttng_event_desc *event_desc_array[] = { |
| 164 | [0] = &myevent_desc, |
| 165 | }; |
| 166 | |
| 167 | /* Dummy probe. */ |
| 168 | |
| 169 | static struct lttng_probe_desc __probe_desc___myprobe = { |
| 170 | .provider = "myprobe", |
| 171 | .event_desc = event_desc_array, |
| 172 | .nr_events = LTTNG_ARRAY_SIZE(event_desc_array), |
| 173 | .head = { NULL, NULL }, |
| 174 | .lazy_init_head = { NULL, NULL }, |
| 175 | .lazy = 0, |
| 176 | .major = LTTNG_UST_PROVIDER_MAJOR, |
| 177 | .minor = LTTNG_UST_PROVIDER_MINOR, |
| 178 | }; |
| 179 | |
| 180 | int main(int argc, char **argv) |
| 181 | { |
| 182 | int ret; |
| 183 | |
| 184 | ret = lttng_probe_register(&__probe_desc___myprobe); |
| 185 | if (ret) |
| 186 | abort(); |
| 187 | sleep(5); |
| 188 | lttng_probe_unregister(&__probe_desc___myprobe); |
| 189 | |
| 190 | return 0; |
| 191 | } |