TRACE_EVENT: start work on type metadata declaration
[lttng-modules.git] / probes / lttng-types.c
CommitLineData
40652b65
MD
1/*
2 * probes/lttng-types.c
3 *
4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng types.
7 */
8
9#include <linux/module.h>
10#include <linux/types.h>
11#include <linux/seq_file.h>
12#include <linux/jbd.h> /* tid_t */
13#include <linux/debugfs.h>
14#include "lttng-types.h"
15
16struct dentry *lttng_types_dentry;
17
18#define ATYPE_ENTRY(name) [atype_##name] = #name
19
20const char * const astract_types[NR_ABSTRACT_TYPES] = {
21 ATYPE_ENTRY(integer),
22 ATYPE_ENTRY(enum),
23 ATYPE_ENTRY(array),
24};
25
26#define STAGE_EXPORT_ENUMS
27#include "lttng-types.h"
28#include "lttng-type-list.h"
29#undef STAGE_EXPORT_ENUMS
30
31struct lttng_type lttng_types[] = {
32#define STAGE_EXPORT_TYPES
33#include "lttng-types.h"
34#include "lttng-type-list.h"
35#undef STAGE_EXPORT_TYPES
36};
37
38static void print_enum(struct seq_file *m, const struct lttng_enum *lttng_enum)
39{
40 int i;
41
42 for (i = 0; i < lttng_enum->len; i++) {
43 if (lttng_enum->entries[i].start == lttng_enum->entries[i].end)
44 seq_printf(m, "\t\t{ %llu, %s },\n",
45 lttng_enum->entries[i].start,
46 lttng_enum->entries[i].string);
47 else
48 seq_printf(m, "\t\t{ { %llu, %llu }, %s },\n",
49 lttng_enum->entries[i].start,
50 lttng_enum->entries[i].end,
51 lttng_enum->entries[i].string);
52 }
53}
54
55static void print_event_type(struct seq_file *m, const struct lttng_type *type)
56{
57 switch(type->atype) {
58 case atype_integer:
59 seq_printf(m, "type %s {\n"
60 "\tparent = %s;\n"
61 "\tsize = %u;\n"
62 "\tsigned = %u;\n"
63 "\talign = %u;\n"
64 "};\n", type->name,
65 astract_types[type->atype],
66 type->u.integer.size,
67 type->u.integer.signedness,
68 type->u.integer.alignment);
69 break;
70 case atype_enum:
71 seq_printf(m, "type %s {\n"
72 "\tparent = %s;\n"
73 "\tparent.parent = %s;\n"
74 "\tmap = {\n",
75 type->name,
76 astract_types[type->atype],
77 type->u.enumeration.parent_type);
78 print_enum(m, &type->u.enumeration.def);
79 seq_printf(m, "\t};\n"
80 "};\n");
81 break;
82 case atype_array:
83 seq_printf(m, "type %s {\n"
84 "\tparent = %s;\n"
85 "\telem_type = %s;\n"
86 "\tlength = %u;\n"
87 "};\n", type->name,
88 astract_types[type->atype],
89 type->u.array.elem_type,
90 type->u.array.length);
91 break;
92 default:
93 seq_printf(m, "<<< unknown abstract type %s for type %s >>>\n",
94 astract_types[type->atype],
95 type->name);
96 }
97}
98
99static void *lttng_seq_start(struct seq_file *m, loff_t *pos)
100{
101 struct lttng_type *type = &lttng_types[*pos];
102
103 if (type > &lttng_types[ARRAY_SIZE(lttng_types) - 1])
104 return NULL;
105 return type;
106}
107
108static void *lttng_seq_next(struct seq_file *m, void *v, loff_t *ppos)
109{
110 struct lttng_type *type = &lttng_types[++(*ppos)];
111
112 if (type > &lttng_types[ARRAY_SIZE(lttng_types) - 1])
113 return NULL;
114 return type;
115}
116
117static void lttng_seq_stop(struct seq_file *m, void *v)
118{
119}
120
121static int lttng_seq_show(struct seq_file *m, void *v)
122{
123 struct lttng_type *type = v;
124
125 print_event_type(m, type);
126 return 0;
127}
128
129static const struct seq_operations lttng_types_seq_ops = {
130 .start = lttng_seq_start,
131 .next = lttng_seq_next,
132 .stop = lttng_seq_stop,
133 .show = lttng_seq_show,
134};
135
136static int
137lttng_types_open(struct inode *inode, struct file *file)
138{
139 return seq_open(file, &lttng_types_seq_ops);
140}
141
142static const struct file_operations lttng_types_fops = {
143 .open = lttng_types_open,
144 .read = seq_read,
145 .llseek = seq_lseek,
146 .release = seq_release_private,
147};
148
149static int lttng_types_init(void)
150{
151 int ret = 0;
152
153 lttng_types_dentry = debugfs_create_file("lttng-types", S_IWUSR,
154 NULL, NULL, &lttng_types_fops);
155 if (IS_ERR(lttng_types_dentry) || !lttng_types_dentry) {
156 printk(KERN_ERR "Error creating LTTng type export file\n");
157 ret = -ENOMEM;
158 goto error;
159 }
160error:
161 return ret;
162}
163
164module_init(lttng_types_init);
165
166static void lttng_types_exit(void)
167{
168 debugfs_remove(lttng_types_dentry);
169}
170
171module_exit(lttng_types_exit);
172
173MODULE_LICENSE("GPL and additional rights");
174MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
175MODULE_DESCRIPTION("LTTng types");
This page took 0.029031 seconds and 4 git commands to generate.