4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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"
16 struct dentry
*lttng_types_dentry
;
19 #define ENTRY(name) [atype_##name] = #name
21 const char * const astract_types
[NR_ABSTRACT_TYPES
] = {
30 #define ENTRY(name) [lttng_encode_##name] = #name
32 const char * const string_encodings
[NR_STRING_ENCODINGS
] = {
37 #define STAGE_EXPORT_ENUMS
38 #include "lttng-types.h"
39 #include "lttng-type-list.h"
40 #undef STAGE_EXPORT_ENUMS
42 struct lttng_type lttng_types
[] = {
43 #define STAGE_EXPORT_TYPES
44 #include "lttng-types.h"
45 #include "lttng-type-list.h"
46 #undef STAGE_EXPORT_TYPES
49 static void print_enum(struct seq_file
*m
, const struct lttng_enum
*lttng_enum
)
53 for (i
= 0; i
< lttng_enum
->len
; i
++) {
54 if (lttng_enum
->entries
[i
].start
== lttng_enum
->entries
[i
].end
)
55 seq_printf(m
, "\t\t{ %llu, %s },\n",
56 lttng_enum
->entries
[i
].start
,
57 lttng_enum
->entries
[i
].string
);
59 seq_printf(m
, "\t\t{ { %llu, %llu }, %s },\n",
60 lttng_enum
->entries
[i
].start
,
61 lttng_enum
->entries
[i
].end
,
62 lttng_enum
->entries
[i
].string
);
66 static void print_event_type(struct seq_file
*m
, const struct lttng_type
*type
)
70 seq_printf(m
, "type %s {\n"
76 astract_types
[type
->atype
],
78 type
->u
.integer
.signedness
,
79 type
->u
.integer
.alignment
);
80 if (type
->u
.integer
.reverse_byte_order
)
81 seq_printf(m
, "\tbyte_order = %s;\n",
82 (__BYTE_ORDER
== __LITTLE_ENDIAN
) ?
84 seq_printf(m
, "};\n");
87 seq_printf(m
, "type %s {\n"
89 "\tparent.parent = %s;\n"
92 astract_types
[type
->atype
],
93 type
->u
.enumeration
.parent_type
);
94 print_enum(m
, &type
->u
.enumeration
.def
);
95 seq_printf(m
, "\t};\n"
99 seq_printf(m
, "type %s {\n"
101 "\telem_type = %s;\n"
104 astract_types
[type
->atype
],
105 type
->u
.array
.elem_type
,
106 type
->u
.array
.length
);
109 seq_printf(m
, "type %s {\n"
111 "\telem_type = %s;\n"
112 "\tlength_type = %s;\n"
114 astract_types
[type
->atype
],
115 type
->u
.sequence
.elem_type
,
116 type
->u
.sequence
.length_type
);
119 seq_printf(m
, "type %s {\n"
123 astract_types
[type
->atype
],
124 string_encodings
[type
->u
.string
.encoding
]);
127 seq_printf(m
, "<<< unknown abstract type %s for type %s >>>\n",
128 astract_types
[type
->atype
],
133 static void *lttng_seq_start(struct seq_file
*m
, loff_t
*pos
)
135 struct lttng_type
*type
= <tng_types
[*pos
];
137 if (type
> <tng_types
[ARRAY_SIZE(lttng_types
) - 1])
142 static void *lttng_seq_next(struct seq_file
*m
, void *v
, loff_t
*ppos
)
144 struct lttng_type
*type
= <tng_types
[++(*ppos
)];
146 if (type
> <tng_types
[ARRAY_SIZE(lttng_types
) - 1])
151 static void lttng_seq_stop(struct seq_file
*m
, void *v
)
155 static int lttng_seq_show(struct seq_file
*m
, void *v
)
157 struct lttng_type
*type
= v
;
159 print_event_type(m
, type
);
163 static const struct seq_operations lttng_types_seq_ops
= {
164 .start
= lttng_seq_start
,
165 .next
= lttng_seq_next
,
166 .stop
= lttng_seq_stop
,
167 .show
= lttng_seq_show
,
171 lttng_types_open(struct inode
*inode
, struct file
*file
)
173 return seq_open(file
, <tng_types_seq_ops
);
176 static const struct file_operations lttng_types_fops
= {
177 .open
= lttng_types_open
,
180 .release
= seq_release_private
,
183 static int lttng_types_init(void)
187 lttng_types_dentry
= debugfs_create_file("lttng-types", S_IWUSR
,
188 NULL
, NULL
, <tng_types_fops
);
189 if (IS_ERR(lttng_types_dentry
) || !lttng_types_dentry
) {
190 printk(KERN_ERR
"Error creating LTTng type export file\n");
198 module_init(lttng_types_init
);
200 static void lttng_types_exit(void)
202 debugfs_remove(lttng_types_dentry
);
205 module_exit(lttng_types_exit
);
207 MODULE_LICENSE("GPL and additional rights");
208 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
209 MODULE_DESCRIPTION("LTTng types");