Steven Rostedt | 770cb24 | 2009-03-05 21:35:29 -0500 | [diff] [blame] | 1 | /* |
| 2 | * trace_export.c - export basic ftrace utilities to user space |
| 3 | * |
| 4 | * Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com> |
| 5 | */ |
| 6 | #include <linux/stringify.h> |
| 7 | #include <linux/kallsyms.h> |
| 8 | #include <linux/seq_file.h> |
| 9 | #include <linux/debugfs.h> |
| 10 | #include <linux/uaccess.h> |
| 11 | #include <linux/ftrace.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/fs.h> |
| 15 | |
| 16 | #include "trace_output.h" |
| 17 | |
Steven Rostedt | da4d030 | 2009-03-09 17:14:30 -0400 | [diff] [blame] | 18 | |
| 19 | #undef TRACE_STRUCT |
| 20 | #define TRACE_STRUCT(args...) args |
| 21 | |
| 22 | #undef TRACE_FIELD |
| 23 | #define TRACE_FIELD(type, item, assign) \ |
| 24 | ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \ |
| 25 | "offset:%u;\tsize:%u;\n", \ |
| 26 | (unsigned int)offsetof(typeof(field), item), \ |
| 27 | (unsigned int)sizeof(field.item)); \ |
| 28 | if (!ret) \ |
| 29 | return 0; |
| 30 | |
| 31 | |
| 32 | #undef TRACE_FIELD_SPECIAL |
| 33 | #define TRACE_FIELD_SPECIAL(type_item, item, cmd) \ |
| 34 | ret = trace_seq_printf(s, "\tfield special:" #type_item ";\t" \ |
| 35 | "offset:%u;\tsize:%u;\n", \ |
| 36 | (unsigned int)offsetof(typeof(field), item), \ |
| 37 | (unsigned int)sizeof(field.item)); \ |
| 38 | if (!ret) \ |
| 39 | return 0; |
Steven Rostedt | 770cb24 | 2009-03-05 21:35:29 -0500 | [diff] [blame] | 40 | |
| 41 | #undef TRACE_FIELD_ZERO_CHAR |
Steven Rostedt | 156b5f1 | 2009-03-06 10:50:53 -0500 | [diff] [blame] | 42 | #define TRACE_FIELD_ZERO_CHAR(item) \ |
Zhaolei | 1bbe2a8 | 2009-04-03 18:24:46 +0800 | [diff] [blame] | 43 | ret = trace_seq_printf(s, "\tfield:char " #item ";\t" \ |
Steven Rostedt | 156b5f1 | 2009-03-06 10:50:53 -0500 | [diff] [blame] | 44 | "offset:%u;\tsize:0;\n", \ |
| 45 | (unsigned int)offsetof(typeof(field), item)); \ |
| 46 | if (!ret) \ |
Steven Rostedt | 770cb24 | 2009-03-05 21:35:29 -0500 | [diff] [blame] | 47 | return 0; |
| 48 | |
| 49 | |
Steven Rostedt | 2939b04 | 2009-03-09 15:47:18 -0400 | [diff] [blame] | 50 | #undef TP_RAW_FMT |
| 51 | #define TP_RAW_FMT(args...) args |
Steven Rostedt | 770cb24 | 2009-03-05 21:35:29 -0500 | [diff] [blame] | 52 | |
| 53 | #undef TRACE_EVENT_FORMAT |
| 54 | #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \ |
| 55 | static int \ |
| 56 | ftrace_format_##call(struct trace_seq *s) \ |
| 57 | { \ |
| 58 | struct args field; \ |
| 59 | int ret; \ |
| 60 | \ |
| 61 | tstruct; \ |
| 62 | \ |
| 63 | trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \ |
| 64 | \ |
| 65 | return ret; \ |
| 66 | } |
| 67 | |
| 68 | #include "trace_event_types.h" |
| 69 | |
| 70 | #undef TRACE_ZERO_CHAR |
| 71 | #define TRACE_ZERO_CHAR(arg) |
| 72 | |
| 73 | #undef TRACE_FIELD |
| 74 | #define TRACE_FIELD(type, item, assign)\ |
| 75 | entry->item = assign; |
| 76 | |
| 77 | #undef TRACE_FIELD |
| 78 | #define TRACE_FIELD(type, item, assign)\ |
| 79 | entry->item = assign; |
| 80 | |
Steven Rostedt | 2939b04 | 2009-03-09 15:47:18 -0400 | [diff] [blame] | 81 | #undef TP_CMD |
| 82 | #define TP_CMD(cmd...) cmd |
Steven Rostedt | 770cb24 | 2009-03-05 21:35:29 -0500 | [diff] [blame] | 83 | |
| 84 | #undef TRACE_ENTRY |
| 85 | #define TRACE_ENTRY entry |
| 86 | |
| 87 | #undef TRACE_FIELD_SPECIAL |
| 88 | #define TRACE_FIELD_SPECIAL(type_item, item, cmd) \ |
| 89 | cmd; |
| 90 | |
| 91 | #undef TRACE_EVENT_FORMAT |
| 92 | #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \ |
| 93 | \ |
| 94 | static struct ftrace_event_call __used \ |
| 95 | __attribute__((__aligned__(4))) \ |
| 96 | __attribute__((section("_ftrace_events"))) event_##call = { \ |
Steven Rostedt | ef18012 | 2009-03-10 14:10:56 -0400 | [diff] [blame] | 97 | .name = #call, \ |
Steven Rostedt | 770cb24 | 2009-03-05 21:35:29 -0500 | [diff] [blame] | 98 | .id = proto, \ |
| 99 | .system = __stringify(TRACE_SYSTEM), \ |
| 100 | .show_format = ftrace_format_##call, \ |
| 101 | } |
| 102 | #include "trace_event_types.h" |