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
;
18 #define ATYPE_ENTRY(name) [atype_##name] = #name
20 const char * const astract_types
[NR_ABSTRACT_TYPES
] = {
26 #define STAGE_EXPORT_ENUMS
27 #include "lttng-types.h"
28 #include "lttng-type-list.h"
29 #undef STAGE_EXPORT_ENUMS
31 struct 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
38 static void print_enum(struct seq_file
*m
, const struct lttng_enum
*lttng_enum
)
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
);
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
);
55 static void print_event_type(struct seq_file
*m
, const struct lttng_type
*type
)
59 seq_printf(m
, "type %s {\n"
65 astract_types
[type
->atype
],
67 type
->u
.integer
.signedness
,
68 type
->u
.integer
.alignment
);
71 seq_printf(m
, "type %s {\n"
73 "\tparent.parent = %s;\n"
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"
83 seq_printf(m
, "type %s {\n"
88 astract_types
[type
->atype
],
89 type
->u
.array
.elem_type
,
90 type
->u
.array
.length
);
93 seq_printf(m
, "<<< unknown abstract type %s for type %s >>>\n",
94 astract_types
[type
->atype
],
99 static void *lttng_seq_start(struct seq_file
*m
, loff_t
*pos
)
101 struct lttng_type
*type
= <tng_types
[*pos
];
103 if (type
> <tng_types
[ARRAY_SIZE(lttng_types
) - 1])
108 static void *lttng_seq_next(struct seq_file
*m
, void *v
, loff_t
*ppos
)
110 struct lttng_type
*type
= <tng_types
[++(*ppos
)];
112 if (type
> <tng_types
[ARRAY_SIZE(lttng_types
) - 1])
117 static void lttng_seq_stop(struct seq_file
*m
, void *v
)
121 static int lttng_seq_show(struct seq_file
*m
, void *v
)
123 struct lttng_type
*type
= v
;
125 print_event_type(m
, type
);
129 static 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
,
137 lttng_types_open(struct inode
*inode
, struct file
*file
)
139 return seq_open(file
, <tng_types_seq_ops
);
142 static const struct file_operations lttng_types_fops
= {
143 .open
= lttng_types_open
,
146 .release
= seq_release_private
,
149 static int lttng_types_init(void)
153 lttng_types_dentry
= debugfs_create_file("lttng-types", S_IWUSR
,
154 NULL
, NULL
, <tng_types_fops
);
155 if (IS_ERR(lttng_types_dentry
) || !lttng_types_dentry
) {
156 printk(KERN_ERR
"Error creating LTTng type export file\n");
164 module_init(lttng_types_init
);
166 static void lttng_types_exit(void)
168 debugfs_remove(lttng_types_dentry
);
171 module_exit(lttng_types_exit
);
173 MODULE_LICENSE("GPL and additional rights");
174 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
175 MODULE_DESCRIPTION("LTTng types");