diff options
Diffstat (limited to 'trace-options.c')
-rw-r--r-- | trace-options.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/trace-options.c b/trace-options.c new file mode 100644 index 0000000..70c6343 --- /dev/null +++ b/trace-options.c | |||
@@ -0,0 +1,113 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> | ||
3 | * | ||
4 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; version 2 of the License (not later!) | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | * | ||
19 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
20 | */ | ||
21 | #define _LARGEFILE64_SOURCE | ||
22 | #define _GNU_SOURCE | ||
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <string.h> | ||
26 | #include <getopt.h> | ||
27 | #include <unistd.h> | ||
28 | |||
29 | #include "trace-local.h" | ||
30 | |||
31 | enum { | ||
32 | OPT_kallsyms = 253, | ||
33 | OPT_events = 254, | ||
34 | OPT_cpu = 255, | ||
35 | }; | ||
36 | |||
37 | struct option_list { | ||
38 | struct option_list *next; | ||
39 | struct plugin_option *op; | ||
40 | }; | ||
41 | |||
42 | static struct plugin_list { | ||
43 | struct plugin_list *next; | ||
44 | const char *name; | ||
45 | struct option_list *ops; | ||
46 | } *plugin_list; | ||
47 | |||
48 | static void add_option(struct plugin_option *option) | ||
49 | { | ||
50 | struct plugin_list *pl; | ||
51 | struct option_list *po; | ||
52 | const char *name; | ||
53 | |||
54 | name = option->plugin_alias ? : option->file; | ||
55 | |||
56 | for (pl = plugin_list; pl; pl = pl->next) { | ||
57 | if (strcmp(name, pl->name) == 0) | ||
58 | break; | ||
59 | } | ||
60 | if (!pl) { | ||
61 | pl = malloc_or_die(sizeof(*pl)); | ||
62 | memset(pl, 0, sizeof(*pl)); | ||
63 | pl->name = name; | ||
64 | pl->next = plugin_list; | ||
65 | plugin_list = pl; | ||
66 | }; | ||
67 | po = malloc_or_die(sizeof(*po)); | ||
68 | po->next = pl->ops; | ||
69 | pl->ops = po; | ||
70 | po->op = option; | ||
71 | } | ||
72 | |||
73 | void trace_option (int argc, char **argv) | ||
74 | { | ||
75 | struct plugin_option *options; | ||
76 | struct plugin_option *op; | ||
77 | struct plugin_list *pl; | ||
78 | struct plugin_list *npl; | ||
79 | struct option_list *po; | ||
80 | struct option_list *npo; | ||
81 | |||
82 | if (argc < 2) | ||
83 | usage(argv); | ||
84 | |||
85 | if (strcmp(argv[1], "options") != 0) | ||
86 | usage(argv); | ||
87 | |||
88 | options = trace_util_read_plugin_options(); | ||
89 | if (!options) { | ||
90 | printf("No plugin options found\n"); | ||
91 | goto out; | ||
92 | } | ||
93 | |||
94 | /* Group them up according to aliases */ | ||
95 | for (op = options; op; op = op->next) | ||
96 | add_option(op); | ||
97 | |||
98 | for (pl = plugin_list; pl; pl = npl) { | ||
99 | npl = pl->next; | ||
100 | printf("%s\n", pl->name); | ||
101 | for (po = pl->ops; po; po = npo) { | ||
102 | npo = po->next; | ||
103 | printf(" %s: %s\n", | ||
104 | po->op->name, po->op->description); | ||
105 | free(po); | ||
106 | } | ||
107 | free(pl); | ||
108 | } | ||
109 | |||
110 | out: | ||
111 | trace_util_free_options(options); | ||
112 | return; | ||
113 | } | ||